Results 1 to 4 of 4
  1. #1
    ddatta8 is offline Member
    Join Date
    Dec 2008
    Posts
    27
    Rep Power
    0

    Default Use GeneralPath class to draw octagon

    I want to use GeneralPath class to construct a shape of a regular octagon. Please help.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by ddatta8 View Post
    I want to use GeneralPath class to construct a shape of a regular octagon. Please help.
    Why don't you use the much simpler Path2D class; you can add your eight points to it and be done with it.

    kind regards,

    Jos

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

  4. #4
    ddatta8 is offline Member
    Join Date
    Dec 2008
    Posts
    27
    Rep Power
    0

    Default

    I was using this code but it is not working. Can you tell me what is wrong with it?

    Java Code:
    public void paintComponent(Graphics g){
            float x,y;
    		super.paintComponent(g);
    		Graphics2D g2 = (Graphics2D)g;
    		GeneralPath path = new GeneralPath();
            path.moveTo(200,200);
            for (int i = 1; i < 8; i++){
                double a = i*0.25*Math.PI;
                path.lineTo((float)Math.cos(a), (float)Math.sin(a));
                x = (float)Math.cos(a);
                y = (float)Math.sin(a);
                g2.draw(path);
                //printf("x %d,y %d: %f, %f\n", i,i,x,y);
            }
            path.closePath();
    		g2.draw(path);

Similar Threads

  1. how to draw an arc
    By Baker in forum New To Java
    Replies: 1
    Last Post: 04-16-2009, 10:05 PM
  2. How to create a GeneralPath
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 11:38 AM
  3. GeneralPath demo
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 11:37 AM
  4. How to obtain a filled and stroked GeneralPath
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 11:37 AM
  5. How to use GeneralPath class
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 11:37 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
  •