Results 1 to 3 of 3
  1. #1
    Izuba is offline Member
    Join Date
    Oct 2010
    Posts
    16
    Rep Power
    0

    Exclamation Drawing a checkerboard

    Hey guys!
    here is a program that is suppose to display a checkerboard on an applet as shown below but it is not.
    I really do not know where I am wrong. I have spinned my brain to no avail.
    kindly help me see where I am wrong.
    kind regards


    /*
    23.7 (Draw a Checkerboard Pattern) Write an applet that draws a checkerboard pattern as follows:

    * * * * * * * *
    * * * * * * * *
    * * * * * * * *
    * * * * * * * *
    * * * * * * * *
    * * * * * * * *
    * * * * * * * *
    * * * * * * * *
    */
    import java.awt.Graphics;
    import javax.swing.JApplet;


    public class Exercise23_7 extends JApplet
    {
    // method paint to paint a checker board pattern
    public void paint( Graphics g )
    {

    // calling superclass version of method paint
    super.paint( g );
    // local variables
    int location1 = 0;
    //int location2 = 50;
    int location3 = 50;
    int location4 = 60;
    // drawing a rectanglle where to display the results
    g.drawRect( 10, 17, 400, 350 );

    // drawing the checker board pattern
    for( int i = 1; i <= 4; i++ )
    {
    for( int location2 = 50; location2 <= 50; location2 +=10 )
    {
    location1 = 40;

    for( int j = 1; j <= 8; j++ )
    {
    location1 += 10 ;
    g.drawString( "*", location1, location2 );
    } // end for

    for( int j = 1; j <= 8; j++ )
    {
    location3 += 10;
    g.drawString( "*", location3, location4 );
    } // end for
    } // end for
    } // end outer for
    } // end method paint
    } // end class Exercise23_7

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Drawing a checkerboard

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Can you describe what is wrong with the program?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: Drawing a checkerboard

    I didn't understand the assignment but you second for loop seems wrong. It only run once, because you set loication2 to 50 and the check is for <=50.

    Konrad

Similar Threads

  1. Checkerboard
    By mbw290 in forum New To Java
    Replies: 4
    Last Post: 09-07-2011, 07:29 AM
  2. checkerboard help
    By armedrabbit in forum New To Java
    Replies: 1
    Last Post: 04-03-2011, 07:23 AM
  3. Simple Checkerboard
    By ShortIt in forum New To Java
    Replies: 2
    Last Post: 01-19-2011, 04:03 AM
  4. Checkerboard Program
    By Jnoobs in forum New To Java
    Replies: 9
    Last Post: 09-21-2010, 03:46 AM
  5. Replies: 3
    Last Post: 07-23-2009, 07:45 AM

Tags for this Thread

Posting Permissions

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