M
mrthis
I am writing a minesweeper game for a class and have just gotten
started. I cannot figure out why this program gives me a blank screen.
I think it has something to do with how I have set up my array. Any
guidance gratefully accepted. /ml
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* <p>Title: Minesweeper </p>
* <p>Minesweeper game </p>
* <p>author Matthew Lasar</p>
* @version 1.0
*/
public class Minesweeper extends JFrame {
JToggleButton cell[][];
public Minesweeper() {
Container cp = getContentPane();
cp.setLayout(new GridLayout(16, 16));
try {
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
cell[x][y] = new JToggleButton();
cell[x][y].setText("yes!");
cp.add(cell[x][y]);
}
}
pack();
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) {
Minesweeper sweeper = new Minesweeper();
sweeper.setVisible(true);
}
}
started. I cannot figure out why this program gives me a blank screen.
I think it has something to do with how I have set up my array. Any
guidance gratefully accepted. /ml
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* <p>Title: Minesweeper </p>
* <p>Minesweeper game </p>
* <p>author Matthew Lasar</p>
* @version 1.0
*/
public class Minesweeper extends JFrame {
JToggleButton cell[][];
public Minesweeper() {
Container cp = getContentPane();
cp.setLayout(new GridLayout(16, 16));
try {
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
cell[x][y] = new JToggleButton();
cell[x][y].setText("yes!");
cp.add(cell[x][y]);
}
}
pack();
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) {
Minesweeper sweeper = new Minesweeper();
sweeper.setVisible(true);
}
}