Java Coding Help

Discussion in 'OT Technology' started by LooneyTuned, Feb 29, 2004.

  1. LooneyTuned

    LooneyTuned Oil? Bitch you cookin OT Supporter

    Nov 15, 2003
    Likes Received:
    Edmonton, Alberta

    Alright well im trying to do some javaing and im goin crazy trying to create this game. well this is the first of three parts its just drawing a board. the numbers must be buttons, (later on i have to make them move and shit and they need to have actionListener functions so they have to be buttons).

    1 2 3
    4 5 6
    7 8 9

    is what the board looks like where the top row is defaulted at red (1,2,3) middle is defaulted at yellow and bottom is defaulted at blue. the middle square is defualted at white.
    Where row 1,2,3 are panels and all of the numbers together is another main panel. The Board should arrange the squares (i.e. the 9 Buttons) into 3 rows. Each row is a Panel into which the 3 buttons are added. The rows should then be assembled into another Panel. this Final board has to be centered (i believe GridLayout).

    Ive started as much as i can in the board.class which is how i can test this out, Im using COdewarrior version 6. its pissing me off i cant get this. im not sure what to do for certain methods. However i broke into different methods to make it look cleaner for style. Also so if i have a mistake i know where to look. My brother helped me out alittle but he forgot alotta of the stuff. he organized some things around.....but im not sure if what he did was correct. he just set up the methods i did all the inside code(as much as i could do)

    import java.awt.*;

    public class Board {

    // Constants
    private static final Color emptySquareColor = Color.white;
    private static final int defaultEmpty = 5;
    private static final int boardSize = 3;

    // instance variables
    private Panel row1, row2, row3, boardPanel;
    private Button square1, square2, square3, square4, square5;
    private Button square6, square7, square8, square9;
    private Color topRowColor, middleRowColor, bottomRowColor;
    private int emptySquare;

    // Constructor
    public Board(Color top, Color middle, Color bottom) {

    **i understand that this the constructor of my row colors, but am i supposed to go topRowColor =;?? then what about the argument? whats that do...***

    = Color.yellow;


    // Instance methods
    private Panel makeRowPanel( ) {
    // Create a Panel. Set the LayoutManager to FlowLayout (centered). Return a reference to the Panel.

    **I have to make four row/and a board panel which includes these should there be 4 new Panel objects created??***

    Panel aPanel;
    aPanel = new Panel();

    return aPanel;


    private Button makeSquare(String squareNumber) {
    // Create and return a button with the given String as its Label
    Button square1;
    square1 = new Button("1");
    Button square2;
    square2 = new Button("2");
    Button square3;
    square3 = new Button("3");
    Button square4;
    square4 = new Button("4");
    Button square5;
    square5 = new Button("5");
    Button square6;
    square6 = new Button("6");
    Button square7;
    square7 = new Button("7");
    Button square8;
    square8 = new Button("8");
    Button square9;
    square9 = new Button("9");


    **I believe this part is right but now i have to make the certain buttons go into there corresponding panels**

    public void paintSquares( ) {
    // Set the colours of the squares according to their row colours and set variable emptySquare to default

    **not sure how to approach**


    private void fillRows( ) {
    // Create the squares and their labels, add them to the appropriate rows 1, 2 or 3

    **not sure how to approach**

    private void assembleRows( ) {
    // Arranges the rows into a single Panel (using GridLayout)
    Panel mainPanel;
    mainPanel = newPanel;
    newPanel setLayout(new GridLayout(6,6));
    mainPanel add(this.row1);
    mainPanel add(this.row2);
    mainPanel add(this.row3);
    boardPanel = new Panel(mainPanel);

    **I kinda skipped ahead and organized it into how i would like the assembled rows to look like...its the inner steps that is totally blowing me off*

    public Panel getBoard( ){
    // Return a reference to the Panel into which all 3 rows have been assembled.

    return this.BoardPanel;
    *not totally sure if this is return message is correct to be placed here*

    } // end of Board class

    thats my Board class where that board is supposed to be created.. i want it to work when i test it

    * Description: Test code for drawing the board.

    import java.awt.*;
    import java.applet.*;

    public class BoardTest extends Applet {

    public void init() {


    private void part1BoardTest() {

    Board board;
    board = new Board(, Color.yellow,;
    Panel myBoardPanel = new Panel(new FlowLayout());

    this is my BoardTest which tests if my Board will show up the way i want. i know thats right its my Board Class thats fuckin me up. my html file is okay as well.

    Thanks for all the java coders who can help me figure this out..hate java...need to learn...must make $$ in summer gotta do what yah gotta do.

    Anyone know any good java books also? i got a decent one, but im not sure if there is anything better.(its in a box right now ill get the title later).

  2. LooneyTuned

    LooneyTuned Oil? Bitch you cookin OT Supporter

    Nov 15, 2003
    Likes Received:
    Edmonton, Alberta
    can anyone help me with this problem..?
  3. aphoric

    aphoric Even if god did exist, it would be necessary to ab

    Aug 29, 2003
    Likes Received:
    Leaving Afghanistan
    Break it down into smaller problems, someone might help, I don't have the time to look at all that code, so you gotta ask stuff like: "How do I make it so I can drag a button from one location to another?" or something like that...

Share This Page