Assingment 6

Assingment 6
Assignment #6 – CSE205

Due: Friday, March 2th by 8:00PM

Requirements to get full credits in Documentation

The assignment number, your name, StudentID, and Lecture number need to be included at the top of each file/class.
An overview/purpose of each class needs to be described at the top of each class.
A description of each method is also needed.
Some additional comments inside of methods to explain codes that are hard to follow should be written.
You can look at the Java programs in the text book to see how comments are added to programs.

Minimal Submitted Files

You are required, but not limited, to turn in the following source files:

Assignment6.java (Assignment6 class extends JApplet)
CreatePanel.java – to be completed (it extends JPanel and contains ButtonListener nested class)
SelectPanel.java – to be completed (it extends JPanel and contains ButtonListener nested class)

You can download the above files and use them to complete this assignment. You might need to add more methods than the specified ones.
Skills to be Applied:

Swing/AWT

Classes may be needed:
JApplet, JButton, JTextField, JTextArea, JLabel, Container, JPanel, JTabbedPane, JScrollPane, Vector, JList, and ActionListener. You may use other classes.

How to run an applet program:

-Create an html file, say “hw6.html” with the following content:
——————————————————–

<HTML>
<HEAD>
<TITLE>Assignment 6 Applet</TITLE>
</HEAD>
<BODY>

<applet code=”Assignment6.class” width=550 height=250>
</applet>

</BODY>
</HTML>
——————————————————
-Compile your java program as usual.

-In a console, type:

appletviewer hw6.html

(instead of typing “java Assignment6”).

-In the TextPad, choose Tool->Run Java Applet or
press Ctrl-3 (press control key and 3 at the same time).

-In the jGrasp,
choose Run->Run as Applet.

Program Description

Suggested Class Diagram: (.ppt file is available for this figure)

Write a Java program that constructs an Applet. Your program should provide a label and a textfield to a user to enter a pet type.

The Applet (JApplet) of your program should contain two tabs. The first tab is labeled “Pet List Creation” and the second tab is labeled “Pet Selection”.

(The size of the applet here is approximately 500 X 200).

The section under the first tab should be divided into two parts:

The left part contains a label, a textfield, and a button for a user to enter a pet type. The right part shows “No pet” at the beginning (it is done using JTextArea).

A user can enter a pet name in the textfield, and push “Create a pet” button.

Then the pet type should appear on the right hand side panel. A message “Pet type added” should also appear with red color at the top of the panel.

Error handling:

1. If a user forgets to enter a pet type and pushes “Create a pet” button, show a message “Please enter a pet type.” with red color, and nothing should be added to the right hand side panel.

2. If a user enters a pet type that is already listed on the right hand side panel, and pushes “Create a pet” button, show a message “The pet type already exists.” with red color and nothing should be added to the right hand side panel.

After entering several pet types, the applet will have the following appearance.

Under the “Pet Selection” tab, there should be four parts. The left parts will have a list of “Available pet(s)”, pets that are created under “Pet List Creation” tab and a label saying “Available pet(s)”. This list needs to match with the list under the ” Pet List Creation ” tab. The right panel should have a label saying “Selected pet(s)”, but no pet type should be listed at the beginning. In the middle, there should be two buttons, one is “Add” button and the other is “Remove” button. Below these three parts, there should be a label showing “The number of selected pet(s): 0”. Note that this label will be changed later.

A user can choose which pet to add by clicking on a pet type on the left side list first, then pushing the add button. At this point, the pet to be added should appear in the list of right part. Note that if a user tries to add a pet type that is already listed in the right side, it should not be added twice, but you do not need to show an error message. Also, the right hand side list should show pet types in the order that they are added. This is not necessary the same order as the left hand side list.

Also, at this point, the number of selected pets should be incremented by 1, thus the label at the bottom should show “The number of selected pet(s): 1” and so on.

A user can also choose which pet to remove by clicking on a pet listed on the right part first, then pushing the remove button. At this point, the pet to be removed should disappear from the right hand side list, the number of selected pets should be decremented by 1, and the label below should be updated.

Class description

CreatePanel
CreatePanel class extends JPanel defined in javax.swing package. It should contain at least the following instance variable:

Attribute name
Attribute type
Description
petList
Vector
a list of pet types.
selectPanel
SelectPanel
an object of SelectPanel.
This class should have a constructor:

public CreatePanel(Vector petList, SelectPanel panel)

where the parameters “petList” and “panel” are passed from the Assignment6 class. The constructor layouts and organizes components in this panel. You will be adding more variables (components) than what is listed here, including a button, a label, a textfield, and a text area.

This class contains a nested class called ButtonListener class that implements ActionListener interface. Thus the ButtonListener needs to have a definition for actionPerformed method that updates the right hand side list or shows an error message. See the UML class diagram for the parameter and return type of this method.

SelectPanel
SelectPanel extends JPanel defined in the javax.swing package. It should contains at least the following instance variable:

Attribute name
Attribute type
Description
petList
Vector
a list of pet types.
This class should have a constructor:

public SelectPanel(Vectore petList)

where the parameter “petList” is passed from the Assignment6 class. The constructor layouts and organizes components in this panel. You will be adding more variables (components) that what is listed here, including JList objects, buttons, and labels.

public void updatePetList()

This method can refresh the appearance of the list of pets by calling updateUI() method for the JList. It can be called from the CreatePanel class whenever a new pet type is added to the vector and the JList appearence needs to be refreshed.

This class contains a nested class called ButtonListener class that implements ActionListener interface. Thus the ButtonListener needs to have a definition for actionPerformed method that defines actions to be performed in case “Add” or “Remove” buttons is pushed.

See the UML class diagram for the parameter and return type of this method.

Assignment6 class
Assignment6 class extends JAppet defined in javax.swing package. It contains at least init() method (see UML diagram for its return type) to instantiate all instance variables and adds its components to itself. It also sets its size. It contains at least following instance variables:

Attribute name
Attribute type
Description
petList
Vector
a list of pet types. It will be used in both createPanel and selectPanel.
createPanel
CreatePanel
an object of CreatePanel.
selectPanel
SelectPanel
an object of SelectPanel.
tPane
JTabbedPane
an object of JTabbedPane. It will contain createPanel and selectPanel under each tab.
Grading Policy:

submit assignment on time
indicate assignment number, name, ASU id, lecture number, description of each class clearly in each submitted java file
your program minimally has the following functionalities:
1 point: a textfield, a label, a button, and a text area are shown under the “Pet List Creation” tab.
1 point: when the “Create a pet” button is pushed, a pet type is added on the right panel in the correct order, and “pet type added” message shows.
1 point: Error handing in case the textfield is not filled.
1 point: Error handing in case an already existing pet type is entered.
1 point: The same list of pet types is shown under the ” Pet List Creation ” tab and under the “Pet Selection” tab.
2 points: A pet type is selected or unselected correctly by pushing the add button or the remove button under the selection panel.
1 point: The number of selected pets is updated correctly.

Leave a Reply

Your email address will not be published. Required fields are marked *