changed I/O to JOptionPane
This commit is contained in:
116
testJOptionPane2.java
Normal file
116
testJOptionPane2.java
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* @(#)testJOptionPane.java
|
||||
*
|
||||
* @author Horton
|
||||
* @version 1.00 2012/5/15
|
||||
*/
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class testJOptionPane2 {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// ## creates a loop to display the main menu
|
||||
boolean done = false;
|
||||
|
||||
while (!done) {
|
||||
String menu =
|
||||
"1 - load file"
|
||||
+ "\n"
|
||||
+ "2 - add something "
|
||||
+ "\n"
|
||||
+ "3 - save file "
|
||||
+ "\n"
|
||||
+ "4- quit";
|
||||
String inputValue = JOptionPane.showInputDialog(menu);
|
||||
int n = Integer.parseInt(inputValue);
|
||||
switch (n) {
|
||||
case 1:
|
||||
loadFile(); // Read data from file
|
||||
break;
|
||||
case 2:
|
||||
doSomething();
|
||||
break;
|
||||
case 3:
|
||||
JOptionPane.showMessageDialog(null, "user instructions here ");
|
||||
break;
|
||||
case 4:
|
||||
done = true;
|
||||
break;
|
||||
default:
|
||||
JOptionPane.showMessageDialog(null, "invalid option, please try again ");
|
||||
}
|
||||
}
|
||||
|
||||
// JOptionPane.showMessageDialog(null,"You Chose " + inputValue);
|
||||
|
||||
// *********************************************************************
|
||||
// Custom button text -- returns 0 for the first button
|
||||
Object[] options = {"Yes, please", "No, thanks", "No eggs, no ham!"};
|
||||
int n =
|
||||
JOptionPane.showOptionDialog(
|
||||
null,
|
||||
"Would you like some green eggs to go " + "with that ham?",
|
||||
"A Silly Question",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[2]);
|
||||
// ## do not include the following line. It is to help determine what the switch should do
|
||||
JOptionPane.showMessageDialog(null, "You Chose " + n);
|
||||
|
||||
// ****************************************************************
|
||||
// pull down menu
|
||||
// --NOTE: this would be a good place to call a method in your list class to get an array of
|
||||
// objects to display such as all the names of the teams or products in your list.
|
||||
|
||||
Object[] possibilities = {"ham", "spam", "yam"};
|
||||
String s =
|
||||
(String)
|
||||
JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Complete the sentence:\n" + "\"Green eggs and...\"",
|
||||
"Customized Dialog",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null, // icon if you have one
|
||||
possibilities,
|
||||
"ham");
|
||||
}
|
||||
|
||||
public static void doSomething() {
|
||||
// ## this method is just to show displaying
|
||||
// ## a different menu. You would need to
|
||||
// ## add a switch to handle menu options
|
||||
// ## when option 4 is selected,the loop/method will end
|
||||
// ## and processing can return to the menu that called this
|
||||
|
||||
boolean editMore = true;
|
||||
while (editMore) {
|
||||
String menu =
|
||||
"1 - show all data"
|
||||
+ "\n"
|
||||
+ "2 - show only one thing "
|
||||
+ "\n"
|
||||
+ "3 - save file "
|
||||
+ "\n"
|
||||
+ "4 - done editing ";
|
||||
String inputValue = JOptionPane.showInputDialog(menu);
|
||||
// out write a switch to evaluate the options -- following if would be in your switch
|
||||
if (inputValue.equals("4")) editMore = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadFile() {
|
||||
// loop, read data for one record, construct object of that class, add to the appropriate list
|
||||
/**
|
||||
* Scanner saved; try { saved = new Scanner (new File("itemList.dat")); while(saved.hasNext()) {
|
||||
* itemName = saved.nextLine(); itemPrice = saved.nextDouble(); itemQuantity = saved.nextInt();
|
||||
* saved.nextLine(); //cleans out end of line myCart.addItem(new ItemKEY(itemName, itemPrice,
|
||||
* itemQuantity)); } //end of while block to read } // end of try block catch (IOException e) {
|
||||
* System.out.println ("input read failed " + e); }
|
||||
*/
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user