[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ActionEvent not compiling when used in ActionPerformed

Posted on 2004-10-28
4
Medium Priority
?
389 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
Comment
Question by:brjattwood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
4 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12435225
include

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

Expert Comment

by:zzynx
ID: 12435231
in fact better replace

     import java.awt.event.ActionListener;

by

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

Accepted Solution

by:
zzynx earned 1500 total points
ID: 12435296
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
ID: 12436956
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

656 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