创建一个200*200的名为"java"的窗口,在窗口上做一个名为“exit”的按扭(可以覆盖整个窗口)点击该按扭退出窗口
import javax.swing.*;
import java.awt.event.*;
public class TestFrame extends JFrame,implements ActionListner
{
public TestFrame()
{
JButton b = new JButton("exit");
b.addActionListener(this);
Container cp = this.getContentPane();
cp.add(b);
this.setSize(200,200);
this.setVisible(true);
}
public void actionPerformed(ActionEvent evt)
{
System.exit(0);
}
public static void main(String[] args)
{
new TestFrame();
}
}·