如何从JDesktopPane处理JInternalFrame Close opeartion?

时间:2013-11-20 06:19:46

标签: java swing jinternalframe

我有一个JFrame(HMSDoctor),我使用JInternalFrame(CurrentOPD)呼叫一个JDesktopPane

//opening JInternalFrame(CurrentOPD) by using JDesktopPane in JFrame(HMSDoctor).

       JDesktopPane jdp=new JDesktopPane();
   jdp.add(new CurrentOPD);

//Above code display proper JInternalFrame.

当我关闭那个JInternalFrame时,我想在JFrame(HMSDoctor)中执行另一个JInternalFrame(Follow)。

我该怎么做?

3 个答案:

答案 0 :(得分:5)

请参阅How to Write an Internal Frame Listener上的Swing教程中的部分。我猜你会想听“封闭”事件,然后做一些额外的处理。

答案 1 :(得分:4)

 public void actionPerformed(ActionEvent e) {
    if (SHOW.equals(e.getActionCommand())) {
        ...
        if (listenedToWindow == null) {
            listenedToWindow = new JInternalFrame("Event Generator",
                                                  true,  //resizable
                                                  true,  //closable
                                                  true,  //maximizable
                                                  true); //iconifiable
            //We want to reuse the internal frame, so we need to
            //make it hide (instead of being disposed of, which is
            //the default) when the user closes it.
            listenedToWindow.setDefaultCloseOperation(
                                    WindowConstants.HIDE_ON_CLOSE);

            listenedToWindow.addInternalFrameListener(this);
            ...
        }
    } 
    ...
}

答案 2 :(得分:1)

是的,首先您必须在addInternalFramaeListenerframe,当您JInternalFrame(CurrentOPD)关闭时,您可以致电JInternalFrame(Follow)