I have one Jframe which includes two TextFields and I want to exchange two integer numbers after clicking on exchange button.
Get the value from one text box and store it in the other.
.getText() is used to get the value from the textbox. .setText() is used to set the value of a textbox.
.getText() is used to get the value from the textbox.
.setText() is used to set the value of a textbox.
private void jButtonActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: String temp = jTextField1.getText(); jtextField1.setText(jTextField2.getText()); jtextField2.setText(temp); } // Variables declaration - do not modify private javax.swing.JButton jButton; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2;
Since JTextFields use Strings this works pretty much everywhere.
JTextField
String temp = text1.getText(); text1.setText(text2.getText()); text2.setText(temp);
Get the value from one text box and store it in the other.