GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Not able to run ActionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Not able to run ActionListener " Watch "Not able to run ActionListener " New topic
Author

Not able to run ActionListener

Thunthu Ganapathy
Greenhorn

Joined: May 09, 2000
Posts: 19
I could compile the following program and While running using appletviewer I get an error message saying I/O exception while reading. Make sure that ListenerTest is a file and is readable.
Here is the program.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class MyActionListener implements ActionListener
{
public void actionPerformed (ActionEvent ae) {
System.out.println("Action Performed");
}
}

public class ListenerTest extends Applet {
public void init() {
Button btn = new Button("OK");
MyActionListener listener = new MyActionListener();
btn.addActionListener(listener);
add(btn);
}
}
Could any one throw some light?.
Thanks,
Thunthu
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I don't know how did you try to run your program. But I just tried this way and it runs perfect.
< html>
< body>
< applet code = ListnerTest width = 100 height = 100> < /applet>
< /body>
< /html>
cut and paste the above code into a file in the same directory with xxx.html extention. Now run the program with
appletviewer xxx.html
As I know this is the only way to run the applet.
[I edited this to put spaces after each "<" so that it would display the HTML tags rather than executing / interpreting them. To run this, remove the speace from the beginning of each HTML tag. - Jim]
[This message has been edited by Jim Yingst (edited June 27, 2000).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I guess my code became an html file.
pls. take these code
"<applet code = ListenerTest width = 100 height = 100> </applet>"
put the above code with basic html tags.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I don't know how did you try to run your program. But I just tried this way and it runs perfect.

applet code = ListnerTest width = 100 height = 100
cut and paste the above code into a file in the same directory with xxx.html extention. Now run the program with
appletviewer xxx.html
As I know this is the only way to run the applet.
sgwbutcher
Ranch Hand

Joined: May 13, 2000
Posts: 56
The code compile and runs fine for me under MacOS 8.6, MRJ 2.2 (JDK 1.1.8).
So...no I can't shed any light.
Maybe an appletviewer misconfiguration?
Best regards,
Steve Butcher
exceptionraised@aol.com


-------------------------<BR>Steve<BR>sgwbutcher@aol.com<BR>http://hometown.aol.com/sgwbutcher/
Thunthu Ganapathy
Greenhorn

Joined: May 09, 2000
Posts: 19
Yes. Thanks guys. I just tried in other machine and worked just fine. I guess the problem is with my machine.
Thanks again,
Thunthu
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Not able to run ActionListener