Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Troubles with ActionListener and event driven program

 
John Bishop
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic