窗口应用程序无法在eclipse中打开

时间:2014-06-08 14:28:57

标签: java eclipse

您好我正在尝试学习java。我写了一个代码,在窗口中打开字符串,但实际上它没有打开。

import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Test extends Frame {
    public void paint(Graphics g){
        g.drawString("Hello from Java",60,100);
    }


public static void main(String args[]){
    Test f = new Test();
    f.setSize(200,200);
    f.addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent e){
            System.exit(0);}});
}
}

先谢谢

1 个答案:

答案 0 :(得分:1)

您必须使用setVisible()将其设置为可见

Test f = new Test();
f.setVisible(true);
// ...