for the 1st class on line 22: ActionClass cannot be resolved
for the 2nd class on line 8: text cannot be resolved
for the first error, the two classes are public and stays in the same package so why cannot see each other?
for the second error, text variable has no access modifier (friendly access),
so it should be seen in the second class
can you help me about these issues? which points i am missing?
Expand|Select|Wrap|Line Numbers
- import java.awt.*;
- import java.awt.event.*;
- public class GuiClass extends Frame {
- TextField text = new TextField(20);
- Button b;
- public static void main(String[] args) {
- GuiClass myWindow = new GuiClass("My first window");
- myWindow.setSize(350,100);
- myWindow.setVisible(true);
- }
- public GuiClass(String title) {
- super(title);
- setLayout(new FlowLayout());
- b = new Button("Click me");
- add(b);
- add(text);
- b.addActionListener(ActionClass);
- }
- }
Expand|Select|Wrap|Line Numbers
- import java.awt.*;
- import java.awt.event.*;
- public class ActionClass implements ActionListener{
- private int numClicks = 0;
- public void actionPerformed(ActionEvent e) {
- numClicks++;
- text.setText("Button Clicked " + numClicks + " times");
- }
- }