-1

I'm trying to code a game where the user try's to guess a number, randomly generated between 1 and 10, I need to know how to get the text from the JTextField

    JFrame frame = new JFrame("The Guessing Game");
    frame.setVisible(true);
    frame.setSize(400, 300);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);

    JPanel panel = new JPanel();

    JButton rndbutton = new JButton("Click to create random nubmer!");
    panel.add(rndbutton);
    frame.add(panel);

    JTextField tField = new JTextField(15);
    panel.add(tField);



    //^^ The GUI code ^^



    game.game();
}

}

Mrsoldier3201
  • 23
  • 1
  • 6
  • `tField.getText()` http://stackoverflow.com/questions/5752307/how-to-retrieve-value-from-jtextfield-in-java-swing – pattmorter Jul 25 '14 at 18:22
  • 1
    When you asked the question, did it not suggest duplicates? – iptq Jul 25 '14 at 18:24
  • it is pretty straight forward - just call the `getText()` method of your JTextField. Or is ur question not clear? – Pat Jul 25 '14 at 18:25

1 Answers1

0

Use:

tField.getText()

If you're not sure how to do something, you should first check the documentation to see if there's a function for it. Searching on Google is also a good idea.

iptq
  • 657
  • 1
  • 7
  • 15
  • Also, this question may have been answered before on stack overflow, so you should do a search on stack overflow first. – iptq Jul 25 '14 at 18:24