1

I can use numbers and stuff like

num1 = Float.parseFloat(txt1.getText());

but I am looking to get words from a text field, then do calculations based on which word. Like:

String input1;
if (input1.equalsIgnorecase("Word")) {
2 + 2; }

I just don't know how to do that on a jform.

davejal
  • 6,009
  • 10
  • 39
  • 82
The Chair
  • 21
  • 3

1 Answers1

1

As pointed out by @MadProgrammer, .getText() will help you in retrieving String values from a test field.

For example, If your Java Form contains a text field whose variable name is jTextField1, you can retreive value from it by:

String input1 = jTextFielf1.getText();

Just for information,

float num1 = Float.parseFloat(txt1.getText());

also does the same thing, it first gets the string value from the text field and converts it into a float value.

Rohan Pillai
  • 917
  • 3
  • 17
  • 26