File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mouse event for an array of object

 
shalini gnana
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible add moseDragged event for an array of rectangle...
 
shalini gnana
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any help?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic