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.


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

Results 1 to 1 of 1

Thread: Help on programming assignment

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Thanked 0 Times in 0 Posts

    Default Help on programming assignment

    I am doing an independent study at my highschool, and I am struggling to finish an assignment. I am meant to draw certain grids of concentric circles in the drawing panel. The circles, when surrounded by a diamond make the diamond appear bent. Here is the code:

    import java.awt.*;

    public class Illusion {
    public static void main(String[] args) {
    DrawingPanel panel = new DrawingPanel (500, 400);
    Graphics g = panel.getGraphics();
    drawBasic(g, 0, 0, 3, 90);
    drawBasic(g, 120, 10, 3, 90);
    drawBasic(g, 250, 50, 5, 90);
    drawGrid(g, 10, 120, 10, 100, 2);
    drawGrid(g, 350, 20, 5, 40, 3);
    drawGrid(g, 240, 160, 5, 50, 4);

    public static void drawBasic(Graphics g, int x, int y,
    int circles, int size) {
    int gap=size/(2*circles);
    g.fillOval(x, y, size, size);
    for (int i=0; i<circles; i++) {
    g.drawOval(x+(i*gap), y+(i*gap), size-(2*i*gap), size-(2*i*gap));

    Polygon diamond = new Polygon();
    diamond.addPoint(x+(size/2), y);
    diamond.addPoint(x, y+(size/2));
    diamond.addPoint(x+(size/2), y+size);
    diamond.addPoint(x+size, y+(size/2));

    public static void drawGrid(Graphics g, int x, int y, int circles, int size, int rows){
    g.fillRect(x, y, size*rows, size*rows);
    g.drawRect(x, y, size*rows, size*rows);
    for(int i=0; i<rows; i++) {
    drawBasic(g, x+(i*size), y, circles, size);




    I need these grids to complete, rather than just drawing the first row. Currently I am only 3 chapters into the books. I have learned concepts like parameters and for loops, but really don't know any concepts that are not already used somewhere in the program.

    I know this post is long, and if there are certain things I'm doing wrong let me know. Thanks,


    Edit: The assignment link is http://www.cs.washington.edu/educati...ork/3/spec.pdf
    Last edited by aaronmcohen; March 7th, 2012 at 07:52 PM.

Similar Threads

  1. Replies: 0
    Last Post: December 12th, 2011, 03:17 PM
  2. assignment troubles polymorphism (guide for assignment included)
    By tdawg422 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2011, 10:01 AM
  3. Programming help with java assignment!
    By kami21 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 15th, 2011, 06:37 PM
  4. Programming assignment using inheritance
    By Slypher in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 4th, 2011, 05:42 PM
  5. programming assignment help
    By sdgseed in forum Threads
    Replies: 1
    Last Post: October 20th, 2010, 02:43 PM