lectures.htm
 

Assignment 8

Class name: QuizGUI.class, NewQuizDialog.class
File name: QuizGUI.java, NewQuizDialog.java
Type: Object and application
Due Date: 12-11-02

Description: Design, implement and test a basic Quiz GUI application. This application will use the following classes used in Assignment 7. You are given the following classes: Question, MultiChoiceQuestion, TrueFalseQuestion, Choice and ArrUtil (you also need EasyIn which you already have. NOTE: That EasyIn will only be needed to compile your application because your quiz classes already use it. YOU ALSO NEED YOUR Quiz.java FROM THE PREVIOUS ASSIGNMENT). In addition, you will need these classes: QuizGUI.java, NewQuizDialog.java, TFQuestionForm.java, QuestionForm.java, RunQuizForm.java. You will only need to modify QuizGUI.java and NewQuizDialog.java. Once completed, the instructor will use your classes in a program to test the classes' implementations.

To view the final application, download this jar file, QuizGUI.jar and run
java -jar QuizGUI.jar

at the command prompt. Note: you must have Java 1.2 or higher for this to work.

1. (QuizGUI) Add a menu item to the "File" menu labeled "Exit". You need to add the appropriate event handler to this menu item that terminates the application when a user click on this item. This will look as follows:

To add a menu item to a menu you need to use the menu's "add( menuItem )" component.

2. (QuizGUI) Add a menu to the application titled "Help" (You can see this in the above picture). You need to add this Menu to the application's MenuBar before the method, "setMenuBar( MeunBar )" is called in the application's constructor. The menu bar is called "menuBar". Help should also have a menu item called "About". You need to add the appropriate event handler to the "About" item, so when it is clicked on it displays a dialog with information about the application. You do this by registering an event listener, ActionListener, to the "About" menu item. The dialog should have a label and one button titled "OK". When it is clicked on the dialog should be disposed. You should use JOptionPane's static method showMessageDialog() to create and display this dialog. Here is what your dialog should look like:

You need to include "CIS 226", "Introduction to Java Programming", "Fullerton College" and your name.

The menu that calls this dialog should look as follows:

Note: menu and menu items should be private members of the class.

3. (NewQuizDialog) You are given a basic skeleton class, NewQuizDialog, you need to add the components to this class to create a dialog looks as follows:

You will need to add a JLabel, JTextField, and a JButton titled "OK". I have provided some code that declares these components. If you choose not to use my code, the other implementation will be up to you to complete. You will need to lay your components out so the dialog looks identical to the one displayed. Hint: you will need additional help from JPanels.

This dialog is called automatically when the application is started. I have done this for you. You need to implement the specs to make it functional.

4. (NewQuizDialog) Add the appropriate handler to the "OK" button to allow users to click on the button and have the handler submit the quiz's title to create a quiz. Hint: You need to register and actionListener to the button, i.e. okBtn.addActionListener( listener ), and implement the ActionListener's declared method, actionPerformed( ActionEvent ).

5. (NewQuizDialog) Add the appropriate handler to the "OK" button to allow users to press on any key and have the handler submit the quiz's title to create a quiz. Hint: You need to register and actionListener to the button, i.e. okBtn.addKeyListener( KeyListener ), and implement the KeyListener's declared method(s), keyPressed( KeyEvent ). If you use the listener's adapter classes you will only need to implement the methods needed. However, if you use the KeyListener interface, you will have to implement all methods declared in the interface.

6. (NewQuizDialog) Add the appropriate handler to the text field to allow users to press the "ENTER" key and have the handler submit the quiz's title to create a quiz.Hint: You need to register and actionListener to the button, i.e. titleTxtFld.addKeyListener( KeyListener ), and implement the KeyListener's declared method(s), keyPressed( KeyEvent ). If you use the listener's adapter classes you will only need to implement the methods needed. However, if you use the KeyListener interface, you will have to implement all methods declared in the interface.

7. (NewQuizDialog) Add the appropriate code to the private method "handleBasicEvent()" so this dialog is hidden if an error occurs, then displays another error dialog by using JOptionPane.showMessageDialog(), then when the error dialog is terminated, you should display the New Quiz dialog again. Your error dialog should look as follows:

The application looks as like:

Hint: you can hide dialogs with setVisible( boolean ) method from the java.awt.Component class. The Component class is a parent class of JDialog.

8. EXTRA CREDIT (QuizGUI) Change the look and feel of this application to a windows look and feel.

I have taken care of all of the code that handles the tree control as well as the code that displays different forms in the right-hand side of the split pane. If you modify my code, it is your responsibility to fix anything that doesn't compile. Your source code is marked with comments:

/*********** TODO 1 ***************/

YOUR CODE WILL GO HERE


/*********** END TODO 1 ***************/

Where TODO # represents the task number for this assignment. This is an advanced GUI application, so I don't expect you to know everything about it. However, I do expect you to be able to modify the code I have supplied you with.

Objectives:
* Be able to create GUI components.
* Understand Abstract Data Type (ADT)
* Understand Inner classes and event handling
* Understand menus and menu items
* Understand Object Oriented Programming concepts of encapsulation and polymorphism

 

Home | Syllabus | Lectures | Assignments | Schedule | Coding Conventions | Links