• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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: 70215
281
  • Mark post as helpful
  • send pies
  • 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
  • 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: 70215
281
  • Mark post as helpful
  • send pies
  • 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: 4066
156
  • Mark post as helpful
  • send pies
  • 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:
 
    Bookmark Topic Watch Topic
  • New Topic