title: Dynamically Change JTextField?
body: <p>My purpose here is to have the user click 10 buttons and have it show the sum in the uneditable JTextField. I did a little test in the console to show it was calculating right and to my success it was: The console was adding up the numbers as I clicked them. ( <a href="http://i.imgur.com/Cwyjm0h.jpg" rel="nofollow">http://i.imgur.com/Cwyjm0h.jpg</a> )</p>
  
  <p>I know that you can't enter an int value into a JTextField so I tried using String.valueOf(); to convert it and properly output it. The console is stating it's at 0 all the time. Maybe it needs to be reinitalized elsewhere? I can't tell. I also don't believe it's changing when I click a button. I assume thats not how it works but I don't know what will so here I am.</p>
  
  <p>So my question is:</p>
  
  <p>1) What am I doing wrong in converting total to sTotal</p>
  
  <p>2) If the number won't change even with an actionevent, What are my alternatives?</p>
  
  <p>Thank you in advance and here is the source!</p>
  
  <p>EDIT: I fixed the issue with the string converting by adding</p>
  
  <pre><code>String sTotal = String.valueOf(total);
      System.out.println(sTotal);
  </code></pre>
  
  <p>at the bottom under the system.out.println.(total);</p>
  
  <pre><code>import java.awt.FlowLayout;
  import java.awt.event.ActionListener;  
  import java.awt.event.ActionEvent;
  import javax.swing.JFrame; 
  import javax.swing.JButton;
  import javax.swing.JTextField;
  
  //JFrame builds the window
  public class ThreeOne extends JFrame{
  
  int total;
  String sTotal = String.valueOf(total);
  
  private JTextField question;
  private JButton Button1, Button2, Button3, Button4, Button5, 
  Button6, Button7, Button8, Button9, Button10;
  
  
  
  //The window
  public ThreeOne(){
      super("");
      setLayout(new FlowLayout());
  
      question = new JTextField(sTotal, 40);
  
      question.setEditable(false);
      add(question);
  
      Button1 = new JButton("1");
      add(Button1);
      Button2 = new JButton("2");
      add(Button2);
      Button3 = new JButton("3");
      add(Button3);
      Button4 = new JButton("4");
      add(Button4);
      Button5 = new JButton("5");
      add(Button5);
      Button6 = new JButton("6");
      add(Button6);
      Button7 = new JButton("7");
      add(Button7);
      Button8 = new JButton("8");
      add(Button8);
      Button9 = new JButton("9");
      add(Button9);
      Button10 = new JButton("10");
      add(Button10);
  
  
  
  
  
      thehandler handler = new thehandler();
      Button1.addActionListener(handler);
      Button2.addActionListener(handler);
      Button3.addActionListener(handler);
      Button4.addActionListener(handler);
      Button5.addActionListener(handler);
      Button6.addActionListener(handler);
      Button7.addActionListener(handler);
      Button8.addActionListener(handler);
      Button9.addActionListener(handler);
      Button10.addActionListener(handler);
  
  
  }
  
  //implements means this is the class that handles the events
  private class thehandler implements ActionListener{
  
      public void actionPerformed(ActionEvent event){
  
  
  
          // event is like an enter or a click
          if(event.getSource()== Button1)
          total = total + 1;
          if(event.getSource()== Button2)
              total = total + 2;
  
          if(event.getSource()== Button3)
              total = total + 3;
  
          if(event.getSource()== Button4)
              total = total + 4;
  
          if(event.getSource()== Button5)
              total = total + 5;
  
          if(event.getSource()== Button6)
              total = total + 6;
  
          if(event.getSource()== Button7)
              total = total + 7;
  
          if(event.getSource()== Button8)
              total = total + 8;
  
          if(event.getSource()== Button9)
              total = total + 9;
  
          if(event.getSource()== Button10)
              total = total + 10;
  
  
  
      System.out.println(total);
  
  
  
  
      }
  
  }
        }
  </code></pre>