日期:2014-05-20 浏览次数:21004 次
class GJpanel extends JPanel { private int w; private int h; public GJpanel(){ } public void paintComponent(final Graphics g){ w = getWidth(); h = getHeight(); g.setColor(Color.green); g.drawLine(0, 0, 0,getHeight()); g.setColor(Color.red); g.drawLine(0,h/2,w,h/2); //x g.drawLine(w, h/2, w-10, h/2-10); g.drawLine(w, h/2, w-10, h/2+10); g.drawLine(w/2, 0,w/2, h); //y g.drawLine(w/2, 0, w/2-10, 10); g.drawLine(w/2, 0, w/2+10, 10); g.drawString("Y", w/2-20, 20); g.drawString("X", w-20, h/2+20); for(int x =0;x<w; x++){ int y =(int) (Math.cos (x*Math. PI/180)*h/3+h/2); g.drawString("·", x, y); } }