Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-03-2008, 10:19 PM
Member
 
Join Date: Jan 2008
Posts: 7
Cymro is on a distinguished road
[SOLVED] Actionevent problem
I have decided to shy away from IDEs to try my hand at a text editor (proper? ) approach to coding. However, a major problem:

Code:
import javax.swing.*; import java.awt.*; public class SandBox extends JFrame{ private static void makeGUI(){ JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new FlowLayout()); JButton button = new JButton("Login"); button.addActionListener(new ActionListener()); frame.add(button); frame.pack(); frame.setVisible(true); } public void actionPerformed(ActionEvent e){ System.out.println("Test"); } public static void main(String[] args){ SwingUtilities.invokeLater(new Runnable(){ public void run(){ makeGUI(); } }); } }
when this code compiles, it informs me that it “cannot find symbol” whenver ActionEvent/Listener is referred to. Not exactly what was meant to happen
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-03-2008, 11:07 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
C:\jexp>javac sandboxrx.java sandboxrx.java:21: cannot find symbol symbol : class ActionEvent location: class SandBoxRx public void actionPerformed(ActionEvent e){ ^ sandboxrx.java:14: cannot find symbol symbol : class ActionListener location: class SandBoxRx button.addActionListener(new ActionListener()); ^ 2 errors
1 - import java.awt.event.*;
recompile:
Code:
C:\jexp>javac sandboxrx.java sandboxrx.java:15: java.awt.event.ActionListener is abstract; cannot be instantiated button.addActionListener(new ActionListener()); ^ 1 error
Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SandBoxRx implements ActionListener { private void makeGUI(){ JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new FlowLayout()); JButton button = new JButton("Login"); // The jvm is looking for the "ActionListener" class // on your classpath. Since ActionListener is a Java // class then this is doubly confusing. button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("anonymous ActionListener"); } }); button.addActionListener(this); button.addActionListener(new SandBoxListener()); frame.add(button); frame.pack(); frame.setVisible(true); } // Implementation of ActionListener interface // implemented by the enclosing class. public void actionPerformed(ActionEvent e){ System.out.println("Enclosing class-implemented ActionListener"); } private class SandBoxListener implements ActionListener { public void actionPerformed(ActionEvent e) { System.out.println("SandBoxListener ActionListener"); } } public static void main(String[] args){ EventQueue.invokeLater(new Runnable(){ public void run(){ new SandBoxRx().makeGUI(); } }); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-03-2008, 11:13 PM
Member
 
Join Date: Jan 2008
Posts: 7
Cymro is on a distinguished road
Thank you very much. It all works now
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-04-2008, 08:11 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 750
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
I applaud your goal of working with your text editor instead of an IDE. It's my belief it will make you a better programmer- once you've got the fundamentals solidly down, you should move back to the IDE or only move back to the IDE when time constraints and many lines of code are required. They help to reduce production times.

Now that your problem is sufficiently solved, take the time to mark your thread as "Solved" using the Thread Tools at the top.

Best of luck.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on July 13, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] alignment problem nanimtech JavaServer Pages (JSP) and JSTL 1 04-10-2008 02:23 PM
[SOLVED] Problem with setVisible(); on LINUX lepetitprince AWT / Swing 6 04-07-2008 03:14 PM
[SOLVED] file i/o problem aytidaalkuhs New To Java 3 04-06-2008 07:42 PM
[SOLVED] Problem with code - inheritence yalla New To Java 1 03-30-2008 07:11 AM
ActionEvent example Java Tip Java Tips 0 03-12-2008 12:00 AM


All times are GMT +3. The time now is 04:07 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org