import org.jdesktop.application.SingleFrameApplication;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import org.jdesktop.application.FrameView;
public class Welcome extends FrameView
{
SearchPanelClass panel1 = new SearchPanelClass();
AddMaterialPanel panel2 = new AddMaterialPanel();
Container container= AutomobileApplication.getApplication().getMainFrame();
public Welcome(SingleFrameApplication app)
{
super(app);
initMenu();
}
private class MenuAction implements ActionListener {
private SearchPanelClass panel;
private MenuAction(SearchPanelClass pnl)
{
this.panel = pnl;
}
private AddMaterialPanel AddMaterialPan;
private MenuAction(AddMaterialPanel pnl)
{
this.AddMaterialPan = pnl;
}
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if(command == "Panel1")
{
changePanel(panel1);
}
if(command =="Panel2")
{
changePanel(panel2);
}
}
}
private void initMenu() {
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("Menu");
JMenuItem menuItem1 = new JMenuItem("Panel1");
JMenuItem menuItem2 = new JMenuItem("Panel2");
menubar.add(menu);
menu.add(menuItem1);
menu.add(menuItem2);
this.setMenuBar(menubar);
menuItem1.addActionListener(new MenuAction(panel1));
menuItem2.addActionListener(new MenuAction(panel2));
}
private void changePanel(JPanel panel) {
container.removeAll();
setComponent(panel);
panel.setVisible(true);
container.doLayout();
}
}
此處SearchPanelClass和AddMaterialPanel是我想根據menuitem單擊添加的兩個自定義面板。但面板僅在調整窗口大小時纔可見。任何人都可以告訴我哪些程序在窗口調整大小後端調用?動態添加的面板只有在調整大小時才變爲可見
請掌舵我...
在此先感謝..
請問您可以添加main(String [] args)嗎? –
請學習java命名約定並堅持使用它們。 – kleopatra
@ kleopatra它只是練習,但隨後也thnks諮詢 – rupareliab