版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qingfeng812/article/details/16973069
效果:
package CH03;
import java.awt.event.*;
import java.awt.*;
class HelloWindow implements ActionListener
{
private Frame f=new Frame("Hello");
private Button btn=new Button("OK");
private Label l=new Label("Hello World");
public static void main(String[] args)
{
HelloWindow hw=new HelloWindow();
hw.init();
}
private void init()
{
f.add("Center",l);
f.add("North",btn);
btn.addActionListener(this);
f.setVisible(true);
f.setSize(320,150);
f.setResizable(true);
f.setLocation(300,200);
}
public void actionPerformed(ActionEvent e)
{
f.setVisible(false);
System.exit(0);
}
}