title: Don't know how to add a button array - java
body: <p><strong>This is my exercise description:</strong> 
  When the user clicks on one of the buttons, the panel in the middle must change to
  a random colour. And the Label on top must have its text changed to a random element
  in an array of four strings. Use a button array for the four buttons. Whenever the
  user moves the curser over the label, the text colour must change to a random colour
  and font. When the mouse leaves the label,it must go back to default.</p>
  
  <pre><code>import java.awt.*;
  import javax.swing.*;
  import javax.swing.border.*;
  import java.awt.event.*;
  //2.3.5 - 1
  public class UserGui extends JFrame implements ActionListener, WindowListener, MouseListener {
      private JLabel label;
      private JButton button[] = new JButton[4];
      public UserGui() {
          super("My Frame");
          this.setSize(300,150);
          JMenuBar myMenuBar = new JMenuBar();
          ((JPanel) getContentPane()).setBorder(new EmptyBorder(13, 13, 13, 13) );
          setLayout(new GridBagLayout());
          JPanel colorize = new JPanel();
          GridBagConstraints c = new GridBagConstraints();
          c.fill = GridBagConstraints.HORIZONTAL;
  
  
          // from here
          //strings put in array for label change(by hovering over)
          String[] myStringArray = new String[]{"Funky","Classic","Legendary","Awesome"};
          Border border = BorderFactory.createLineBorder(Color.BLACK, 5);
          label = new JLabel("Java Wins!");
          c.ipady = 40;
          c.weightx = 0.0;
          c.gridwidth = 4;
          c.gridx = 0;
          c.gridy = 0;
  
          setJMenuBar(myMenuBar);
          JMenu myMenu = new JMenu("File");
          JMenuItem quitItem = new JMenuItem("Quit");
          add(label);
          addWindowListener(this);
          myMenu.add(quitItem);
          myMenuBar.add(myMenu);      
          setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
          quitItem.addActionListener(this);
          setVisible(true);
      }
  
      public void windowOpened(WindowEvent e) {
          JOptionPane.showMessageDialog(null, "Welcome!"); 
      }  
      /*
      public void actionPerformed(ActionEvent e)
      {
          if(e.getActionCommand().equals(""))
          {
              colorize.setText(field.getText());
          }
      }
      */
      public void actionPerformed(ActionEvent e) { 
          Object source = e.getSource(); 
          if (source.equals("Quit")) { 
              System.exit(1); 
          } 
      } 
      public void windowActivated(WindowEvent e) {} 
      public void windowClosed(WindowEvent e) {} 
      public void windowDeactivated(WindowEvent e) {} 
      public void windowDeiconified(WindowEvent e) {} 
      public void windowIconified(WindowEvent e) {}
      public void mouseClicked(MouseEvent e) {} 
      public void mouseReleased(MouseEvent e) {} 
      public void mousePressed(MouseEvent e) {}
      public void mouseEntered(MouseEvent e) {}
      public void mouseExited(MouseEvent e) {}
      public void windowClosing(WindowEvent e) { 
          int response = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?"); 
          if (response == JOptionPane.YES_OPTION) { 
              System.exit(0); // Exits application 
          } 
      } 
  
      public static void main(String args[]) {
          JFrame frame = new UserGui();
          frame.setVisible(true);
      }
  }
  </code></pre>