Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Applets
Search Coderanch
Advance search
Google search
Register / Login
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
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Applets
How to catch event on label
Aayush Patel
Greenhorn
Posts: 21
posted 23 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can someone tell me how can i change background color by clicking on label
Rowan Brownlee
Ranch Hand
Posts: 97
posted 23 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Aayush,
I've not done much with graphics painting, but this works. Any comments, improvements welcome.
cheerio
rowan
import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="MyLabel.class" height=300 width=300> </applet> */ public class MyLabel extends Applet{ private Label clickLabel; private Color colourStore[] = {Color.blue, Color.red, Color.green, Color.cyan, Color.black, Color.gray}; private int count = 0; public void init(){ clickLabel = new Label("Click this label to change background colour"); clickLabel.addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent me){ repaint(); } }); add(clickLabel); } //Don't change colour when applet becomes visible again public void start(){ if(count > 0){ --count; } } public void paint(Graphics g){ if(count >= colourStore.length){ count = 0; } g.setColor(colourStore[count]); g.fillRect(0,0,getSize().width, getSize().height); count++; } }
[This message has been edited by Rowan Brownlee (edited November 24, 2001).]
What's brown and sticky? ... a stick. Or a tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Rotate text field
how label work ?
Label/Component/Listener
Label/Component/Listener
2 struts question ?!
More...