I am implementing a JButton
to perform an action but it's giving me an error. on my code i wrote
String EnterNumber = txtDisplay.getText() + Jbutton7.getText();
txtDisplay.setText(EnterNumbet) ;
the compiler is asking me to create a local variable call txtDisplay
and declare it to null
, but when i do it, it's not running. thanks
Declare txtDisplay
as field, it seems you declared it as local variable. I suppose that's why you can't get an access to it.
Your button7
variable is declared as a field, but txtDisplay
not.
Here is an example how should it be:
import javax.swing.*;
public class SomeClass {
private JButton jButton;
private JTextField txtDisplay;
public SomeClass() {
jButton = new JButton("7");
txtDisplay = new JTextField();
}
}
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.