asiavoices
Programmer
Hello everyone,
This is followup to my earlier post
I now have the particular section of my actionPerformed working (by printing out... you have click on button 1, 2, or 3, etc.)
but it now seems that when I try to reset or clear a field(s), it is giving me a "java.lang.NullPointerException" X-) error.
I don't understand. Here is my revised code.
public class ItsMe extends JFrame
implements ActionListener
{
......
/* ---- declare JButtons ------- */
private JButton myButton1;
private JButton myButton2;
private JButton myButton3;
private JButton myButton4;
.......
/* ---- My Constructor ------- */
public ItsMe()
{
..........
JTextField nameField = new JTextField(15);
nameField.addActionListener(this);
JTextField costField = new JTextField(8);
costField.addActionListener(this);
JCheckBox taxField = new JCheckBox("Yes", true);
taxField.addActionListener(this);
..........
myButton1 = new JButton("Button 1"
myButton1.addActionListener(this);
...........
myButton2 = new JButton("Button 2"
myButton2.addActionListener(this);
...........
myButton3 = new JButton("Button 3"
myButton3.addActionListener(this);
...........
resetButton = new JButton("Reset"
resetButton.addActionListener(this);
...........
} // end of my constructor
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
//If button 1 pressed . . .
if (source == myButton1)
{
recordCounter ++;
System.out.println("You have clicked on Button 1. Counter hit is: " + recordcounter );
......
}
//If button 2 pressed . . .
if (source == myButton2)
{
recordCounter ++;
System.out.println("You have clicked on Button 2. Counter hit is: " + recordcounter );
......
}
//If button 3 pressed . . .
if (source == myButton3)
{
recordCounter ++;
System.out.println("You have clicked on Button 3. Counter hit is: " + recordcounter );
......
}
//If Reset pressed . . .
if (source == resetButton) :-(
{
nameField.setText(""
costField.setText(""
System.out.println("You have clicked on RESET button. );
......
}
} // end of actionPerformed method
.....
} // end of my ItsMe class
Any ideas?
Thank you,
Christopher
This is followup to my earlier post
I now have the particular section of my actionPerformed working (by printing out... you have click on button 1, 2, or 3, etc.)
but it now seems that when I try to reset or clear a field(s), it is giving me a "java.lang.NullPointerException" X-) error.
I don't understand. Here is my revised code.
public class ItsMe extends JFrame
implements ActionListener
{
......
/* ---- declare JButtons ------- */
private JButton myButton1;
private JButton myButton2;
private JButton myButton3;
private JButton myButton4;
.......
/* ---- My Constructor ------- */
public ItsMe()
{
..........
JTextField nameField = new JTextField(15);
nameField.addActionListener(this);
JTextField costField = new JTextField(8);
costField.addActionListener(this);
JCheckBox taxField = new JCheckBox("Yes", true);
taxField.addActionListener(this);
..........
myButton1 = new JButton("Button 1"
myButton1.addActionListener(this);
...........
myButton2 = new JButton("Button 2"
myButton2.addActionListener(this);
...........
myButton3 = new JButton("Button 3"
myButton3.addActionListener(this);
...........
resetButton = new JButton("Reset"
resetButton.addActionListener(this);
...........
} // end of my constructor
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
//If button 1 pressed . . .
if (source == myButton1)
{
recordCounter ++;
System.out.println("You have clicked on Button 1. Counter hit is: " + recordcounter );
......
}
//If button 2 pressed . . .
if (source == myButton2)
{
recordCounter ++;
System.out.println("You have clicked on Button 2. Counter hit is: " + recordcounter );
......
}
//If button 3 pressed . . .
if (source == myButton3)
{
recordCounter ++;
System.out.println("You have clicked on Button 3. Counter hit is: " + recordcounter );
......
}
//If Reset pressed . . .
if (source == resetButton) :-(
{
nameField.setText(""
costField.setText(""
System.out.println("You have clicked on RESET button. );
......
}
} // end of actionPerformed method
.....
} // end of my ItsMe class
Any ideas?
Thank you,
Christopher