aspose file tools*
The moose likes Beginning Java and the fly likes loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "loop" Watch "loop" New topic
Author

loop

tan man
Greenhorn

Joined: Oct 18, 2005
Posts: 1
i created a programe to change the color of the box while the is clicked in the box and outside the box, for this to change colour i have to run the programe several time.

I would like to add a loop code so it can change when i run the programe once.

this is the code i used:

import element.*;
import structure.*;
import java.awt.Color;

public class IfMouse
{
public static void main(String args[])
{
DrawingWindow d = new DrawingWindow();
Rect r = new Rect(40,40,40,40);

Pt p;

r.drawOn(d);
d.awaitMousePress();
d.moveTo(d.getMouse());

p=d.getMouse();

if(r.contains(p))
{
d.setForeground(Color.red);
d.fill(r); // color the circle
}
else if

(d.mousePressed())

d.setForeground(Color.blue);
d.fill(r);


}
}
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, welcome to the ranch!

I'm not sure what your DrawingWindow is, but I'm going to guess it is an awt Component or Swing JComponent of some kind. In either event, look at the method addMouseListener(). That will lead you to look at MouseListener. When these are all linked up, a mouse click on the component will fire the mouseClicked() method and you can change color there.

Give this a try using the javadoc and maybe some Swing tutorials on the web. If you get some working code or "almost working" code, bring it back and let us see how you're doing!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: loop