• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

applet

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to create my own object(like rectangle), should be able to
display 10(more than one) of these objects in random anywhere in the applet and they should be able to respond to events(like mousePressed). How to create the object and where to call (in paint?).
muru
 
murugesan subramani
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello! some one help me!
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi murugesan,
don't be so impatient.
you will need a Vector to hold your objects. Next you will have to use the java2d api (java.awt.geom pakage). you have a Rectangle2D.Double and a Rectangle2D.Float class. you can use any of these to define your rectangle depending on the precision you want. you can create a new rectangle using new Rectangle2D.Double( x, y, width, height). if you want to store some extra information like the color etc. then you will have t define your own object otherwise you can use the Rectangle2D class itself to be stored on the Vector.
In the paint() method simply clear the draing area and redisplay the contents of the Vector using the Graphics2D.draw() method. Associate a mouse listener with the panel on which you are drawing. in the mousePressed() method of the listener, use Rectangle2D.contains method to find whether the clicked point is inside a rectangle or not. if it returns true, simply update the object in the Vector and call a repaint() for the panel.
Good Luck,
Amit
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic