View Single Post
  #5 (permalink)  
Old 11-03-2007, 12:39 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
I copied, pasted (into a new folder) and compiled your last posted code and got these in the console:
Code:
C:\jexp\flightInterface>javac FlightInterface.java FlightInterface.java:84: cannot find symbol symbol : class ActionEvent location: class FlightInterface public void actionPerformed(ActionEvent e){ ^ FlightInterface.java:69: addActionListener(java.awt.event.ActionListener) in jav ax.swing.AbstractButton cannot be applied to (FlightInterface) exitButton.addActionListener(this); ^ FlightInterface.java:85: cannot find symbol symbol : variable exitButton location: class FlightInterface if(e.getSource() == exitButton){ ^ 3 errors
Make the following changes to compile and run okay:
Code:
// Add import statement. import java.awt.event.*; // Implement ActionListener so "this" can be an ActionListener public class FlightInterface implements ActionListener { // Declare exitButton as a member variable. // This puts it in class scope where it can be // accessed inside the actionPerformed method. JButton exitButton; startButton.setFont(new Font("Serif", Font.PLAIN, 14)); // Remove the type declaration from the instantiation so // that exitButton is not a local variable hiding the // member variable (of the same name) which would remain // uninstantiated and thus have a value of null, causing // NullPointerExceptions when you try to access it in // the actionPerformed method. exitButton = new JButton("Exit");
I did not get the compile errors you reported. The console errors give the line number of the trouble to help track it down. Maybe you omitted a semi-colon somewhere above the actionPerformed method.
Reply With Quote