|
hello! im fairly new to java and have been trying to resolve this problem for over a week with no joy so i thought i would start asking for help.
Basically this is the problem: the program is a basic calculator, however i cant seem to interact with the textfield i set up called display in order to show calculations or numbers in it. the following is how i create the listener and how i add it:
calculator listener = new calculator();
then further down the code...
button0.addActionListener(listener);
now the actuall listener:
class calculator implements ActionListener
{
public void actionPerformed(ActionEvent event){
if (event.getActionCommand().equals("0"))
{
// screen.println("0");
display.setText("0");
}
}
}
now if you notice the commented line, to print to the screen, that works, so i think that the listener is linked properly its just when i try getting it to show the text in display i get an java.lang.nullpointerexception, not in compilation but when i actually click the button when the programs running.
so it prints to the screen no problem, but not the textfield.
If a full code listing is required please tell me.
any help as soon as possible would be dearly appreciated.
sorry it should also be noted that the action listener is an inner class, the class it resides in is responsible for setting up the interface.
|
|
|
|
|
|
|
|