title: How To Make This JFrame Code More Simple?
body: <p>I have just started learning JFrame, and I tried to make a simple calculator. It works, but it's also repetitive, having to make an ActionListener for each button. Is there a way to make it more simple?</p>
  
  <pre><code>public class gui extends JFrame
  {
      private JButton one;
      private JButton two;
      private JButton three;
      private JButton four;
      private JButton five;
      private JButton six;
      private JButton seven;
      private JButton eight;
      private JButton nine;
      public double first  = 0;
      public double second = 0;
      public double sum    = 0;
  
      public gui() 
      {   
          super("title");
          setLayout(new FlowLayout());
  
          one   = new JButton("1"); //makes a new button to click.
          two   = new JButton("2");
          three = new JButton("3");
          four  = new JButton("4");
          five  = new JButton("5");
          six   = new JButton("6");
          seven = new JButton("7");
          eight = new JButton("8");
          nine  = new JButton("9");
          one.addActionListener( //MAKES NEW INNER CLASS TO DEFINE WHAT ONE DOES
              new ActionListener() 
              {
                  public void actionPerformed(ActionEvent event) 
                  { 
                      // checks if clicked. 
                      if (first == 0) first = 1;
                      else second = 1;
  
                      if (first != 0 &amp;&amp; second != 0) 
                      {
                          sum = first + second;
                          System.out.println(sum);
                          first = 0;
                          second = 0;
                      }
                  }
              });
          two.addActionListener( 
  
                  new ActionListener() {
  
                      public void actionPerformed(ActionEvent event) { 
                          if(first == 0) {
                          first = 2;
                          }else {
                              second = 2;
                          }
                          if(first != 0 &amp;&amp; second != 0) {
                              sum = first + second;
                              System.out.println(sum);
                              first = 0;
                              second = 0;
                          }
                      }
                  }
              );
          three.addActionListener( 
  
                  new ActionListener() {
  
                      public void actionPerformed(ActionEvent event) { 
                          if(first == 0) {
                          first = 3;
                          }else {
                              second = 3;
                          }
                          if(first != 0 &amp;&amp; second != 0) {
                              sum = first + second;
                              System.out.println(sum);
                              first = 0;
                              second = 0;
                          }
                      }
                  }
              );
          four.addActionListener(
  
                  new ActionListener() {
  
                      public void actionPerformed(ActionEvent event) {
                          if(first == 0) {
                          first = 4;
                          }else {
                              second = 4;
                          }
                          if(first != 0 &amp;&amp; second != 0) {
                              sum = first + second;
                              System.out.println(sum);
                              first = 0;
                              second = 0;
                          }
                      }
                  }
              );
          five.addActionListener(
  
                  new ActionListener() {
  
                      public void actionPerformed(ActionEvent event) { 
                          if(first == 0) {
                          first = 5;
                          }else {
                              second = 5;
                          }
                          if(first != 0 &amp;&amp; second != 0) {
                              sum = first + second;
                              System.out.println(sum);
                              first = 0;
                              second = 0;
                          }
                      }
                  }
              );
          six.addActionListener( 
  
                  new ActionListener() {
  
                      public void actionPerformed(ActionEvent event) { 
                          if(first == 0) {
                          first = 6;
                          }else {
                              second = 6;
                          }
                          if(first != 0 &amp;&amp; second != 0) {
                              sum = first + second;
                              System.out.println(sum);
                              first = 0;
                              second = 0;
                          }
                      }
                  }
              );
          seven.addActionListener(
  
                  new ActionListener() {
  
                      public void actionPerformed(ActionEvent event) { 
                          if(first == 0) {
                          first = 7;
                          }else {
                              second = 7;
                          }
                          if(first != 0 &amp;&amp; second != 0) {
                              sum = first + second;
                              System.out.println(sum);
                              first = 0;
                              second = 0;
                          }
                      }
                  }
              );
          eight.addActionListener(
  
                  new ActionListener() {
  
                      public void actionPerformed(ActionEvent event) { 
                          if(first == 0) {
                          first = 8;
                          }else {
                              second = 8;
                          }
                          if(first != 0 &amp;&amp; second != 0) {
                              sum = first + second;
                              System.out.println(sum);
                              first = 0;
                              second = 0;
                          }
                      }
                  }
              );
          nine.addActionListener( 
  
                  new ActionListener() {
  
                      public void actionPerformed(ActionEvent event) { 
                          if(first == 0) {
                          first = 9;
                          }else {
                              second = 9;
                          }
                          if(first != 0 &amp;&amp; second != 0) {
                              sum = first + second;
                              System.out.println(sum);
                              first = 0;
                              second = 0;
  
                          }
                      }
                  }
              );
  
          add(one);
          add(two);
          add(three);
          add(four);
          add(five);
          add(six);
          add(seven);
          add(eight);
          add(nine);
  
      }
  
  }
  </code></pre>
  
  <p>Also I can't find a way to "combine" two numbers that I have. If the user presses 9 and 2, I want to combine those two numbers to make 92. How would I do that?</p>