Results 1 to 6 of 6
Thread: paintComponent problem
- 04-01-2011, 10:59 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 62
- Rep Power
- 0
paintComponent problem
Hello,
I am trying to make a separate method called draw() that draws some figures on the screen.
When I try this
I get error message immediately from Eclipse.Java Code:void draw(){ public void paintComponent( Graphics g ){ super.paintComponent(g); int w = getWidth(); int h = getHeight(); g.setColor(Color.BLUE); g.drawLine(w/4, h/2, (w*3)/4, h/2); . . . } }
Can someone, please explain me what I am doing wrong?
Thank you.Last edited by luke; 04-01-2011 at 11:02 PM.
- 04-01-2011, 11:07 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
I need more information, what error message exactly?(copy and paste them)
- 04-01-2011, 11:12 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 62
- Rep Power
- 0
-
You've got a method (paintComponent) inside of another method (draw). Makes no sense.
Solution: don't nest methods. I also have a feeling that you'd benefit (like all of us) by reading the graphics tutorials at the Oracle Swing tutorials. This will show you the correct way to draw.
- 04-02-2011, 06:36 AM #5
Member
- Join Date
- Sep 2010
- Posts
- 62
- Rep Power
- 0
Thank you.
-
Similar Threads
-
geting value from paintComponent
By gedas in forum New To JavaReplies: 3Last Post: 03-21-2011, 07:56 PM -
Help with paintComponent!
By joeyea in forum Java 2DReplies: 6Last Post: 12-27-2010, 01:59 PM -
JPanel PaintComponent
By capiono in forum AWT / SwingReplies: 5Last Post: 10-31-2010, 03:36 AM -
Working around paintcomponent
By sahhhm in forum New To JavaReplies: 2Last Post: 05-16-2008, 02:43 AM -
paint() and paintComponent()
By goldhouse in forum Java 2DReplies: 1Last Post: 07-17-2007, 03:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks