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 4 of 4

Thread: Checkers game code

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Checkers game code

    Hello, any help would be great. I am trying to right the code for a checkers game. I have the board built, but I don't even know how to start to put checkers on it. Can anyone give me a good shove in the right direction? I am new to Java and, well, I am new to Java.

    Here is my board code:

    <code>

    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import javax.swing.*;


    public class CheckerBoard

    {


    public static void main (String args[])
    {
    int row = 8;
    int col = 8;


    JFrame checkerBoard = new JFrame();
    checkerBoard.setSize(400,400);
    checkerBoard.setTitle("CheckerBoard");
    checkerBoard.setDefaultCloseOperation(JFrame.EXIT_ ON_CLOSE);


    Container pane = checkerBoard.getContentPane();
    pane.setLayout(new GridLayout(row,col));

    Color checker;

    for (int x = 1; x <=(row*col); x++)
    {
    int altr = 0;
    altr = (x-1) % col;
    altr += (x-1) / col;

    if (altr % 2 == 0)
    {
    checker = Color.black;
    }

    else
    {
    checker = Color.red;
    }

    JPanel panel = new JPanel();
    panel.setPreferredSize(new Dimension(400/row, 400/col));
    panel.setBackground(checker);
    pane.add(panel);
    }
    checkerBoard.setVisible(true);
    }
    }
    </code>


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Checkers game code

    how to start to put checkers on it
    Can you explain how the program is to work?
    What does it display?

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Checkers game code

    All i need to do is display a checkerboard with a few red and black checkers that will displayed in various locations, but I am unsure as to how to start calling the checkers and their locations. I know I need to impliment a grid to call the checkers location but I don't know how to begin. Can you help point me in the right direction?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Checkers game code

    display a checkerboard with a few red and black checkers
    That sounds like a GUI display.
    Have you read the tutorial on how to draw? That will necessary for you to do to understand.
    Sorry I don't have a link to the specific pages for drawing. Maybe google could help.
    Here's the link to the tutorial: The Java™ Tutorials

    Basically create a JPanel and override its paintComponent method and add your drawing code.

Similar Threads

  1. Simple Checkers Game in J2ME
    By chris2307 in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: February 26th, 2011, 07:40 AM
  2. Can anyone please help me with this java code for minesweeper game!
    By Mahela in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 25th, 2011, 08:10 AM
  3. Small Database Company Looking for Beta Checkers
    By dzrihen in forum JDBC & Databases
    Replies: 1
    Last Post: January 19th, 2011, 09:24 AM
  4. Help With Java Game Code
    By CheekySpoon in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 26th, 2010, 04:07 PM
  5. Robo Code - The funny Java Programming Game
    By Freaky Chris in forum The Cafe
    Replies: 20
    Last Post: October 8th, 2009, 03:42 PM