INFO-I211 Lab 4
??? Palindrome Tester GUI ???

Due date: see Oncourse Modules or Assignments
50 points

WARNING

This assignment is likely to change.

Learning Objectives

  1. Be able to develop a simple GUI (graphical user interface) in Java.
  2. Be able to write loops in Java.
  3. Be familiar with some useful Unix commands.

Part A. Useful Unix Commands.

(ADD DETAILS: Unix Tutorial part 6: gzip, file, diff, etc.)

Part B: Palindrome???

Instructions

A palindrome is a string that reads the same backwards and forwards, such as "abcba". A palindrome tester program allows a user to enter a palindrome candidate (a string), and determines whether the candidate is actually a palindrome or not.

This lab has two stages. In the first stage, you should build a graphical user interface (GUI) for a palindrome tester. In the second stage, you implement the actual palindrome tester.

Prerequisite for Stage 1: GUI material in chapters 1–4.

Prerequisite for Stage 2: sections 5.1–5.4 (if and while statements, nested loops) and 5.7 (determining event sources).

Stage 1: GUI

Build the graphical user interface. It needs components for user input of the palindrome candidate and to display the test result, and buttons to test the candidate and to quit from the program.

  • Use a JFrame with an appropriate title, with a JPanel, a JLabel to display the prompt, a JTextField to receive the input (a palindrome candidate), a JButton to test the palindrome candidate, either a JLabel or a JTextField to display the result of the test (i.e., it is or is not a palindrome), and another JButton to quit.
    • If you use a JTextField for the output, call output.setEditable(false) so the user cannot enter text in it.
    • To respond to the quit button, make the static method call System.exit(0).
  • For Stage 1, your actionPerformed method for the action listener should implement a "dummy" action, such as displaying "I don't know" in the result area, instead of actually testing whether the input is a palindrome. You will add the actual testing in Stage 2.
  • Don't worry too much about the layout (the geometrical arrangement) of the GUI components. Simply let the JPanel arrange its components using its default layout manager. We will learn how to control layout in a later chapter.

Stage 2: Palindrome Testing

In this stage, replace the dummy action of Stage 1 with actual palindrome testing. You may use as much or as little code from Listing 5.9 (pp. 237–238) as you wish; if you use it, you'll need to modify it to use the GUI developed in Stage 1, instead of console I/O. (Think of it as converting a legacy program to a flashy new user interface.)

  • The implicit event loop of the GUI replaces the outer loop of the console-I/O version. (Implicit means you do not write the event loop; you get it automatically by using Swing or AWT.) So, the program should not ask "Test another", and the user does not answer "y" or "n" since the question is not asked. The user simply presses the test button as many times as desired, and presses the quit button to quit. The test button causes the inner loop to run, and there is no outer loop.

If you use the provided code (Listing 5.9), you'll also need to fix an error. The empty string ("") is a palindrome, since it reads the same forward and backward, but the provided code does not handle it correctly. Kill this bug.

What to Turn in; Grading Criteria

Turn in, as attachments in Oncourse assignments, your source code and screenshots demonstrating your program with the following palindrom candidates as test data: "tamat", "rxxr", "rxxy", "rxyr", and "" (the empty string).

Grading: 80% correctness (40 points: 10 for palindrome testing, 30 for GUI) ; 20% (10 points) program style. The Coding Standards for chapters 1–6 apply to this assignment.