This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Applets and the fly likes Adding a button? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Adding a button?" Watch "Adding a button?" New topic
Author

Adding a button?

James Hambrick
Ranch Hand

Joined: Sep 04, 2004
Posts: 282

I have an applet and I want to add a button that clears the screen. I found some code that has a button to change the text color so I looked at it and added the parts to mine and concerned the button.
Here's the code I have. Right now I just have it setup so that when you click the button is changes the background color to test it out. It will not show the button on the applet..



[ July 08, 2007: Message edited by: James Hambrick ]
[ July 08, 2007: Message edited by: Bear Bibeault ]

Visit my blog! http://jameshambrick.com
James Hambrick
Ranch Hand

Joined: Sep 04, 2004
Posts: 282

i was just thinking that I should use Swing and not AWT so im going to try and switch it around to use Swing. Any help is appreciated.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
It works fine for me in appletviewer. Could the problem be that the applet tag has a "heigth" attribute, instead of "height"?

BTW, your homepage link is broken.
[ July 08, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
James Hambrick
Ranch Hand

Joined: Sep 04, 2004
Posts: 282

Yea, it shows in IE, but using Firefox it does not show up, I guess thats a reason I should use Swing and not AWT. Thanks for pointing that out. I though it looked right but it was not working which is pretty frustrating for me.
James Hambrick
Ranch Hand

Joined: Sep 04, 2004
Posts: 282

So now that's out of the way, how do I clear the screen. Someone suggested drawing a rectangle the size of my applet and then filling it with my background color. Is there are better way, thats easy but seems like there would be ramifications by doing so.

[ July 08, 2007: Message edited by: James Hambrick ]

[ July 08, 2007: Message edited by: James Hambrick ]
[ July 08, 2007: Message edited by: James Hambrick ]
Shoumin Li
Ranch Hand

Joined: Jul 06, 2007
Posts: 85
Originally posted by James Hambrick:
[QB]So now that's out of the way, how do I clear the screen. Someone suggested drawing a rectangle the size of my applet and then filling it with my background color. Is there are better way, thats easy but seems like there would be ramifications by doing so.
I think drawing a rect filled backgroud color may be the easiest way,
And it has a good efficency


Java Blog
James Hambrick
Ranch Hand

Joined: Sep 04, 2004
Posts: 282

I also now have it made in Swing and also added a button that changes the foreground color to red. But when I click clear screen my Red button does not show up until my mouse goes over it. Why is this???

Also I have this code


If I draw a line, then change the color, that line changes color. I only want the lines to be a different color after I click the button. I zeroed out the PmouseX, PmouseY, RmouseX and RmouseY and that worked except for that when I drew lines too fast the lines would start from the upper left corner(0,0). Any Ideas?
[ July 09, 2007: Message edited by: James Hambrick ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
One thing that jumps out at me is that string comparison is done using the equals method in Java, so



should be

James Hambrick
Ranch Hand

Joined: Sep 04, 2004
Posts: 282

Thanks for the improvement. Ill try and figure out the code some more later about the last line drawn turning the color of the button I click.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Adding a button?
 
Similar Threads
Help: anonymous class
i'm getting an error start:applet not intialized.
Clear Screen
can't figure it out
How to setColor(Variable)