请问JAVA Jframe加了panint方法后就显示为黑色了是为什么?

public class MyGameFrame extends JFrame {

public void paint(Graphics g) {

g.drawLine(100,100,300,300);

}

/*

 * 初始化窗口

 */

public void launchFrame() {

this.setTitle("打飞机小游戏");

this.setVisible(true);//设置为可见

this.setSize(500,500);//设置窗口的长度、宽度

this.setLocation(300,300);//设置窗口的位置

/*

* 设置关闭窗口功能

*/

this.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

}

public static void main(String[] args)

{

MyGameFrame f = new MyGameFrame();

f.launchFrame();

f.setVisible(true);

}

}


慕虎7371278
浏览 2269回答 4
4回答

那你那

直接把 this.Visible(true);放到this.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e) {System.exit(0);}});的后边就解决了
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java