当前位置: 代码迷 >> J2SE >> JDialog解决思路
  详细解决方案

JDialog解决思路

热度:183   发布时间:2016-04-24 15:52:02.0
JDialog
import   javax.swing.*;
import   java.awt.*;
import   java.awt.event.*;

class   MyDialog   extends   JDialog{
JLabel   label;
MyDialog(JFrame   f,String   s){
super(f,s);
label=new   JLabel( "哈哈!! ");
setSize(90,90);
setModal(true);
getContentPane().setLayout(new   FlowLayout());
getContentPane().add(label);
addWindowListener(new   WindowAdapter(){
public   void   windowClosing(WindowEvent   e){
System.exit(0);
}
});
}
}

class   MyFrame   extends   JFrame   implements   ActionListener{
JButton   button;
MyDialog   dialog;
MyFrame(){
setSize(400,300);
getContentPane().setLayout(new   FlowLayout());
button=new   JButton( "确定 ");
dialog=new   MyDialog(此处, "对话框 ");
getContentPane().add(button);
button.addActionListener(this);
setVisible(true);
}
public   void   actionPerformed(ActionEvent   e){
if(e.getSource()==button){
dialog.setVisible(true);
}
}
}

public   class   Dd{
public   static   void   main(String   args[]){
new   MyFrame();
}
}


//文中 "此处 "应该如何填写?望达人指教!

------解决方案--------------------
this