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 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 Murach's Java Servlets and JSP this week in the Servlets 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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: mouse event for an array of object
 
Similar Threads
Help in adding ActionListener.
Passing values to form bean string array
WA #1.....word association
Event Handling
Object[]