Im пытается получить его так, что, когда я нажимаю на пункт меню, окна меняются с «приветственного текста» на 4 кнопки, которые пользователь может щелкнуть. Однако, когда я нажимаю кнопку симуляции, ничего не происходит. Окно вообще не меняется. Я подвел, кстати, мой код к основному материалу. кто-нибудь видит что-нибудь, что я не могу?JPanel java не отображается
JFrame GUI = new JFrame("Graphical User Interface");
public gui()
{
JMenuBar menubar = new JMenuBar();
JMenu Simulation = new JMenu("Simulation");
theLabel = new JLabel("Welcome to the Main Menu. ",JLabel.CENTER);
GUI.add(theLabel);
menubar.add(Simulation);
Simulation.add(Simulationmenu);
Simulationmenu.addActionListener(this);
GUI.setJMenuBar(menubar);
GUI.setLocation(500,250);
GUI.setSize(300, 200);
GUI.setVisible(true);
}
public void actionPerformed(ActionEvent E){
if(E.getSource() == Simulationmenu){
// Buttons in the menu i want to output once clicked on 'simulation'
thePanel = new JPanel(new GridLayout(4,0));
Run = new JButton("Run");
Pause = new JButton("Pause");
Reset = new JButton("Reset");
DisplayMaps = new JButton("Display Maps?");
// Add the components to the panel:
thePanel.add("West", Run);
thePanel.add("Center", Pause);
thePanel.add("East", Reset);
thePanel.add("West", DisplayMaps);
// Add the panel to the contentPane of the frame:
GUI.add(thePanel);
// add this object as listener to the two buttons:
Run.addActionListener(this);
1) Для лучшей помощи раньше, отправьте сообщение [SSCCE] (http://sscce.org/). 2) Используйте последовательный и логический отступ для кодовых блоков. Отступ кода предназначен для того, чтобы помочь людям понять поток программы. 3) Для многих компонентов в одном пространстве используйте ['CardLayout'] (http://docs.oracle.com/javase/7/docs/api/java/awt/CardLayout.html), как показано в этом [кратком примере ] (http://stackoverflow.com/a/5786005/418556). –