现在的位置: 首页 > 综合 > 正文

java swing打开子窗口后主窗口还用

2013年12月12日 ⁄ 综合 ⁄ 共 845字 ⁄ 字号 评论关闭

 

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);
}
}

抱歉!评论已关闭.