aspose file tools*
The moose likes Applets and the fly likes Troubles with ActionListener and event driven program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Troubles with ActionListener and event driven program" Watch "Troubles with ActionListener and event driven program" New topic
Author

Troubles with ActionListener and event driven program

John Bishop
Greenhorn

Joined: Apr 01, 2004
Posts: 1
I've been trying to write an applet for a class I'm currently in. The assignment states that we are to create an applet which displays our name using a color drawn from a parameter in the html calling the applet. The background color is designated the same way. Finally the applet is to include a button which, when clicked displays a second string below the first string and button.
If anyone could point out my error(s) I would greatly appreciate it.
Jason Huntz
Greenhorn

Joined: Mar 10, 2004
Posts: 7
Currently it doesn't look like most of your code will even get called. The method public void init() will get called when you initialize the applet and
public void start() will get called when the applet starts. Your init(Graphics g) doesn't look like it will ever get called the way it is set up now.
Also, using the graphics class directly usually isn't necessary. Unless your teacher told you to do it that way specifically, you should probably have your name set in a Label and add the label to the applet in the same way you do your button. If your teacher did say to use the graphics specifically, you should understand that the entire applet is redrawn when paint(Graphics g) is called. Any direct painting using methods like g.drawstring that is done outside of this method will be overwritten every time the paint(Graphics g) method is called
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Troubles with ActionListener and event driven program