View Single Post
  #2 (permalink)  
Old 04-04-2008, 12:07 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
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(); } }); } }
Reply With Quote