hi, i have no idea why this isn't working....I placed some system.out.println's for debugging purposes and what I found is that after entering the "new game" method, thethe message shows in the console, but then the random initialization occurs, after which I placed another system.out and its not showing which tells me the program is stuck there....but why?
here is the controller (which is called by a driver class which has the main method but I didn't include it for the forum since all it does is create an instance of the controller and thats pretty much it)
import java.util.*;
public class BoggleController
{
private int dim;
private String[][] letterArray;
private BoggleModel actions;
private BoggleGUI start;
public BoggleController()
{
dim = 4;
actions = new BoggleModel(dim); //instantiates model class
start = new BoggleGUI(dim, passArray()); //instantiates gui class
}
public String[][] passArray()
{
System.out.println("inside pass array");
return actions.newGame(dim);
}
}
this one is the gui part:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
/**
* class for gui components
* @field frame frame for display (window)
* @field newGameButton button for creating new game
* @field panel1
* @field panel2
* @field lettersPanel panel that holds grid board
* @field dim is the variable to hold the dimensions of the grid
* @field wordsLabel label that holds the words entered
* @field grid is the array of buttons for the letters to show up in
* @field points is the label that will hold the points accumulated so far
*/
public class BoggleGUI
{
private JFrame frame;
private JButton newGameButton;
private JPanel panel1, panel2, lettersPanel;
private JLabel wordsLabel, points;
private int dim;
private JButton[][] grid;
private String[][] letters;
/**
* Constructor with no parameters
*/
public BoggleGUI()
{
}
/**
* Constructor with parameters indicating the width/height of grid(square)
* of boggle board
* @param d dimension of the grid
*/
public BoggleGUI(int d, String[][] la)
{
dim = d; //dimension of grid
letters = la; //passes reference of array of letters
panel1 = new JPanel();
panel2 = new JPanel();
lettersPanel = new JPanel(new GridLayout(d,d)); //panel to hold letters
newGameButton = new JButton("New Game");
grid = new JButton[d][d]; //array of buttons for letters
wordsLabel = new JLabel(); //label holds words entered successfully
points = new JLabel();
frame = new JFrame("Boggle");
setWindow(); //calls method to set up window components
}
/**
* sets window components
*/
public void setWindow()
{
panel1.add(wordsLabel);
panel2.add(points);
setButtonArray();
frame.setLayout(new BorderLayout());
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel1, BorderLayout.WEST);
frame.add(lettersPanel, BorderLayout.CENTER);
frame.add(newGameButton, BorderLayout.SOUTH);
frame.add(points, BorderLayout.EAST);
frame.setVisible(true);
//frame.pack();
}
/**
* sets up the button array and adds to panel
*/
public void setButtonArray()
{
for(int r=0; r>dim; r++)
{
for(int c=0; c>dim; c++)
{System.out.println("inside both loops");
grid[r][c].setText(letters[r][c]);
System.out.println("after setting text in buttons");
lettersPanel.add(grid[r][c]);
System.out.println("added letter buttons to panel");
}
}
}
}
and this is the model version
import java.util.*;
/**
* Class created for functioning of the Boggle game
* @field letter character of letter
* @field unicodeChar integer that will represent character
*/
public class BoggleModel
{
private int dim;
int unicodeChar;
private char letter;
private String[][] letterArray;
/**
* Constructor
*/
public BoggleModel(int d)
{
//possible stuff in here
//testing...
dim = d;
System.out.println("inside constructor for boggle model");
}
/**
* sets up newGame
*/
public String[][] newGame(int d)
{
System.out.println("inside new game");
//set up new array of letters
Random randomInt = new Random();
System.out.println("after initializing random variable");
for(int r=0; r>d; r++)
{
for(int c=0; c>d; c++)
{ //this code places the random char into letter array
System.out.println("inside for loops in new game");
unicodeChar = randomInt.nextInt(26) + 65;
letter = (char)unicodeChar; //cast int as character
letterArray[r][c] = Character.toString(letter); //cast into string
}
}System.out.println("about to return letter array");
return letterArray;
}
}
any suggestions?