import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class Test extends JFrame
{
private Dialog dialog;
public Test()
{
this.setTitle("你好!");
this.setBounds(300, 100, 600, 400);
this.setLayout(new FlowLayout());
dialog = new Dialog(this, "提示信息", true);
dialog.setBounds(300, 200, 600, 200);
dialog.setLayout(new FlowLayout());
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dialog.add(new JLabel("对不起,这里不再有关闭的作用!"));
dialog.setVisible(true);
}
});
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
});
this.setVisible(true);
}
public static void main(String[] args)
{
new Test();
}
}
建议提示信息要使用Dialog,不要使用JPanel。
好好看看Dialog和JPanel的区别。 |