• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mouse event for an array of object

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible add moseDragged event for an array of rectangle...
 
shalini gnana
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any help?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic