swing - Using a JButton to change an interface in Java -


The idea is that there are 5 pockets at the top of the screen. Each time you press one, it removes the old menu and produces a new one. For me, my code looks fine. The problem is that when I click on "Add CD", nothing happens, but if I change the size of the window manually (take your mouse over the window edge Is going and changes its shape) The new menu pops up ... Can anyone give me advice about fixing this problem ... Thanks, the full runner code is down.

  Package UI; Import javax.swing *; Import java.awt. *; Import java.awt.event. *; Import javax.swing.event. *; The public class implements the main interface JFrame that implement ActionListener {// Variable declaration - Do not modify the personal JButton jButton1; Private Jebton Jebton 2; Private Jebton Jebton 3; Private Jebton Jebton 4; Private Jebton Jebton 5; Private Jebton Jebton 6; Private Jeppel jPanel1; Private JTextField lesson 1; Private JTextField text 2; Private JTextField lesson 3; Private JTextField text 4; Private JTextField text 5; Private JTextField text 6; Private JTextField text 7; Private JTextField text 8; Private J Label Label 1; Private JLab label 2; Private JL label label 3; Private JLabel label 4; Private J Label 5; Private J Label Label 6; Private JLable label 7; Private JLab label 8; Private Zeppel Down Panel; Private Zeppel Top Panel; // Declared Panels Private Jepinal Grip All; Private Jepinel One; Private Jepynl two; Private Jeppel three; Private Jeppel Four; // ------------------------------------------------ -------------- ------------------------------------ - -------------------- Public stable zero major (string agre []) {java.awt.EventQueue.invokeLater (new runnab) (public zero run) { Main interface myApplication = new main interface (); MyApplication.setLocation (100, 100); MyApplication.setSize (700, 400); MyApplication.setTitle ("Kevin Jukebox"); MyApplication.setVisible (true);}}}; } // ----------------------------------------------- ----------- // ------------------------------------- --------------------- ** New form creates main interface * / public key interface () {jButton1 = new pocket ("add CD"); JButton2 = New Pocket ("Add Video"); JButton3 = New Pocket ("Total Play Time"); JButton4 = New Pocket ("Create Playlist"); JButton5 = New Pocket ("Library Show"); JButton6 = New Pocket ("Quit"); TopPanel = new zpn (); HoldAll = new JPanel (); Bottom panel = new zpn (); A = new zpn (); Two = new zpn (); Three = new zpn (); Four = new zpn (); Text1 = new JTextField (15); Label1 = new JLabel ("title:"); Text2 = new JTextField (15); Label2 = new JLABEL ("Artist:"); Text3 = new JTextField (15); Label 3 = new jlabel ("length:"); Text4 = new JTextField (15); Label4 = new JLABEL ("Number of Tracks:"); Label 5 = new JLabel ("welcome to Kevin Jukebox"); Int flag = 0; DrawApp (flag); JButton1.addActionListener (this); JButton2.addActionListener (this); JButton3.addActionListener (this); JButton4.addActionListener (this); JButton5.addActionListener (this); JButton6.addActionListener (this); SetDefaultCloseOperation (DISPOSE_ON_CLOSE); } // ----------------------------------------------- ----------- // ------------------------------------- --------------------- Public Zero Functionality (Execution E) {if (e.getSource () == jButton1) {int flag = 1; DrawApp (flag); }} // ---------------------------------------------- ------------ // ------------------------------------ ---------------------- Public zero drawApp (int flag) {topPanel.setLayout (new flow layout ()); TopPanel.add (jButton1); TopPanel.add (jButton2); TopPanel.add (jButton3); TopPanel.add (jButton4); TopPanel.add (jButton5); TopPanel.add (jButton6); BottomPanel.add (label5); HoldAll.setLayout (new border layout ()); HoldAll.add (TopPanel, Border Layout. North); HoldAll.add (bottom panel, BorderLayout.CENTER); If (flag == 0) panel.add below (label5); And below Panel.remove (label5); If (flag == 1) {one.add (label1); One.add (text1); BottomPanel.add (a); Two.add (LABEL2); Two.add (text2); BottomPanel.add (two); Three.add (Label3); Three.add (text3); BottomPanel.add (three); Four.add (label4); Four.add (text4); BottomPanel.add (four); Below the Panel.setLayout (New BoxLayout (bottom panel, BoxLayout.PAGE_AXIS)); } GetContentPane (). Add (holdAll, BorderLayout.CENTER); // all the spaces on the frame) // ----------------------------------------- -----------------}    

Execute UI layout after updating Calling this method requires the UI to relay its components.

Comments