I have JTextField
and I want to increase the value by adding one (+1) every time the JButton
is pressed.
public void addtoj()
{
String m = jTextField1.getText();
int addone = Integer.valueOf(s);
s = Integer.toString(++addone);
jTextField1.setText(m);
}
If I understand you, then it should be s
not m
, like so -
String s = jTextField1.getText(); // <-- s not m.
int addone = Integer.valueOf(s);
s = Integer.toString(++addone);
jTextField1.setText(s); // <-- s not m.
Or maybe it should be,
String m = jTextField1.getText();
int addone = Integer.valueOf(m);
jTextField1.setText(String.valueOf(addone+1));
public void addtoj()
{
String text = jTextField1.getText();
int value = Integer.parseInt(text);
value = value + 1;
text = Integer.toString(value);
jTextField1.setText(text);
}
Or
public void addtoj()
{
jTextField1.setText(
Integer.toString( Integer.parseInt(jTextField1.getText()) + 1 ));
}
I don't know if I understand you well if I didn't please forgive me to make it : in ActionListenerclass write this:
float s = (float) Double.parseDouble(theTextField.getText());
int counter = 0;
counter++;
theTextField.setText("" + counter);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.