FileDocCategorySizeDatePackage
LightBoardPane.javaAPI DocExample3157Tue Dec 12 18:58:44 GMT 2000bingo.shared

LightBoardPane

public class LightBoardPane extends JPanel
This class displays the most recently called ball in a panel on the left, and all of the balls called in a lighted display on the right. This class isn't thread-safe, so be sure to call its methods from the AWT thread.

Fields Summary
JLabel[]
allBalls
JLabel[]
rowTitles
JPanel
allBallsPane
JPanel
newBallPane
JLabel
newBallLabel
Color
litColor
Constructors Summary
public LightBoardPane(int ignored)


       
	super(false); //XXX Maybe should double buffer?

	setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
	Font rowTitleFont = new Font("serif", Font.BOLD, 14);
	Font ballFont = new Font("serif", Font.PLAIN, 12);
	Font bigFont = new Font("serif", Font.BOLD, 36);

	GridLayout g;

	allBallsPane = new JPanel(false);
	g = new GridLayout(Card.SIZE, BingoBall.RANGE + 1);
	g.setHgap(5);
	g.setVgap(5);
	allBallsPane.setBorder(BorderFactory.createLoweredBevelBorder());
	allBallsPane.setLayout(g);
	allBallsPane.setBackground(Color.darkGray);

	for (int i = 0; i < Card.SIZE; i++) {
	    for (int j = 0; j < BingoBall.RANGE; j++) {
		if (j == 0) {
	            rowTitles[i] = new JLabel(new Character(Card.columnTitles[i]).toString(), JLabel.CENTER);
	            rowTitles[i].setFont(rowTitleFont);
	    	    rowTitles[i].setForeground(litColor);
		    allBallsPane.add(rowTitles[i]);
		}
	        allBalls[i][j] = new JLabel(new Integer((j+1)+(i*BingoBall.RANGE)).toString(), JLabel.CENTER);
	        allBalls[i][j].setFont(ballFont);
	        allBallsPane.add(allBalls[i][j]);
	    }
	}

	newBallPane = new JPanel(false);
	newBallPane.setLayout(new GridLayout(1, 1));
	newBallLabel = new JLabel("Waiting...", JLabel.CENTER);
	newBallLabel.setFont(bigFont);
	newBallPane.setBorder(BorderFactory.createLoweredBevelBorder());
	newBallPane.add(newBallLabel);
	newBallPane.setMinimumSize(newBallPane.getPreferredSize());
	newBallPane.setPreferredSize(newBallPane.getPreferredSize());

	add(newBallPane);
	add(allBallsPane);
    
Methods Summary
public voidclear()

	for (int i = 0; i < Card.SIZE; i++) {
	    for (int j = 0; j < BingoBall.RANGE; j++) {
	        allBalls[i][j].setForeground(Color.black);
	    }
	}
	newBallLabel.setText("Waiting...");
	allBallsPane.repaint(); // XXXX should not be necessary
    
public voiddisplayNewBall(BingoBall b)

	// light up the number in red
	int i = (b.number-1)/BingoBall.RANGE;
	int j = (b.number-1)%BingoBall.RANGE;
	allBalls[i][j].setForeground(litColor); 

	// change the new ball display
	if (b.number == BingoBall.GAME_OVER) {
	    newBallLabel.setText("Game Over");
	} else {
	    newBallLabel.setText(b.toString());
	}
	allBallsPane.repaint(); // XXXX should not be necessary
    
public java.awt.DimensiongetMaximumSize()

	Dimension d = getPreferredSize();
	d.width = Short.MAX_VALUE;
	return d;