Getting and setting int's from jTextField
807607Nov 5 2006 — edited Nov 19 2006I'm using netbeans.org to make my first desktop application. I made a test project to try to get text from a jTextField and display it, I completed the DiveLog java tutorial and learned to use the getText and setText methods to achieve this.
Here is the method I created to do this. Keep in mind that I have two jTextFields and am joining the text entered in both to display in a jLabel.
private void buttonActionPerformed(java.awt.event.ActionEvent evt) {
if ((evt.getSource() == tf) || (evt.getSource() == button))
{ String disText = tf.getText();
String disText2 = tftwo.getText();
String disText3 = (disText) + " " + (disText2);
jLabel1.setText(disText3);
jLabel1.setForeground(Color.white);
}
...now that I have figured out that I can display text, I would like to know how to get numbers (int) from the two jTextField components and perform simple mathmatical operations on them and then display the result in the jLabel. I tried changing all of the "String" in the method above to "int" but netbeans.org says that setText is incompatible with "int".