如何实现 触发某个事件后弹出新框架窗口,但原有的框架窗口就变成不活动的,必须关闭弹出的窗口原窗口才可用?

解决方案 »

  1.   

    直接构造一个带有模式的Dialog
      

  2.   

    用JDialog的constructor中的第三个参数,将其设置为true。
    第三个参数为modal,具体含义为modal specifies whether dialog 
    blocks user input to other top-level windows when shown.
    参考代码如下:import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    public class Finding 
    {
    public static void main(String[] args)
    {
    final JFrame ownerFrame = new JFrame();
    ownerFrame.setSize(200, 200);
    JButton button = new JButton("Owner");
    button.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    JDialog dialog = new JDialog(ownerFrame, "goods", true);
    dialog.setSize(200, 200);
    dialog.setVisible(true);
    }
    });
    ownerFrame.add(button);
    ownerFrame.setVisible(true);
    }
    }