嗨,我正在尝试学习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);}});
}
}
提前致谢
最佳答案
您必须将其设置为可见,使用 setVisible()
:
Test f = new Test();
f.setVisible(true);
// ...
关于java - 窗口应用程序无法在 Eclipse 中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24107129/