Requirements to get full credits in Documentation
The assignment number, your name, student ID, lecture number, and a class/file description need to be included at the top of each file/class.
A description of each method is also needed.
Some additional comments inside of methods to explain code 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 (The Assignment6 class extends JApplet)
Flight.java
Schedule.java
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, ArrayList (very similar to ArrayList class)
Classes may be needed:
JApplet, JButton, JTextField, JTextArea, JLabel, Container, JPanel, JTabbedPane, JCheckBox, , 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
<titleAssignment 6 Applet</title
</head
<body
<applet code="Assignment6.class" width=500 height=400
</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
-In the jGrasp,
choose Run-Run as Applet.
To test to see if your machine is set to view an applet, please go to the following site:
Click this page
Program Description
Suggested Class Diagram:
Write a Java program that constructs an Applet. Your program should provide labels and textfields to a user to enter information regarding flights.
The Applet (JApplet) of your program should contain two tabs. The first tab is labeled "Flight Creation" and the second tab is labeled "Flight Selection".
(The size of the applet here is approximately 800 X 200).
The section under the first tab should be divided into two parts:
The left part contains labels, textfields, and a button for a user to enter some flight information. The right part shows "No flight" at the beginning (it is done using JTextArea).
A user can enter some flight information, and push "Create a flight" button.
Then the flight information should appear on the right hand side panel (note that the format of the flight information can be using toString() method of the Flight class). A message "Flight added" should also appear with red color at the top of the panel.
Error handling:
If a user forgets to enter some field and pushes "Create a flight" button, show a message "Please enter all fields." with red color, and nothing should be added to the right hand side panel.
If a user enters non-numeric value for its flight number or airfare and pushes "Create a flight" button, show a message "Please enter a number for its flight number and its airfare" with red color, and nothing should be added to the right hand side panel.
After entering several flights, the applet will have the following appearance. Note that a scroll pane needs to be added to show multiple flights.
Under the "Flight Selection" tab, a user can choose flights from There should be a JList containing all flights created by Flight Creation panel and a user can choose flights by clicking its check box.
The list of flights in the Selection Panel should be exactly same as the list under "Flight Creation" tab.
After choosing some flights by checking some check boxes, it should show the total airfare of the chosen flights in the JTextField below. This total purchase amount should be updated everytime a user check or uncheck each check box.
A user should be able to go back and forth between "Flight Creation" tab and "Flight Selection" tab, and these two panels need to have consistent information, i.e., the same list of flights.
Class description
SelectPanel
SelectPanel class extends JPanel defined in javax.swing package. It should contain at least the following instance variable:
Attribute name
Attribute type
Description
flightList
ArrayList
a list of Flight objects.
This class should have a constructor:
public SelectPanel(ArrayList flightList)
where the parameter "flightList" is 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 JLabel, a JTextField,and JCheckBoxs.
public void addCheckBox(Flight flight1)
This method create an object of JCheckBox using the toString of the Flight object parameter. This JCheckBox object needs to be added to the panel to be displayed. An object of CheckBoxListener class needs to be added to this JCheckBox so that it listens when a user checks or un-checks. This method needs to be called from the actionPerformed of ButtonListener of the CreatePanel class when a new Flight object is added.
This class contains a nested class called CheckBoxListener class that implements ItemListener interface. Thus you need to define its itemStateChanged method that is supposed to verify which check boxes are checked and add the airfare of the corresponding flights and display the total purchase amount to the JLabel using the dollar format (Please use NumberFormat class).
CreatePanel
CreatePanel extends JPanel defined in the javax.swing package. It should contain at least the following instance variable:
Attribute name
Attribute type
Description
flightList
ArrayList
a list of Flight objects.
selectPanel
SelectPanel
an object of SelectPanel.
This class should have a constructor:
public CreatePanel(ArrayList flightList, SelectPanel selectPanel)
where the parameter "flightList" is passed from the Assignment6 class and the second parameter is an object of SelectPanel. The constructor layouts and organizes components in this panel. You will be adding more variables (components) than what is listed here, including labels, textfields, a button, 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 adds some flight information to the list and does error handling. See the UML class diagram for the parameter and return type of this method. In the actionPerformed, you need to extract the information from the textfields for flight information. Then you can instantiate an object of the Flight class using the information. You can use the toString( ) method of the Flight object to display the information on the textarea on the right hand side and also add the Flight object to the "flightList". This is also where addCheckBox( ) method of the SelectPanel class needs to be called with its object "selectPanel". so that a new flight is added to the CreatePanel, the same one is added to the SelectPanel.
Assignment6 class
Assignment6 class extends JApplet 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
flightList
ArrayList
a list of Flight objects. It will be used in both CreatePanel and SelectPanel.
selectPanel
SelectPanel
an object of SelectPanel.
createPanel
CreatePanel
an object of CreatePanel.
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, lecture number, and description of each class clearly in each submitted java file
your program minimally has the following functionalities:
3 points: Appropriate components such as textfields, labels, etc. are shown under the "Flight Creation" and "Flight Selection" tabs. JScrollPane is added to display the entire information on each Panel.
1 point: When the "Create a flight" button is pushed, the flight information from textfields is added on the right panel in the correct order and the message of "Flight added" shows up.
1 point: Error handing in case some field is not filled.
1 point: Error handing in case non-numerica value is entered for flight number or airfare.
1 point: The same list of flights is shown under the "Flight Creation" tab and under the "Flight Selection" tab.
1 point: When a user checks or unchecks each check box in SelectPanel, it updates the total purchase amount in the textfield.