• 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

Java 2D Shape classes (design question)

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone. Been riding the fence on a design decision and I was hoping someone could stear me in the right direction.
First has anyone worked with the 2DLine objects much? I've got a class that extends from the Rectangle shape but their is no easy way to extend a Line object. It basically has two static factory methods which kind of puts a cramp in the direction I was going with my Rectangle class.
I want a clean way via a mediator to handle events on objects drawn in a JPanel. They are loaded in via a file and drawn into a JPanel at the moment. My demo works fine and I'm happy with it but I'm worried about how it will scale. Right now I'm using the JPanel's paint(Graphic) to draw the images into.
I parse a file that contains a uniqueID, color and icon name. I basically need to allow them to click on a rectangle, then a line and make an entry into a JPanel(BorderLayout.South).add(myJTable).
What is the best way to handle the events?
Do I have this objects extend JComponent? I see a lot of examples that do. If I do that I can override the tooltip text messages for free and do some neat stuff.
Do I implement the objects as Shape and have the Graphics 'canvas' passed in and the object draw into it?
Can't decide but my deadline for the beta is before Thanksgiving so any help would be appreciated.
Been reading and looking at examples and can't find ANYTHING that is like what I want to do. I basically want to do something JUST LIKE TogetherJ with the mouse clicks on UML shapes updating via mediator other associated component views.
Thanks for reading. Look forward to your comments on this thread.
Ed
 
Ed Tidwell
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just an FYI for anyone who may have this question.
I picked JComponent for several reasons. I get tooltips free. It offers double buffering. Mouse events are easy to register. Last but not least. I can set a Panel to the (null) layout manager and just do a panel.add(jcomponentShape).
I can add a border to do neat stuff. I can also just add a JLabel to to give the object a name.
Works out very well.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reporting your decision - how many components are you going to be managing on a single display?
Bill
 
Ed Tidwell
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see there ever being more than 50 items but on a rare occasion it could get that high. 100 items are the max.
I've basically built to ArrayList lookup tables. One for the rectangles and another for the lines connecting the rectangles.
For now I have all my rectangle objects as JPanels and set their x, y, width and height properties as well as color. Set the parent layout manager to be (null) for X Y layout and it works very well. It didn't even require me to do any code in the paint thread at all. Works pretty fast as well.
I don't need the user to move anything. Only click the appropiate rectangle and assign it a location.
Thanks for asking.
 
Ed Tidwell
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just so some poor soul doesn't read this and spend a waste time.
I have rectangles and lines. The lines are drawn in the paintComponent thread of the parent panel.
Child rectangles are given a color, tooltip, JLabel name BorderLayout.Center and then parentPanel.add(child);
The lines that connect the rectangles get the center point from the JPanel rectangle for point1 and then the adjoining rectangle which is point2.
Anyway it works very well and I'm having a lot of fun with it.
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic