Professional Documents
Culture Documents
import
import
import
import
javax.swing.JOptionPane;
java.util.Scanner;
java.io.PrintWriter;
java.io.FileNotFoundException;
java.io.File;
/**
* A console menu for the IRS
*
* @author William McDaniel Albritton
*/
public class Menu {
// data fields
private BinarySearchTree<Person> tree =
new BinarySearchTree<Person>();
private String database =
new String("presidents.csv");
/** No-parameter constructor */
public Menu() {
// We don't need any code in constructor,
// as we already initialized the data fields.
}
/**
* Starts the menu.
*
* @param args
*
is not used
*/
public static void main(String[] args) {
// Instantiate menu & display menu
Menu menu = new Menu();
menu.displayMenu();
}
/** Displays a menu, asks for choice, executes choice */
public void displayMenu() {
// read records from database and store in tree
try {
this.readFromDatabase();
}
catch (Exception exception) {
System.out.println("Error in reading from database: " + exception
);
}
// list of choices
String[] choices = { "Add Person", "Edit Person", "Remove Person",
"Display Person", "Display List", "Exit Program",
"Node Information" };
// display loop
int choice = 0;
while (choice != choices.length) {
choice = JOptionPane.showOptionDialog(null, // put in center of
// screen
"Select a Command", // message to user
"Main Menu", // title of window
JOptionPane.YES_NO_CANCEL_OPTION, // type of option
JOptionPane.QUESTION_MESSAGE, // type of message
null, // icon