OK, I did some coding, and I am getting the results you mentioned, but I am still not sure why. I created a frame, and added 2 components to it: a Button, and a myButton, which I defined. I first tried to call button1.enableEvents(), and I got an error telling me that method was not visible. That is what you told me to expect. I then used the usual process, added an ActionListener, and got it to work fine. For myButton, I called enableEvents() in the constructor, and then overrode the processActionEvent() method. I added that to my frame, and it works also. So I have a frame with two buttons, both of which respond to action events, one through an event listener and one through explicit event enabling.
I still have the question, though, why I could not call button1.enableEvents(). since the method is defined in Component, as a protected final method, I should be able to call that method from any subclass of Component, or any class in the same package as Component.
import java.awt.*;
import java.awt.event.*;
public class ActionTest extends Frame implements ActionListener
{
class windowHandler extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
Button button1;
MyButton button2;
public ActionTest()
{
addWindowListener(new windowHandler());
button1 = new Button("Button");
button2 = new MyButton("MyButton");
setLayout(new GridLayout(1,2));
add(button1);
add(button2);
// button1.enableEvents(AWTEvent.ACTION_EVENT_MASK);
button1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Button tempbutton = (Button)ae.getSource();
if(tempbutton == button1)
System.out.println("Button 1");
}
public static void main(
String[] args)
{
ActionTest at = new ActionTest();
at.setBounds(10, 10, 50, 200);
at.show();
}
}