Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Drawing a pentagon

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Drawing a pentagon

    Hello!

    I am in my final year of High School so my knowledge about Java is fairly limited. I do not need the following for a school project, I am busy developing a program that will make use of a pentagon.
    I already have the coordinates (x ; y) of the pentagon, I just need an example of how to plot the coordinates and draw the pentagon in Java.

    Thank you for your help.

    Regards
    Zomosa


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Drawing a pentagon

    Check out the Polygon class and the Graphics class. The API is your best friend: Java Platform SE 6
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Drawing a pentagon

    I was afraid someone was going to link me to Java Documents. We never did the Graphics class nor any basic shape drawing due to our limited syllabus, nonetheless I will try...

    Polygon(int[] xpoints, int[] ypoints, int npoints) - Can the xpoints and ypoints be declared as Double?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Drawing a pentagon

    Quote Originally Posted by Zomosa View Post
    I was afraid someone was going to link me to Java Documents. We never did the Graphics class nor any basic shape drawing due to our limited syllabus, nonetheless I will try...
    You've never worked with the Graphics class at all? How have you done your drawing previously?

    Quote Originally Posted by Zomosa View Post
    Polygon(int[] xpoints, int[] ypoints, int npoints) - Can the xpoints and ypoints be declared as Double?
    What happened when you tried?

    Note that using the Polygon class is just one way to do it. You could just use drawLine() instead, if you wanted to stick with something a bit easier to understand.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Drawing a pentagon

    Yes, we have not. Basically we did input from user, Graphical User Interface, arrays, matrices, write and read to and from a file, loops and array of objects.
    I googled and got some notes on StdDraw.java. They do not say what to import though, do you perhaps know? I should be able to figure it out from there, there is a few examples.

    It looks like this : StdDraw.line(0.0, 0.0, 1.0, 0.0);

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Drawing a pentagon

    I don't know what StdDraw is. I'd recommend you read through this instead: Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Drawing a pentagon

    Thank you. I will work through that.

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Drawing a pentagon

    Quote Originally Posted by Zomosa View Post
    Thank you. I will work through that.
    No problem. Let us know how it goes.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Drawing images with different angles
    By gargamel7 in forum AWT / Java Swing
    Replies: 24
    Last Post: September 13th, 2011, 06:04 AM
  2. help with JFrame, drawing, and JButtons
    By Khoatic in forum AWT / Java Swing
    Replies: 1
    Last Post: November 19th, 2010, 12:34 AM
  3. Line Drawing Program
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 13th, 2010, 03:54 PM
  4. [SOLVED] Drawing on JFrame
    By kbarrett1989 in forum AWT / Java Swing
    Replies: 3
    Last Post: October 31st, 2010, 03:41 AM
  5. Drawing
    By toxikbuni in forum Java Theory & Questions
    Replies: 0
    Last Post: April 20th, 2010, 02:43 PM