paint是自动调用的,不需要自己去调,把
Graphics gg=new Graphics();//编译错误:类不能被初始化???
paint(gg);
这两句删掉
而且初始化Graphics也不能用new,如下:
Graphics gg=new JFrame().getContentPane().getGraphics();
Graphics gg=new Graphics();//编译错误:类不能被初始化???
paint(gg);
这两句删掉
而且初始化Graphics也不能用new,如下:
Graphics gg=new JFrame().getContentPane().getGraphics();
Graphics gg=new Graphics();//编译错误:类不能被初始化???
paint(gg);
这两句删掉
而且初始化Graphics也不能用new,如下:
Graphics gg=new JFrame().getContentPane().getGraphics();
void jButton1_actionPerformed(ActionEvent e) {
Graphics gg=new frmMain().getContentPane().getGraphics();
//Color c= new Color(100,100,100);
//gg.setColor(c) ;
gg.drawLine(0,0,10,10);
}
repaint();
}
因为repaint()函数自动调用paintComponent(Graphics g),然后你把需要的画图代码填到重载的paintComponent里就行了
paintComponent(Graphics g){
g.drawLine(0,0,10,10);
}
public void paintComponent(Graphics g){
Color c= new Color(100,100,100);
g.setColor(c) ;
g.drawLine(0,0,10,10);
} void jButton1_actionPerformed(ActionEvent e) {
repaint();
}
paintComponent(g);
}
public void paintComponent(Graphics g){
Color c= new Color(100,100,100);
g.setColor(c) ;
g.drawLine(0,0,100,100);
}
void jButton1_actionPerformed(ActionEvent e) {
repaint();
}