import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
class a{
public static void main(String[] args) {
JFrame JF=new JFrame();//创建窗口
JF.setSize(500,500);//设置窗口大小
JF.setLocationRelativeTo(null);//设置窗口居中
JF.setDefaultCloseOperation(3);//设置关闭模式
JF.setResizable(false);//禁止调窗口大小
JF.setLayout(null);//取消默认布局
JButton JB=new JButton("必须关闭新弹窗口才能操作原窗口");
JB.setBounds(0,0,250,100);//设置大小、位置
JButton JB1=new JButton("无需关闭新窗口可继续操作原窗口");
JB1.setBounds(250,0,250,100);//设置大小、位置
JDialog JD=new JDialog();//创建顶级窗口
JD.setBounds(0,0,500,500);//设置大小、位置
JDialog JD1=new JDialog();//创建顶级窗口
JD1.setBounds(800,300,500,500);//设置大小、位置
JB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JD.setModal(true);//设置模态,当前对话框打开同时,不可以操作其他对话框
if(e.getSource()==JB) {
JD.setVisible(true);//设置JD窗口可见
}
}
});
JB1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JD1.setModal(false);//设置非模态,当前对话框打开同时,也可以操作其他对话框
if(e.getSource()==JB1) {
JD1.setVisible(true);//设置JD1窗口可见
}
}
});
JF.add(JB);
JF.add(JB1);//将
JF.setVisible(true);//设置窗口可见
}
}