package com.ui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class TestMode extends JFrame implements ActionListener{
JDialog dialog;
public TestMode(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton b = new JButton();
b.addActionListener(this);
getContentPane().add(b);
setSize(100,100);
}
public static void main(String[] args){
TestMode frame = new TestMode();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(dialog == null){
dialog = new JDialog(this, true);
JButton b = new JButton();
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
//需要隐藏再显示,以便释放锁
dialog.setVisible(false);
dialog.setModal(false);
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
}
});
dialog.add(b);
dialog.setSize(100,100);
}
dialog.setVisible(true);
}
}
java swing打开子窗口后主窗口还用
最新推荐文章于 2024-04-15 15:36:19 发布