简体   繁体   English

关闭JAppletFrame而不关闭JFrame

[英]Closing JAppletFrame without closing JFrame

I have placed a button on my parent JFrame which on click opens a JAppletFrame, now when i close the JAppletFrame the whole application closes. 我在父JFrame上放置了一个按钮,单击该按钮将打开一个JAppletFrame,现在当我关闭JAppletFrame时,整个应用程序都将关闭。 So is there any method that only my child frame closes and not the parent frame?Here is the code 那么有什么方法只能关闭我的子框架而不关闭父框架?

public static void main(String[] args) {

    applet = new HearDAHDSR();


    //User defined class containing the frames
    window = new window1();
    //window2 window = new window2();
    //then you set to your node
    frame = window.frame();
    frame.setSize(700, 500);
    frame.setVisible(true);

    //User defined class containing all panels
    panel = new Panels();

    StringBuilder b = new StringBuilder();

    //Retrieving the width and height of the frame
    w = frame.getContentPane().getWidth();
    h = frame.getContentPane().getHeight();

    //
    JPanel bar_panel = panel.Bar();
    JPanel tabbed_playlist = panel.Playlist(w,h);

    frame.getContentPane().add(bar_panel, BorderLayout.NORTH);

    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);

    //Adding the Playlist and Library tabs
    tabbedPane.addTab("Playlist", tabbed_playlist);
    tabbedPane.addTab("Library", panel.Library(w,h));

    launch(args);;
}


}
public static void effect2(){
    frame2 = new JAppletFrame( "Effect", applet );
    frame2.setSize( 440, 300 );
    frame2.setVisible( true );
    frame2.test();
    frame2.setDefaultCloseOperation(frame2.EXIT_ON_CLOSE);

}
frame2.setDefaultCloseOperation(frame2.EXIT_ON_CLOSE);

Don't use EXIT_ON_CLOSE . 不要使用EXIT_ON_CLOSE Instead use: 而是使用:

frame2.setDefaultCloseOperation(frame2.DISPOSE_ON_CLOSE);

If the applet frame is the only frame, then the JVM will exit, but if more than one frame is open the other frame will remain open. 如果applet框架是唯一的框架,那么JVM将退出,但是如果打开了多个框架,则另一个框架将保持打开状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM