Results 1 to 4 of 4
- 02-12-2011, 10:26 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 27
- Rep Power
- 0
Does Each Shape requre a new Panel?
Hi,
I've been trying to search the net on this topic and haven't had much luck. I am trying to draw a variety shapes each having different stroke sizes etc.
The way I am doing it now doesn't seem to be very efficient. I am creating a new class that extends jPanel and then draw my shape under the paint method. Am I going to have to do this for every little shape?
Can't I have one class with many different paint methods or something? Like paintRect or paintLine, and then in the paintRect I call g2.draw(new Rectangle2D(...)). This doesn't work but I think I want something like that.
Any help would be great. Thanks everyone.
- 02-12-2011, 11:47 PM #2
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
All you need is one JPanel.
You can then use the paintComponent method to draw as many shapes as you want in that method.
Java Code:private static class ExamplePanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); g.drawString( "Hello World!", 20, 30 ); } }Last edited by Humbly; 02-12-2011 at 11:47 PM. Reason: Forgot code tags
- 02-13-2011, 01:44 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 27
- Rep Power
- 0
Thanks Humbly,
So unless Im missing something huge here, I still don't see how this will work.
If I draw multiple shapes with this they all have to have the same linewidth right? What if I want shapes with different linewidths? Or if I want to set different opacities on each shape.
- 02-13-2011, 05:22 AM #4
Senior Member
- Join Date
- Feb 2011
- Posts
- 118
- Rep Power
- 0
Similar Threads
-
panel on a panel not visible
By warchieflll in forum Advanced JavaReplies: 2Last Post: 01-29-2011, 08:29 PM -
Add panel to parent panel
By LovJava in forum AWT / SwingReplies: 10Last Post: 09-02-2010, 08:43 PM -
how to change the shape of the JFrame to a oval shape
By kiki2009 in forum Java 2DReplies: 1Last Post: 04-02-2010, 12:48 PM -
Adding a panel to a panel
By rclausing in forum New To JavaReplies: 7Last Post: 02-02-2010, 05:56 AM -
implementing shape
By sidkdbl07 in forum Java 2DReplies: 1Last Post: 01-12-2008, 06:42 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks