• 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

Has anyone tried to Create Rounded Rectangles extending the Shapes class of Java AWT ?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This is how I create rounded rectangles and if I create rounded rectangles in this fashion, the code cannot be reused.

But if I could create a Class Rounded Rectangle that extends Shape Class of Java, I can use it anywhere and anytime.

Java AWT's GEOM class and Graphics2D class are not supported in my Virtual Machine environment, So the only way to create Rounded Rectangle is to use drawRoundRect function of Graphics class. But doing this way has so many disadvantages.

                      If I create 4 shapes, and if I want to add key listener to 4 shapes and on click of a shape a new screen should open, since I dont have Geom Class support, I cant store rounded rectangle shapes in an arraylist and access it. I have to every time detect the pixels space between 2 rounded rectangles to detect the Click event.  

So I am looking for a possible code example of Rounded Rectangle created by extending Shapes class.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought there already was a rounded rectangle class in the java.awt.geom package. You shou‍ld find details in the 2D part of the Java™ Tutorials.
 
Ganesh Ramachandran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java.awt.geom package has support for Rounded Rectangle. But my problem is that, the environment in which I write my code has only selected packages of AWT. GEOM package in AWT is not available in the environment I work on.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My, you must be using an old implementation. The java.awt.geom package was introduced about 1997. There is no such thing as the GEOM class. The only Shape class is a JavaFX class; there is a Shape interface.

Somebody was talking about old implementations a few weeks ago. They couldn't use 2D graphics. Was it you?
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can create a class that has a 'draw' method that draws a round rectangle.
Say we have this interface:

The first abstract method is when a mouseListener reports a MouseEvent, that you can check whether the Point in question lies within whatever implements this interface.
For instance:

So, Shape is not implemented, but I fail to see what good that would be. Can you elaborate a little? It is not difficult to implement it, by the way, although it is not so easy to get a PathIterator.

As an example, you can see what a PathIterator involves with:
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic