I'm trying to get these two classes to work together:
import java.applet.*; import java.awt.*; /* <applet code = Buttons.java width = 100 height = 100> </applet> */ public class Buttons extends Applet { Label label = new Label("Push the button!"); Button button = new Button("Push me!"); Pushed pushed = new Pushed(); public void init () { this.add(button); this.add(label); } }
import java.awt.event.*; public class Pushed implements ActionListener { Buttons buttons = new Buttons(); buttons.addActionListener(buttons.button); public void actionPerformed(ActionEvent ae) { String actionStr = ae.getActionCommand(); if (actionStr.equals("Push Me!")) { System.out.println("Stop pushing my buttons!"); } } }
Right now, Buttons compiles only when the the Pushed object is commented out and tells me that that it expects identifiers in front of the occurrences of "buttons.button" and that the package "buttons" cannot be found when the Pushed object is included in the code. The compiler also says that it expects identifiers in front of the occurrences of "buttons.button" when it tries to compile Pushed.
Can I have a "static" GUI class that simply extends the Applet class and a "dynamic" engine class that only implements the ActionListener interface?
Or do I have to have both classes implement ActionListener so that I can have the calls to *.assActionListener in side an initialization block and can pass an ActionEvent to Pushed?