Battleship - Java Pt. 6

Chris Chen
/*
* Purpose: To easily get input from a jOptionPane call
*/

import javax.swing.*;

public class PopUpReader {

//method that returns the integer representation of input from a jOptionPain call
public static int readInt(String message){

return(Integer.parseInt(readString(message)));

}

//method that returns the double representation of input from a jOptionPain call
public static double readDouble(String message){

return(Double.parseDouble(readString(message)));

}

//method that returns the char representation of input from a jOptionPain call
public static char readChar(String message){

return(readString(message).charAt(0));

}

//helper method that returns the String input from a jOptionPain call
public static String readString(String message){

return(JOptionPane.showInputDialog(null, message));

}

}

Published by Chris Chen

Chris is currently attending the University of California, Berkeley seeking an undergraduate's degree in Electrical Engineering Computer Science. He enjoys playing basketball, practicing kendo, hanging out w...  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.