• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to run ActionListener

 
Thunthu Ganapathy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Thunthu Ganapathy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Thanks guys. I just tried in other machine and worked just fine. I guess the problem is with my machine.
Thanks again,
Thunthu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic