import javax.swing.JOptionPane;
/* other options for creatine JOptionPane dialogs
JOptionPane.showMessageDialog(frame, "text here", "title here", JOptionPane.ERROR_MESSAGE); //custom title, error icon
JOptionPane.showMessageDialog(frame, "text here", "title here", JOptionPane.INFORMATION_MESSAGE,icon); //custom title & icon
Object[] options = {"Yes!", "No, thanks", "Not Sure"};
int n = JOptionPane.showOptionDialog(frame, "question here ", "custom title",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html#api
*/
public class LocalApplication
{
public static void displayCredit()
{
double tempBalance = Credit.getCreditBalance();
JOptionPane.showMessageDialog( null, "Credit Balance = " + tempBalance );
}
public static int validateMenuChoice(String response)
{
int choice = 0;
if( response != null && !response.isEmpty() )
{
try{
choice = Integer.parseInt( response );
return choice;
}catch( NumberFormatException e)
{ return 0;
}
}
return 0;
} // end validateMenuChoice
public static void main(String[] args)
{
String response;
int choice = 0;
response = JOptionPane.showInputDialog( "Do you want to modify Credits? (yes)");
if( response != null && response.equals( "yes" ) )
{
while( choice != 4 )
{
response = null;
response = JOptionPane.showInputDialog( "1 = Increase Credit , 2 = Decrease Credit, 3 = Show Current Credit, 4 = Quit");
choice = validateMenuChoice( response );
switch( choice )
{
case 1:
Credit.increaseCredit( 1 );
break;
case 2:
Credit.decreaseCredit( 1 );
break;
case 3:
displayCredit();
break;
case 4:
// cleanup before quitting?
break;
default:
JOptionPane.showMessageDialog( null, "Please enter one of the digits from the menu" );
break;
} //end switch
} //end while
}
JOptionPane.showMessageDialog( null, "Thank you!" );
} //end main
} //end class