The method in the class implementing ActionListener should be actionPerformed and not ActionPerformed. ( Note the case of the method name) -----Original Message----- From: RVASUDEV [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 26, 1999 6:50 PM To: [EMAIL PROTECTED] Subject: Partly off-topic: Q on inner classes/ActionListener Hi [Platform: Win NT 4.0 SP3, Sun JDK 1.2.2] While compiling a java application, I get some errors. App and err details below. Any suggestions appreciated. [The program is a simple one to encode/decode a file, the encode/decode logic hasn't been added yet] TIA Vasudev The application : ------------------------------------------------- // Codec1.java import java.awt.*; import java.awt.event.*; import java.io.*; public class Codec1 extends Frame { /** initialize fields */ Label inFileLabel = new Label("Input file name"); TextField inFileName = new TextField(64); Label outFileLabel = new Label("Output file name"); TextField outFileName = new TextField(64); Button encodeBtn = new Button("Encode"); Button decodeBtn = new Button("Decode"); Button exitBtn = new Button("Exit"); TextField status = new TextField(64); FileInputStream fis; BufferedInputStream bis; DataInputStream dis; FileOutputStream fos; BufferedOutputStream bos; DataOutputStream dos; /** main - just creates a new Codec1 object */ public static void main(String[] args) { new Codec1(); } /* no-arg constructor */ public Codec1() { super("Codec1"); // setup GUI setLayout(new FlowLayout()); add(inFileLabel); add(inFileName); add(outFileLabel); add(outFileName); add(encodeBtn); add(decodeBtn); add(exitBtn); add(status); // add listeners encodeBtn.addActionListener(new EncBtnAL()); decodeBtn.addActionListener(new DecBtnAL()); exitBtn.addActionListener(new ExiBtnAL()); enableButtons(); this.setSize(400, 500); this.setVisible(true); this.show(); } /** listener for Encode Button */ public class EncBtnAL implements ActionListener { public void ActionPerformed(ActionEvent ae) { disableButtons(); status.setText("Encoding...please wait"); encode( inFileName.getText().trim(), outFileName.getText().trim() ); enableButtons(); } } /** listener for Decode Button */ public class DecBtnAL implements ActionListener { public void ActionPerformed(ActionEvent ae) { //disableButtons(); status.setText("Not implemented yet"); // decode(inFileName.getText(), //outFileName.getText()); //enableButtons(); } } /** listener for Encode Button */ public class ExiBtnAL implements ActionListener { public void actionPerformed(ActionEvent ae) { System.out.println("Exiting..."); sleep(1); System.exit(0); } } public void encode(String inFileName, String outFileName) { try { fis = new FileInputStream(inFileName); bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); fos = new FileOutputStream(outFileName); bos = new BufferedOutputStream(fos); dos = new DataOutputStream(bos); char c; while ((c = dis.readChar()) != -1) { //c = c ^ c; dos.writeChar((int) c); } status.setText("Encoding complete"); sleep(1); } catch(IOException ioe) { System.out.println("IO error: " + ioe); status.setText("Encode failed"); sleep(1); } finally { try { dis.close(); bis.close(); fis.close(); dos.close(); bos.close(); fos.close(); } catch(IOException ioe) { System.out.println("IO error: " + ioe); status.setText("Close(s) failed"); sleep(1); } } } public void disableButtons() { encodeBtn.setEnabled(false); decodeBtn.setEnabled(false); exitBtn.setEnabled(false); } public void enableButtons() { encodeBtn.setEnabled(true); decodeBtn.setEnabled(true); exitBtn.setEnabled(true); } public void sleep(int seconds) { try { Thread.sleep(seconds * 1000); } catch(InterruptedException ie) { } } } ------------------------------------------------- The errors : C:> javac Codec1.java 2>e C:> type e Codec1.java:47: inner class Codec1. EncBtnAL is an abstract class. It can't be instantiated. encodeBtn.addActionListener(new EncBtnAL()); ^ Codec1.java:48: inner class Codec1. DecBtnAL is an abstract class. It can't be instantiated. decodeBtn.addActionListener(new DecBtnAL()); ^ Codec1.java:59: inner class Codec1. EncBtnAL must be declared abstract. It does not define void actionPerformed(java.awt.event.ActionEvent) from interface java.awt.event.ActionListener. public class EncBtnAL implements ActionListener { ^ Codec1.java:70: inner class Codec1. DecBtnAL must be declared abstract. It does not define void actionPerformed(java.awt.event.ActionEvent) from interface java.awt.event.ActionListener. public class DecBtnAL implements ActionListener { ^ 4 errors ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
Re: Partly off-topic: Q on inner classes/ActionListener
Ramakanth Padmanabhan Sengamedu Tue, 26 Oct 1999 07:20:48 -0700
- Partly off-topic: Q on inner classes/Actio... RVASUDEV
- Re: Partly off-topic: Q on inner clas... Srini
- Re: Partly off-topic: Q on inner clas... Girish Jaju
- Re: Partly off-topic: Q on inner clas... Girish Jaju
- Re: Partly off-topic: Q on inner clas... kavitha ramasamy
- Re: Partly off-topic: Q on inner clas... Ramakanth Padmanabhan Sengamedu
- Re: Partly off-topic: Q on inner clas... Cushman, Michael
- Re: Partly off-topic: Q on inner clas... Stark, Scott (Exchange)
- Re: Partly off-topic: Q on inner clas... Sharat Babu
- Re: Partly off-topic: Q on inner clas... Noble, Charles G. (PS, NE)
- Re: Partly off-topic: Q on inner clas... jhughes
- Re: Partly off-topic: Q on inner clas... RVASUDEV
- Re: Partly off-topic: Q on inner clas... RVASUDEV
