import java.util.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; @SuppressWarnings("serial") public class BingoBoardTester extends JPanel implements MouseListener, MouseMotionListener { private BingoBoard board; private String message, message2; public static final int SIZE = 75; public static final int WIDTH = 500; public static final int HEIGHT = 500; public static final int GAP =3; private Font font; public void resetBoard() { board = new BingoBoard(0, 0, 490); message = "Click of the board to reset"; repaint(); } public BingoBoardTester() // constructor { message = "Click of the board to reset"; font = new Font("Times", Font.BOLD, 18); resetBoard(); addMouseListener(this); addMouseMotionListener(this); } public void paintComponent(Graphics g) { setBackground(new Color(224,124,125) ); super.paintComponent(g); board.draw(g); g.setColor(Color.WHITE); g.setFont(font); g.drawString(message, SIZE, SIZE/2); } public static void main(String[] args) { JFrame window = new JFrame(); window.setSize(WIDTH, HEIGHT); Container c = window.getContentPane(); c.add(new BingoBoardTester()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); } public void mouseReleased(MouseEvent e) { int x = e.getX(); int y = e.getY(); if ( board.cellClick(x, y) ) { message=""; if (board.hasBingoSelected()) message = "BINGO DETECTED"; if (board.hasCornersSelected()) message += " (4 Corners)"; if (board.hasBlackoutSelected()) message += " (Blackout)"; repaint(); return; } // If user didn't click on a BoardCell, we reset the board resetBoard(); repaint(); } public void mousePressed(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } public void mouseDragged(MouseEvent e) {} public void mouseMoved(MouseEvent e) { // hilight a tile if mouse is hovering int x=e.getX(); int y=e.getY(); board.cellHover(x, y); repaint(); } }