Results 1 to 2 of 2
- 11-05-2012, 07:59 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 24
- Rep Power
- 0
can several seperate paint component classes draw on the one jpanel
i am trying to use good oop practices for my gui game. as the question asks, can you draw seperately on one container?
some code:
Java Code:@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.RED); g2.fillRoundRect(600, 100, 100, 100, 20, 20); g2.setBackground(Color.BLUE); g2.setColor(Color.CYAN); g2.fillOval(400, 200, 200, 200);
Java Code:@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.RED); g2.fillRoundRect(200, 100, 100, 100, 20, 20); g2.setBackground(Color.BLUE); g2.setColor(Color.CYAN); g2.fillOval(700, 200, 200, 200);
thx!
- 11-05-2012, 08:09 PM #2
Re: can several seperate paint component classes draw on the one jpanel
Not really sure what you're actually doing with that code- an SSCCE would be much better.
You can pass the Graphics instance to whatever method you want, including methods in other classes that contain some rendering logic. You only have to override paintComponent once though.How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
Similar Threads
-
Can't paint my Buffered image on my component?
By Bram in forum New To JavaReplies: 2Last Post: 06-05-2012, 05:22 PM -
help importing pictures into paint component of another class.
By Grid_iso in forum New To JavaReplies: 1Last Post: 05-20-2011, 02:59 PM -
Placing a new JPanel over a paint overriden JPanel
By Tanshaydar in forum AWT / SwingReplies: 4Last Post: 12-08-2010, 07:00 PM -
Conditions through seperate classes
By LennyKosmos in forum New To JavaReplies: 9Last Post: 09-22-2010, 05:10 PM -
Custom component and paint outside of bounds
By happy_hippie in forum AWT / SwingReplies: 2Last Post: 06-30-2010, 06:41 PM
Bookmarks