• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Homework Question (Not looking for someone to do it for me!!)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been trying to figure this out for a while now. Normally I just keep trying until I make it work. The assignment is: Create a JApplet with a JButton that displays my name in blue the first time it is clicked. The second time it is clicked my name should disappear and then print again in bigger dark gray font. This is what I have:

And my button does....ABSOLUTELY NOTHING when I push it. I've been all over the map. First when I ran the applet it showed my button and my name in blue and if I pushed the button my name went away. Then it stopped displaying anything but the button. Can anyone tell me what in the bejebers I'm doing wrong? Maybe I've been staring at this too long!!


Edit by mw: Added Code Tags.
[ March 20, 2008: Message edited by: marc weber ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

I don't have much experience with applets, but I noticed a few things...

You're missing a semicolon after the first line in the paint method.

Your "else if" block is indented to suggest that the 4 lines after it should execute with the "if" condition, but there are no braces here, so only the first line is executing as part of the "if." The other 3 will always execute whenever the method is invoked. I think that's causing a problem for you.

After setting the color to white, don't you want to draw the String again?

(Note: I tested this using an Applet viewer, and the position of 250, 250 was out of range. After changing this to 50, 50, the String displayed.)
 
author & internet detective
Posts: 39348
755
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rebekah,
We have a separate forum for Applets. I'm going to move your thread there. Not everyone knows about Applets, but the people in that forum know it well!
 
Rebekah McKenna
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys! Thanks for all the help. I've fixed a couple of things and I think my code is finally working! I was so close...and to find my errors were small things I overlooked...frustrating!!! Thanks again! I'll try to post in the correct forum next time!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!