Results 1 to 8 of 8
  1. #1
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default Paint problem =P

    Im a newbeginner on painting in java ... Im trying to paint a circle in a JPanel.
    I made a class for the painting:
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    
    
    public class Graphic extends JPanel {
      
    
       public void paintComponent(Graphics g) {
          super.paintComponent(g);
    
          g.setColor(Color.BLACK);
          g.fillOval(400, 400, 50, 50);
          
    
        }
       }
    and in my GUI constructor i made a object and added it to my panel.

    Java Code:
     Graphic g = new Graphic();
     cordinatepanel.add(g);
    so why is it not painting anyting??? Thanks

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

    Default

    Do you know if your Graphic panel is big enough to show the drawing, that it is larger than 400 by 400? After adding your Graphic JPanel and rendering your GUI (calling pack() or setVisible(true) on the top-level container), you may wish to call System.out.println(g.getSize()) to see how big the panel is.

  3. #3
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    the panel is y: 640 x :1200 =/

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

    Default

    Quote Originally Posted by santa View Post
    the panel is y: 640 x :1200 =/
    That's its position. We need to know its dimensions. Its height and width.

    Note that if this doesn't solve the problem, then you're going to have to post more code.

  5. #5
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    no not position ... cordinatepanel.setSize(1200, 640);

  6. #6
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    My problem is ... i wrote this GPS application ... and now i want to draw my pos on a image witch is an imageicon ... just want to paint a circle at the cordinate where the GPS pos is ...

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

    Default

    Quote Originally Posted by santa View Post
    My problem is ... i wrote this GPS application ... and now i want to draw my pos on a image witch is an imageicon ... just want to paint a circle at the cordinate where the GPS pos is ...

    I'll state again what I've stated before:
    Quote Originally Posted by fubarable
    Note that if this doesn't solve the problem, then you're going to have to post more code.

  8. #8
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    Yes .. I know you said that =/ but I dont whanna get fail on the task because of the teachers search bot finding a match on Java forum =/ can i mail it to you or someting ... would be awsome =)

Similar Threads

  1. About super.paint()
    By jordan2816 in forum Java Applets
    Replies: 1
    Last Post: 01-24-2011, 12:14 PM
  2. Java Paint Program problem (JPanel)
    By KilKidd in forum Advanced Java
    Replies: 6
    Last Post: 11-20-2010, 05:31 AM
  3. paint and repaint problem
    By koddy in forum NetBeans
    Replies: 2
    Last Post: 05-21-2010, 07:43 AM
  4. how to add more than one paint method
    By gautham in forum Java 2D
    Replies: 2
    Last Post: 04-06-2010, 08:07 AM
  5. Some confusions with paint()
    By kendaop in forum Java Applets
    Replies: 1
    Last Post: 01-24-2009, 01:23 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
  •