This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes mouse event for an array of object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "mouse event for an array of object" Watch "mouse event for an array of object" New topic
Author

mouse event for an array of object

shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
Is it possible add moseDragged event for an array of rectangle...
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
How to drag an array of rectangle..If its a single rectangle,then we can say,

.....
//drawing the rectangle
g2.drawrect(rectx,recty ,10,10);
....
....
public void mouseDragged(MouseEvent e)
{
//Moving the rectangle to new position
rectx = e.getx();
......
}
{code}

if this is the case,How can we move...
protected void paintComponent(Graphics g)
{for(int k = 0;k<5;k++)
{
rect.setBounds(rectx [k];k<rectx.length;k++)
g2.fill(rect);
}
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
Any help?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

For your approach to work (updating paint location of rectangle) you'll need to compute the difference between the old location and the new location and update every rectangle in the array.

You could also paint all the rectangles in one component and move the entire component around in mouseDragged.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mouse event for an array of object