Back to 111 Main Page

Mobius strip

Assignment 14

Task

Create a different user interface for your to-do list from Assignment 11.

Steps

You are going to write a very primitive GUI (graphical user interface) for a to-do list. You may use your own ToDoList class, or else you can use mine: ToDoList.class and ToDoListItem.class. These are the class files; just dump them in the same directory as the rest of your code. My ToDoList has the four methods as documented on the A11 page.

Your GUI should do everything the UI for A11 did, except replace all uses of System.out.println and Scanner with calls to JOptionPane methods. The two JOptionPane methods you need to know are:

  • JOptionPane.showMessageDialog(null, "Your message here.") -- Displays a pop-up with an OK button and the message "Your message here." The first parameter is a reference to the parent component (window); since we have no parent window, just use null.
  • JOptionPane.showInputDialog("Your prompt here: ") -- Displays a pop-up with an input box, an OK and Cancel buttons, and the message "Your prompt here: ". This method returns a String containing whatever the user types into the input box. If the user just hits OK, you'll get the empty string (""). If the user closes the window or hits Cancel, you'll get null instead.

You can learn more about JOptionPane in the API documentation. You will need to import javax.swing.JOptionPane; at the start of your file.

As an example, your main menu screen should look something like this:

Main menu screen shot.

Since you can now read in only Strings, you will need to use Integer's method parseInt to convert a String to an int. Here is an example:

  String menu = "1. Do some stuff.\n";
  menu += "2. Quit.\n\n";
  menu += "Choose an option: ";
  String input = JOptionPane.showInputDialog(menu);
  int choice = Integer.parseInt(input);

Optional: If you want to catch the exception caused by the user entering something other than a number, note that parseInt throws a NumberFormatException rather than an InputMismatchException.

What to submit

If you just used my classes, attach only your ToDoListGUI.java to an email. If you used your ToDoList, attach all files needed to run your program.

FAQs

Sample progam?
Yeah, right here: AgeCalculator.java
The ToDoList won't delete the first item in the list.
Yeah, there was a bug in the original version of ToDoList.class I released: I made sure that index was > 1 rather than index > 0. The current version has been corrected. If you have this problem, just download the .class files again.
How do I display the ToDoList in the main menu dialog?
Call the toString method on the todo list object and append it to the menu string you're creating:
  String menu = "TODO LIST:\n";
  menu += todo.toString() + "\n";
  ...

Grading

Out of 10 points:

1 - Submission and Coding Standards
Follows required submission policies and coding standards.
1 - Compiles
Remember to include all needed files (if I don't already have them)!
1 - Displaying the list
Your program first displays the contents of the list time each time it asks the user to select a menu choice.
2 - Adding to the list
You can add new items to the list, specifying any string and then an urgency rating (1 to 10, only) for that item.
1 - Removing from the list
You can remove an item from the list by specifying the displayed index number of the item to remove.
1 - Changing item urgency
You can change the urgency rating of an item already in the list.
1 - Error-checking
Your program gracefully handles incorrect input of the same type as requested, such as numbers out of the valid range, incorrect menu choices, closed or cancelled pop-ups, etc.
2 - No System.out.println or Scanners
All aspects of the new UI use JOptionPanes.


~ztomasze Index : TA Details: ICS111: Assignment 14
http://www2.hawaii.edu/~ztomasze
Last Edited: 15 Apr 2008
©2008 by Z. Tomaszewski.