import java.awt.*;
import java.awt.event.*;
public class TestFrame implements ActionListener
{
Frame f = new Frame("Tian Shugang");
public static void main(String[] args)
{
TestFrame tf = new TestFrame();
tf.init();
}
public void init()
{
Button btn = new Button("退出");
btn.addActionListener(this);
f.setVisible(true);
f.setSize(500,500);
f.add(btn);
f.addWindowListener(new MyWindowListener());
} public void actionPerformed(ActionEvent e)
{
f.setVisible(false);
f.dispose();
System.exit(0);
}
}
class MyWindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
e.getWindow().setVisible(false);
System.exit(0);
}
} 这个小的测试程序在几天前还可以用jcreator编译并且运行,运行的时候会显示一个小的窗口.但是现在却不行了,一运行就出来控制台窗口了:"按任意键".这是为什么呢?如果直接在控制台运行就能正常显示窗口.
import java.awt.event.*;
public class TestFrame implements ActionListener
{
Frame f = new Frame("Tian Shugang");
public static void main(String[] args)
{
TestFrame tf = new TestFrame();
tf.init();
}
public void init()
{
Button btn = new Button("退出");
btn.addActionListener(this);
f.setVisible(true);
f.setSize(500,500);
f.add(btn);
f.addWindowListener(new MyWindowListener());
} public void actionPerformed(ActionEvent e)
{
f.setVisible(false);
f.dispose();
System.exit(0);
}
}
class MyWindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
e.getWindow().setVisible(false);
System.exit(0);
}
} 这个小的测试程序在几天前还可以用jcreator编译并且运行,运行的时候会显示一个小的窗口.但是现在却不行了,一运行就出来控制台窗口了:"按任意键".这是为什么呢?如果直接在控制台运行就能正常显示窗口.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货