Solved

ActionEvent not compiling when used in ActionPerformed

Posted on 2004-10-28
349 Views
Last Modified: 2010-03-31
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
Question by:brjattwood
    4 Comments
     
    LVL 37

    Expert Comment

    by:zzynx
    include

            import java.awt.event.*;
    0
     
    LVL 37

    Expert Comment

    by:zzynx
    in fact better replace

         import java.awt.event.ActionListener;

    by

         import java.awt.event.*;
    0
     
    LVL 37

    Accepted Solution

    by:
    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
     
    LVL 37

    Expert Comment

    by:zzynx
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    This video teaches viewers about errors in exception handling.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    845 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    5 Experts available now in Live!

    Get 1:1 Help Now