import java.awt.Container; import java.awt.Font; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.Color; /** * BingoHopperTester is to help you test the * functionality of your BingoHopper class * and your BingoBall class * @author Chris Thiel, ofmcap * @version May 1, 2021 * */ public class BingoHopperTester extends JPanel implements MouseListener { private BingoHopper hopper; private String message, message2; private Font font1, font2; public static final int SIZE = 25; public static final int WIDTH = 700; public static final int HEIGHT = 500; public static final int GAP =3; public BingoHopperTester() { font1 = new Font("Impact", Font.BOLD, 18); font2 = new Font("Sans-Serif", Font.BOLD,54); hopper = new BingoHopper(); message = "Click to get next Bingo Ball"; message2 = "Current Ball is " + hopper.currentBall(); addMouseListener(this); } // MouseListener implementation public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) { hopper.nextBall(); message2 = "Current Ball is " + hopper.currentBall() +", " ; message2 += hopper.called()+ " have been called, and " + hopper.remaining()+" balls remain."; repaint(); } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} // Make the application end if window is closed public static void main(String[] args) { JFrame window = new JFrame(); window.setSize(WIDTH, HEIGHT); Container c = window.getContentPane(); c.add(new BingoHopperTester()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); } public void paintComponent(Graphics g) { setBackground(new Color(224,224,225) ); super.paintComponent(g); // Adjust location of boxes according to the current panel size g.setColor(Color.BLACK); g.setFont(font1); g.drawString(message, 20, 20); g.drawString(message2, 20, 50); // called ball display int left = 135; int top=105; g.drawString("B",left-SIZE+GAP, top+SIZE+GAP-8); g.drawString("I",left-SIZE+GAP, top+2*(SIZE+GAP)-8); g.drawString("N",left-SIZE+GAP, top+3*(SIZE+GAP)-8); g.drawString("G",left-SIZE+GAP, top+4*(SIZE+GAP)-8); g.drawString("O",left-SIZE+GAP, top+5*(SIZE+GAP)-8); for(int i=0; i<75; i++) { int x = left + (SIZE+GAP)*(i%15); int y = top+(SIZE+GAP)*(i/15); g.setColor(Color.WHITE); if (hopper.wasCalled(i+1)) g.setColor(Color.RED); if (hopper.getCurrentBall().getNumber()-1 == i ) g.setColor(Color.BLUE); g.fillOval(x, y, SIZE, SIZE); } // current ball display g.setColor(Color.WHITE); g.fillOval(500, 300, 150, 150); g.setColor(Color.BLUE); g.setFont(font2); g.drawString(hopper.getCurrentBall().getLetter(),555, 360); g.drawString(""+hopper.getCurrentBall().getNumber(),545, 410); } }