Giving Rectangle2D a border

S

Scott Steiner

Hi,

is it possible to give a rectangle (class: Rectangle2D) a 3D-like
border? I'm relatively new to java and can't seem to figure out if this
is possible and how it could be accomplished.

Thanks.
 
J

jan V

is it possible to give a rectangle (class: Rectangle2D) a 3D-like
border? I'm relatively new to java and can't seem to figure out if this
is possible and how it could be accomplished.

Note that Rectangle2D is an abstract GEOMETRIC rectangle (it's in the *.geom
package). No pure geometric entity will have any rendering-related
functionality (separation of concerns, etc..).

Graphics and Graphics2D do a lot of rendering for you... and there's a
draw(Shape) method in Graphics2D... and Rectangle2D is a Shape. Hence... ;-)
 
S

Scott Steiner

jan said:
Note that Rectangle2D is an abstract GEOMETRIC rectangle (it's in the *.geom
package). No pure geometric entity will have any rendering-related
functionality (separation of concerns, etc..).

Graphics and Graphics2D do a lot of rendering for you... and there's a
draw(Shape) method in Graphics2D... and Rectangle2D is a Shape. Hence... ;-)

I don't think I quite understand, what are you implying with the last
sentence?

thx!
 
J

jan V

Note that Rectangle2D is an abstract GEOMETRIC rectangle (it's in the
*.geom
;-)

I don't think I quite understand, what are you implying with the last
sentence?

Well, if you're already woring with Rectangle2D objects, then you could pass
them to Graphics2D.draw() and the Graphics2D object will render your
rectangle. You could obtain 3D-like borders by drawing two rectangles
slightly offset from each other, and using two colours (light and dark) for
each rendered rect. That would give you essentially an raised or etched
border effect, which is what you're after, ... ?
 
S

Scott Steiner

jan said:
Well, if you're already woring with Rectangle2D objects, then you could pass
them to Graphics2D.draw() and the Graphics2D object will render your
rectangle. You could obtain 3D-like borders by drawing two rectangles
slightly offset from each other, and using two colours (light and dark) for
each rendered rect. That would give you essentially an raised or etched
border effect, which is what you're after, ... ?

What I actually want to accomplish is this:

I implementing a backgammon board game. The board is a JPanel that has a
very long paintComponent() method where all the drawing is done (lots of
shapes, rectangles and polygons...). I want to give certain rectangles a
raised 3D border, so I used fill3DRect(). However, this method uses the
current color exclusively and ignores the current paint which is not so
good since I want to fill the rectangle with a texturepaint. So this
won't work:

....
TexturePaint tp = new TexturePaint(bImage, tr);
g2D.setPaint(tp);
g2D.fill3DRect(...);
....

So now I'm looking for a way to draw a rectangle in my paintComponent()
method that has a 3D raised border and that can contain a texturepaint.
I'm kind of stuck on this for a couple of weeks now :-(
 
J

jan V

So now I'm looking for a way to draw a rectangle in my paintComponent()
method that has a 3D raised border and that can contain a texturepaint.
I'm kind of stuck on this for a couple of weeks now :-(

Ever considered drawing the most gorgeous-looking board square (with and
without 3D raised border) in something like Photoshop, saving the square as
a GIF/JPEG/PNG, and then using drawImage() to blast whatever you had in mind
onto your screen? Forget about the Graphics2D primitives altogether?

Not everything has to be rendered "manually", cheating is a way of life in
game software you know :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top