Wednesday, March 4, 2015

Basic Battleship v1.1

I edited the code of my basic Battleship program to include option panels as opposed to writing directly in the console. The main things that were added were:

import javax.swing.JOptionPane; //Function used to create panel

/*
 * Pretend the rest of the code is here, nothing was changed
 */

String guess = JOptionPane.showInputDialog("Enter your guess here (0-7): ");  
//Creates a window where the user can input their guess

/*
 * Rest of the code goes here
 */

The remaining code from v1.0 was unchanged and worked smoothly. I want to add a window to display whether or not the user's guess is a hit or a miss, but that goes more into JFrames and JPanels and UI that I'm assuming gets covered more in Chapter 6. I just wanted to make sure I understood JOptionPane for this activity.

No comments:

Post a Comment