A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Applets
Author
How to catch event on label
Aayush Patel
Greenhorn
Joined: Apr 26, 2001
Posts: 21
posted
Nov 23, 2001 01:46:00
0
Can someone tell me how can i change background color by clicking on label
Rowan Brownlee
Ranch Hand
Joined: Aug 07, 2000
Posts: 97
posted
Nov 24, 2001 01:47:00
0
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).]
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: How to catch event on label
Similar Threads
Label/Component/Listener
Rotate text field
Label/Component/Listener
2 struts question ?!
how label work ?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter