/**
* @(#)TestDialog2.java
*
* TestDialog2 application
*
* @author
* @version 1.00 2007/1/20
*/
import java.awt.*;
import java.awt.event.*;
public class TestDialog2 extends Frame
{
private TextField tf=new TextField(10);
public TestDialog2()
{
Button bt1=new Button("打开模态窗口");
Button bt2=new Button("打开非模态窗口");
add(tf,"North");
add(bt1,"Center");
add(bt2,"East");
bt1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
MyDialog dlg=new MyDialog(TestDialog2.this,"模态窗口",true);
dlg.setTF(tf.getText());
dlg.setVisible(true);
}
});
bt2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
MyDialog dlg=new MyDialog(TestDialog2.this,"非模态窗口",false);
dlg.setTF(tf.getText());
dlg.setVisible(true);
}
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
e.getWindow().dispose();
}
});
}
public void setTF(String setInfo)
{
tf.setText(setInfo);
}
public static void main(String[] args)
{
// TODO, add your application code
System.out.println("Hello World!");
TestDialog2 mainFram=new TestDialog2();
mainFram.setTitle("hello");
//mainFram.setBackground(Color.lightGray);
mainFram.setBounds(300,200,400,400);
mainFram.setVisible(true);
}
}
//**************************************************************
import java.awt.*;
import java.awt.event.*;
import java.awt.Dialog;
public class MyDialog extends Dialog
{
private TextField tf=new TextField(10);
public MyDialog(Frame owner,String title,boolean modal)
{
super(owner,title,modal);
Button b1=new Button("应用");
Button b2=new Button("确定");
add(tf,"North");
add(b1,"Center");
add(b2,"East");
setBounds(0,0,200,200);
if(this.isModal()==true)
{
b1.setEnabled(false);
}
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
((TestDialog2)MyDialog.this.getOwner()).setTF(tf.getText());
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
((TestDialog2)MyDialog.this.getOwner()).setTF(tf.getText());
dispose();
}
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
e.getWindow().dispose();
}
});
}
public void setTF(String setInfo)
{
tf.setText(setInfo);
}
}