• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

ActionEvent not compiling when used in ActionPerformed

I get the following error

"loginGUI.java": cannot resolve symbol: class ActionEvent in class asys.loginGUI.ButtonListener at line 106, column 34

In Jbuilder10 from the following code

Please advise me where i am going wrong. Thanks in advance.

My "main" is in a separate class called AsysMain
Exert is listed below this class

package asys;

import javax.swing.*;
import java.awt.*;
import java.lang.*;
import java.awt.event.ActionListener;








public class loginGUI extends JFrame {

  void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy)
{
 gbc.gridx = gx;
 gbc.gridy = gy;
 gbc.gridwidth = gw;
 gbc.gridheight = gh;
 gbc.weightx = wx;
 gbc.weighty = wy;
}

  JPanel loginPane = new JPanel();
  JLabel usernameLabel = new JLabel("Username: ");
  JTextField username = new JTextField();
  JLabel passwordLabel = new JLabel("Password: ");
  JPasswordField password = new JPasswordField();
  JButton submit = new JButton("Submit");
  JButton clear = new JButton("Clear");

  public loginGUI() {
    super("Asys Log in");

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //loginPane.setLocation(128,128);
    loginPane.setSize(500,500);
    GridBagLayout gridbag1 = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    setContentPane(loginPane);

    //usernameLabel
    buildConstraints(constraints,0,0,1,1,100,100);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.anchor = GridBagConstraints.EAST;
    gridbag1.setConstraints(usernameLabel,constraints);
    loginPane.add(usernameLabel);

    //username textbox
    buildConstraints(constraints,1,0,2,1,100,100);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.WEST;
    gridbag1.setConstraints(username,constraints);
    loginPane.add(username);

    //passwordLabel
    buildConstraints(constraints,0,1,1,1,100,100);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.anchor = GridBagConstraints.EAST;
    gridbag1.setConstraints(passwordLabel,constraints);
    loginPane.add(passwordLabel);

    //password textbox
    buildConstraints(constraints,1,1,2,1,10,100);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.WEST;
    gridbag1.setConstraints(password,constraints);
    loginPane.add(password);

    //submit button
    buildConstraints(constraints,1,2,1,1,100,100);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.CENTER;
    gridbag1.setConstraints(submit,constraints);
    loginPane.add(submit);
    submit.addActionListener(new ButtonListener());


    //clear button
    buildConstraints(constraints,2,2,1,1,100,100);
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.CENTER;
    gridbag1.setConstraints(clear,constraints);
    loginPane.add(clear);
    clear.addActionListener(new ButtonListener());


    loginPane.setLayout(gridbag1);




  }//koginGUI

  class ButtonListener implements ActionListener
  {
     public void actionPerformed(ActionEvent event)
     {
       Object target = event.getSource();
       
       if (target == submit)
       {
         System.out.println("Submit button pressed");
       }//if
     }//actionPerformed
  }
 


}

   GUI mainFrame = new GUI();
      loginGUI loginFrame = new loginGUI();

      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

      int width = screenSize.width / 2;
      int height = screenSize.height / 2;

      loginFrame.setLocation(width,height);
      loginFrame.setSize(300,200);
      loginFrame.setVisible(true);

      mainFrame.setSize(mainFrame.getToolkit().getScreenSize());
      mainFrame.setVisible(true);
0
brjattwood
Asked:
brjattwood
  • 4
1 Solution
 
zzynxSoftware engineerCommented:
include

        import java.awt.event.*;
0
 
zzynxSoftware engineerCommented:
in fact better replace

     import java.awt.event.ActionListener;

by

     import java.awt.event.*;
0
 
zzynxSoftware engineerCommented:
Explanation:
- the class ActionEvent is defined in the package java.awt.event
- By writing
        import java.awt.event.ActionListener;
  you only import the class ActionListener

- if you write

       import java.awt.event.*;

  you import all classes of the package java.awt.event (all the classes you use in your code)
0
 
zzynxSoftware engineerCommented:
Thanks for accepting

But I think my answer deserved an A grade instead of a B.
Did you know giving an A grade doesn't cost you any more points while
we get the number of points multiplied by 2 for a C, 3 for a B and 4 for an A?
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now