title: Drawing buttons outside of the method they were made in?
body: <p>Basically, I drew and have all my code in the main method. I'm trying to make a start menu so I want to be able to have a method (named <code>drawMenu</code>), that I can run to draw out the tic-tac-toe buttons. </p>
  
  <p>Shorter explanation, how do I draw buttons outside of this main method in this <code>drawMenu</code> method?</p>
  
  <pre><code>package myClass;
  import java.awt.Dimension;
  import java.awt.GridLayout;
  import java.util.HashMap;
  import java.util.Map;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.tools.ToolProvider;
  
  public class mainClass {
  
  
      //Boolean switcher for playing/not
  
  
      //Create panel sides for action listeners
      enum ESide {
                tleft, tmid, tright,
                mleft, mmid, mright,
                bleft, bmid, bright,
              };
  
  public static void main(String[] args) {
  
      //Objects
  
      //create window
      JFrame mainWindow = new JFrame("Tic Tac Toe");
      //properties of mainWindow
      mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      mainWindow.setSize(600, 600); // buttons will fill entirely, 200x200      buttons
      mainWindow.setLayout(new GridLayout(3, 3));
  
      //create buttons
      JButton startButton = new JButton("Start");
      JButton topLeft = new JButton("");
      JButton topMid = new JButton("");
      JButton topRight = new JButton("");
      JButton midLeft = new JButton("");
      JButton midMid = new JButton("");
      JButton midRight = new JButton("");
      JButton botLeft = new JButton("");
      JButton botMid = new JButton("");
      JButton botRight = new JButton("");
  
      //Definitions
      final Map&lt;ESide, Boolean&gt; board = new HashMap&lt;&gt;();
      for (ESide side : ESide.values()) {
          board.put(side, false);
      }
      //Dimensions
      Dimension selectionButtonSize = new Dimension(100,25);
      Dimension buttonSize = new Dimension(200,200);
  
      //Action listener
  
  topLeft.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt)
          {
              if (board.get(ESide.tleft).booleanValue() == false) {
                  topLeft.setText("X");
                  board.put(ESide.tleft, true);
              }
          }
  
    });
  
  topMid.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt)
          {
              if (board.get(ESide.tmid).booleanValue() == false) {
                  topMid.setText("X");
                  board.put(ESide.tmid, true);
              }
          }
  
    });
  
  topRight.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseClicked(java.awt.event.MouseEvent evt)
                {
                    if (board.get(ESide.tright).booleanValue() == false) {
                        topRight.setText("X");
                        board.put(ESide.tright, true);
                    }
                }
  
    });
  
  midLeft.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseClicked(java.awt.event.MouseEvent evt)
                {
                    if (board.get(ESide.mleft).booleanValue() == false) {
                        midLeft.setText("X");
                        board.put(ESide.mleft, true);
                    }
                }
  
    });
  
  midMid.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseClicked(java.awt.event.MouseEvent evt)
                {
                    if (board.get(ESide.mmid).booleanValue() == false) {
                        midMid.setText("X");
                        board.put(ESide.mmid, true);
                    }
                }
  
    });
  
  midRight.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseClicked(java.awt.event.MouseEvent evt)
                {
                    if (board.get(ESide.mright).booleanValue() == false) {
                        midRight.setText("X");
                        board.put(ESide.mright, true);
                    }
                }
  
    });
  
  botLeft.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseClicked(java.awt.event.MouseEvent evt)
                {
                    if (board.get(ESide.bleft).booleanValue() == false) {
                        botLeft.setText("X");
                        board.put(ESide.bleft, true);
                    }
                }
  
    });
  
  botMid.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseClicked(java.awt.event.MouseEvent evt)
                {
                    if (board.get(ESide.bmid).booleanValue() == false) {
                        botMid.setText("X");
                        board.put(ESide.bmid, true);
                    }
                }
  
    });
  
  botRight.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseClicked(java.awt.event.MouseEvent evt)
                {
                    if (board.get(ESide.bright).booleanValue() == false) {
                        botRight.setText("X");
                        board.put(ESide.bright, true);
                    }
                }
  
    });
  
  
  
  drawMenu();
  mainWindow.setVisible(true); // draw it
  
  
  
  }
  
  public static void drawMenu() {
      System.out.println("Drawing menu button");
      //I want to be able to access the buttons to draw them here.
  
  }
  
  }
  </code></pre>