我在我的父JFrame上放了一个按钮,点击后会打开一个JAppletFrame,现在当我关闭整个应用程序关闭JAppletFrame时。那么有没有只有我的子帧关闭而不是父帧的方法?这是代码
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);
}
答案 0 :(得分:2)
frame2.setDefaultCloseOperation(frame2.EXIT_ON_CLOSE);
不要使用EXIT_ON_CLOSE
。而是使用:
frame2.setDefaultCloseOperation(frame2.DISPOSE_ON_CLOSE);
如果applet框架是唯一的框架,那么JVM将退出,但如果打开多个框架,则另一个框架将保持打开状态。