import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class V_IO_GUI
{
public static void main(String[] args)
{
VFrame frm=new VFrame("frame");
JButton btn=new JButton("ÏÔÊŸdialog");
frm.add(btn);
btn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
new VDialog("dialog").setVisible(true);
}
});
}
}
class VFrame extends JFrame
{
//super();
VFrame()
{
this.setBounds(300, 300, 360, 360);
this.setLayout(new FlowLayout());
this.setVisible(true);
this.addWindowEvent();
}
VFrame(String str)
{
//super(str);
setTitle(str);
setBounds(300, 300, 360, 360);
setLayout(new FlowLayout());
setVisible(true);
addWindowEvent();
}
public void addWindowEvent()
{
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
class VDialog extends JDialog
{
private JLabel lab;
VDialog(String str)
{
lab=new JLabel(str);
setLayout(new FlowLayout());
setBounds(320, 320, 300, 200);
this.setModal(true);
add(lab);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ /*问题在这:这里要实现外部类的对象的隐藏,要怎么调用外部类的setVisible()?我是用下边的方法实现的,但为什么调用别的一个控件的setVisible()也可以呢?*/
//new VDialog().setVisible(false);
//new JDialog().setVisible(false);
new JFrame().setVisible(false);
}
});
}
}
|
|