日期:2014-05-20  浏览次数:20875 次

JDialog的构造方法中的owner是什么意思
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

public class AboutDialog extends JDialog{
static JFrame jf=new JFrame();
/**
 * @param args
 */
static JFrame tf=new JFrame();
public static void main(String[] args) {
// TODO Auto-generated method stub


new AboutDialog(jf);
}
public AboutDialog(JFrame owner){

super(owner,"关于记事本",true);
tf.setVisible(true);
tf.setLocation(600, 600);
tf.setSize(100,100);

JMenuBar jb=new JMenuBar();
JMenu jm=new JMenu("FIle");
JMenuItem ji=new JMenuItem("About");
jb.add(jm);
jm.add(ji);
jf.setJMenuBar(jb);
ji.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
setVisible(true);
}
});
jf.setVisible(true);
jf.setSize(300,300);

add(new JLabel("<html><h1>Window7 旗舰版</i></h1><hr><p>Microsoft Windows</p><p>....</p></html>"),BorderLayout.CENTER);

JPanel panel=new JPanel();
JButton ok=new JButton("Ok");
ok.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
setVisible(false);
}
});
panel.add(ok);
add(panel,BorderLayout.SOUTH);

setSize(250,150);
}

}

这里super(owner,"关于记事本",true);我吧owner改成tf并没有看出什么变化,看了一会API文档后还是一头雾水,求解释了

------解决方案--------------------
super(owner,"关于记事本",false);    
这里把true改为false

然后,执行程序,在打开dialog框的状态下,分别关闭jf和tf,看dialog框是随着谁的关闭而关闭的.
然后,把owner改成tf,再按上面的方式执行下,看这次dialog框是随着谁的关闭而关闭的.
如此可以看出来区别.