Java 关闭JAppletFrame而不关闭JFrame
我在父JFrame上放置了一个按钮,单击该按钮将打开一个JAppletFrame,现在当我关闭JAppletFrame时,整个应用程序将关闭。那么,有没有任何方法只关闭我的子帧而不关闭父帧?下面是代码Java 关闭JAppletFrame而不关闭JFrame,java,swing,javafx,Java,Swing,Javafx,我在父JFrame上放置了一个按钮,单击该按钮将打开一个JAppletFrame,现在当我关闭JAppletFrame时,整个应用程序将关闭。那么,有没有任何方法只关闭我的子帧而不关闭父帧?下面是代码 public static void main(String[] args) { applet = new HearDAHDSR(); //User defined class containing the frames window = new window1();
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.DISPOSE_ON_CLOSE);
如果小程序框架是唯一的框架,则JVM将退出,但如果有多个框架打开,则另一个框架将保持打开状态。是的,也尝试过,但不起作用……甚至尝试过隐藏,但没有幸运地发布一条消息&要么包含
JAppletFrame
代码,要么至少链接到Java文档。我从没听说过那门课。。
frame2.setDefaultCloseOperation(frame2.DISPOSE_ON_CLOSE);