public class NewJFrame extends javax.swing.JFrame { /** Creates new form NewJFrame */
static Timer t=new Timer(40,new time());
static int sx=0,sy=0,ex=0,ey=0;
static int sx1=0,sy1=0,ex1=0,ey1=0;
public NewJFrame() {
initComponents();
Graphics g=this.getGraphics();
g.drawLine(0,0,1000,1000);
this.getGraphics().drawLine(0, 0, 100,100);
this.getGraphics().drawRect(0,0,100,100);
this.setResizable(false);
this.setVisible(true);
}
static Timer t=new Timer(40,new time());
static int sx=0,sy=0,ex=0,ey=0;
static int sx1=0,sy1=0,ex1=0,ey1=0;
public NewJFrame() {
initComponents();
Graphics g=this.getGraphics();
g.drawLine(0,0,1000,1000);
this.getGraphics().drawLine(0, 0, 100,100);
this.getGraphics().drawRect(0,0,100,100);
this.setResizable(false);
this.setVisible(true);
}
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
g.drawLine(10, 100, 90, 100);
}
g.drawLine(0,0,1000,1000);
this.getGraphics().drawLine(0, 0, 100,100);
this.getGraphics().drawRect(0,0,100,100);
this.setResizable(false);
this.setVisible(true); 我在奇怪楼主在g.drawLine(0,0,1000,1000)怎么不会出现null错误,是不是楼主在initComponents()用了show()。如果楼主的程序能跑,应该在运行时,可以看到红色线条一闪而过。要想线条一直显示,你要按1楼和3楼的方法实现画线才行。