Hint 1: 2D array of type Button, all buttons hidden except for one Hint 2: Add I
ID: 3799595 • Letter: H
Question
Hint 1: 2D array of type Button, all buttons hidden except for one
Hint 2: Add Insets and horizontal and vertical gaps
Hint 3: The button text will correspond to the two dimensional position in the button array, i.e. the button in the top left corner at row zero column zero is labeled 00. Up to you if you want to label them rowcolumn or columnrow
Hint 4: Math.random creates random numbers between 0 and 1
Hint 5: .setVisible( true ) shows a button, .setVisible( false ) hides it.
Hint 6: Be careful not to try to uncover buttons that are out of bounds
Hint 7: .getSource to get the event source object, .getText gets the text from the button, use already known methods and wrapper classes to get the numeric value
Explanation / Answer
public class Minesweeper { public static void main(String[] args) { int m = Integer.parseInt(args[0]); int n = Integer.parseInt(args[1]); double p = Double.parseDouble(args[2]); // game grid is [1..m][1..n], border is used to handle boundary cases boolean[][] bombs = new boolean[m+2][n+2]; for (int i = 1; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.