【发布时间】:2015-04-11 16:33:29
【问题描述】:
我在我的父 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);
}
【问题讨论】: