Results 1 to 6 of 6
  1. #1
    luke is offline Member
    Join Date
    Sep 2010
    Posts
    62
    Rep Power
    0

    Question paintComponent problem

    Hello,

    I am trying to make a separate method called draw() that draws some figures on the screen.

    When I try this

    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);
                                     .
                                     .
                                     .
    } 
    }
    I get error message immediately from Eclipse.

    Can someone, please explain me what I am doing wrong?
    Thank you.
    Last edited by luke; 04-02-2011 at 12:02 AM.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I need more information, what error message exactly?(copy and paste them)

  3. #3
    luke is offline Member
    Join Date
    Sep 2010
    Posts
    62
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    I need more information, what error message exactly?(copy and paste them)
    paintComponent gets underlined with a red line and when I position the mouse over it says:

    "void is an invalid type for the variable paintComponent" .

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  5. #5
    luke is offline Member
    Join Date
    Sep 2010
    Posts
    62
    Rep Power
    0

    Default

    Thank you.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. geting value from paintComponent
    By gedas in forum New To Java
    Replies: 3
    Last Post: 03-21-2011, 08:56 PM
  2. Help with paintComponent!
    By joeyea in forum Java 2D
    Replies: 6
    Last Post: 12-27-2010, 02:59 PM
  3. JPanel PaintComponent
    By capiono in forum AWT / Swing
    Replies: 5
    Last Post: 10-31-2010, 03:36 AM
  4. Working around paintcomponent
    By sahhhm in forum New To Java
    Replies: 2
    Last Post: 05-16-2008, 03:43 AM
  5. paint() and paintComponent()
    By goldhouse in forum Java 2D
    Replies: 1
    Last Post: 07-17-2007, 04:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •