asiavoices
Programmer
Hello everyone,
I have a peculiar problem in (as I described in the subject line)that actionPerformed method is not excuting .
I have no errors during compilation and when a click on a button, nothing happens.
Here's my version of actionPerfomed....
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()
{
..........
JButton myButton1 = new JButton("Button 1"
myButton1.addActionListener(this);
...........
JButton myButton2 = new JButton("Button 2"
myButton2.addActionListener(this);
...........
JButton myButton3 = new JButton("Button 3"
myButton4.addActionListener(this);
...........
JButton myButton4 = new JButton("Button 4"
myButton4.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 button 4 pressed . . .
if (source == myButton4)
{
recordCounter ++;
System.out.println("You have clicked on Button 4. Counter hit is: " + recordcounter );
......
}
} // end of actionPerformed method
.....
} // end of my ItsMe class
Any ideas?
Thank you,
Christopher
P.S. I understand there are alternate ways of doing this but this makes it clearer for me to read.
I have a peculiar problem in (as I described in the subject line)that actionPerformed method is not excuting .
I have no errors during compilation and when a click on a button, nothing happens.
Here's my version of actionPerfomed....
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()
{
..........
JButton myButton1 = new JButton("Button 1"
myButton1.addActionListener(this);
...........
JButton myButton2 = new JButton("Button 2"
myButton2.addActionListener(this);
...........
JButton myButton3 = new JButton("Button 3"
myButton4.addActionListener(this);
...........
JButton myButton4 = new JButton("Button 4"
myButton4.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 button 4 pressed . . .
if (source == myButton4)
{
recordCounter ++;
System.out.println("You have clicked on Button 4. Counter hit is: " + recordcounter );
......
}
} // end of actionPerformed method
.....
} // end of my ItsMe class
Any ideas?
Thank you,
Christopher
P.S. I understand there are alternate ways of doing this but this makes it clearer for me to read.