Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Troubles with ActionListener and event driven program

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.
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
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic