import java.util.Random; // Java core packages import java.awt.*; import java.awt.event.*; // Java extension packages import javax.swing.*; /* Pete Dobbins Section: xxxx Group: 0 Partner: None */ class P3 { public static void main(String[] args) { int row = 10; int col = 10; int numMines = 10; int buttonSize = 20; int fixSizeX = 10; int fixSizeY = 60; if ( args.length >= 3 ) { try { row = Integer.valueOf( args[0] ); col = Integer.valueOf( args[1] ); numMines = Integer.valueOf( args[2] ); } catch (NumberFormatException e) { row = col = numMines = 10; } } // Create minesweeper game Minesweeper minesweeper = new Minesweeper( row, col, numMines ); // width then height minesweeper.setSize(col*buttonSize + fixSizeX, row*buttonSize + fixSizeY); //minesweeper.pack(); minesweeper.setVisible( true ); minesweeper.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } class Minesweeper extends JFrame { // Game properties private int p_iNumMines; private int p_iMineLeft; private JButton [][] p_board; // def ctor public Minesweeper() { this( 10, 10, 15 ); } // non-def ctor public Minesweeper(int row, int col, int numMines) { p_board = new JButton[row][col]; p_iNumMines = numMines; setGUIs(); } // private void setGUIs() { // set container Container container = getContentPane(); container.setLayout( new BorderLayout() ); // infobar container.add( createInfoBar(), BorderLayout.NORTH ); // board container.add( createBoard(), BorderLayout.CENTER ); // Set up menu createMenu(); } // Create board in a JPanel private JPanel createBoard() { // create panel for the board JPanel boardPanel = new JPanel( new GridLayout(p_board.length, p_board[0].length) ); // create board for ( int r = 0; r < p_board.length; ++r ) { // row for ( int c = 0; c < p_board[0].length; ++c ) { // column p_board[r][c] = new JButton(); //p_board[r][c].setSize(new Dimension(20,20)); boardPanel.add( p_board[r][c] ); } } return boardPanel; } // Create info bar in a JPanel private JPanel createInfoBar() { JButton btnNumMines = new JButton("" + 10); JButton btnNewGame = new JButton("new"); JButton btnTime = new JButton("time"); btnNumMines.setEnabled( false ); btnTime.setEnabled( false ); JPanel infoBar = new JPanel( new FlowLayout() ); infoBar.add( btnNumMines ); infoBar.add( btnNewGame ); infoBar.add( btnTime ); return infoBar; } // Menu private void createMenu() { // Items of game menu JMenuItem newItem = new JMenuItem( "New" ); newItem.setMnemonic( 'N' ); JMenuItem aboutItem = new JMenuItem( "About..." ); aboutItem.setMnemonic( 'A' ); JMenuItem exitItem = new JMenuItem( "Exit" ); exitItem.setMnemonic( 'x' ); // Game menu JMenu gameMenu = new JMenu( "Game" ); gameMenu.setMnemonic( 'G' ); gameMenu.add( newItem ); gameMenu.addSeparator(); gameMenu.add( aboutItem ); gameMenu.addSeparator(); gameMenu.add( exitItem ); JMenuBar bar = new JMenuBar(); setJMenuBar( bar ); bar.add( gameMenu ); } }