Results 1 to 4 of 4

Thread: 10x10 Grid Java

  1. #1
    efceddy is offline Member
    Join Date
    Apr 2013
    Posts
    12
    Rep Power
    0

    Default 10x10 Grid Java

    so i need to create a 10x10 grid for a snakes and ladders board, the board loads but i cant figure out how to add numbers to the squares here is mycode

    import java.awt.*;

    import javax.swing.*;
    public class Board
    {
    //Creating the array

    int[][] numbers=new int[10][10];
    public static int rows = 10;
    public static int columns = 10;
    public static Color col1 = Color.green;
    public static Color col2 = Color.YELLOW;
    public static void main(String[] args)
    {

    // creating the board
    JFrame Board = new JFrame();
    Board.setTitle("Snakes And Ladders");
    Board.setSize(500, 500);
    Container pane = Board.getContentPane();
    pane.setLayout(new GridLayout(rows, columns));


    //Colour
    Color temp;
    for (int i = 0; i < rows; i++)
    {
    if (i%2 == 0)
    {
    temp = col1;
    }
    else
    {
    temp = col2;
    }
    for (int j = 0; j < columns; j++)
    {
    JPanel panel = new JPanel();
    panel.setBackground(temp);
    if (temp.equals(col1))
    {
    temp = col2;
    }
    else
    {
    temp = col1;
    }
    pane.add(panel);
    }
    }
    // Showing the Board
    Board.setVisible(true);
    }

    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: 10x10 Grid Java

    You don't seem to remember advice you received earlier on this forum.

    http://www.java-forums.org/advanced-...tml#post329635

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: 10x10 Grid Java

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: 10x10 Grid Java

    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 1
    Last Post: 01-27-2014, 06:57 PM
  2. java set grid GUI
    By Ericyue in forum New To Java
    Replies: 1
    Last Post: 11-07-2012, 04:45 PM
  3. Open Grid Scheduler/Grid Engine
    By java software in forum Java Software
    Replies: 0
    Last Post: 03-27-2012, 07:00 PM
  4. Java visual grid. and X, Y cordinates
    By Zocheyado in forum New To Java
    Replies: 1
    Last Post: 02-11-2012, 10:04 AM
  5. Help in creating grid points using java swing
    By mhariharasudan in forum AWT / Swing
    Replies: 2
    Last Post: 02-24-2011, 06:42 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
  •