Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Minimal Submitted Files: You are required, but not limited, to turn in the follo

ID: 3795993 • Letter: M

Question

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.

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).

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.

FILES:

1) Assignment 6:

2) Flight (no changes required):

3) Schedule (no changes required):

4) CreatePanel - to be completed (it extends JPanel and contains ButtonListener nested class) :

5) SelectPanel - to be completed (it extends JPanel and contains ButtonListener nested class):

Attribute name

Attribute type

Description

flightList

ArrayList

a list of Flight objects.

Schedule Flight E Assignment6 -tPane:JTabbedPane -createPanel CreatePanel -selectPanel SelectPanel -flightList ArrayList nit void Check Box Listener titemStateChanged(ItemEvent):void JApplet defined in javax.swing JPanel defined in javax.swing Create Panell Select Panel -flight List:ArrayList -flightList: AmayList -selectPanel Select Panel +Select Panel (ArrayList) +addCheck Box(Flight):void +CreatePanel ArrayList,SelectPanel) Button Listener Arizona State University CSE205, Spring 2017 Assignment tactionPerformed(ActionEvent):void

Explanation / Answer

mport java.awt.*; import javax.swing.*; public class CustomComponent1 extends JFrame { private static final long serialVersionUID = 1L; public CustomComponent1() { setTitle("Custom Component Test / GridLayout"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void display() { setLayout(new GridLayout(10, 10, 10, 10)); for (int row = 0; row < 100; row++) { add(new CustomComponents1()); } //pack(); // enforces the minimum size of both frame and component setMinimumSize(getMinimumSize()); setPreferredSize(getPreferredSize()); setVisible(true); } public static void main(String[] args) { Runnable r = new Runnable() { @Override public void run() { CustomComponent1 main = new CustomComponent1(); main.display(); } }; javax.swing.SwingUtilities.invokeLater(r); } } class CustomComponents1 extends JLabel { private static final long serialVersionUID = 1L; @Override public Dimension getMinimumSize() { return new Dimension(20, 20); } @Override public Dimension getPreferredSize() { return new Dimension(20, 20); } @Override public void paintComponent(Graphics g) { int margin = 10; Dimension dim = getSize(); super.paintComponent(g); g.setColor(Color.red); g.fillRect(margin, margin, dim.width - margin * 2, dim.height - margin * 2); } } import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.Border; public class CustomComponent { Border emptyBorder = BorderFactory.createEmptyBorder(1,1,1,1); Border selectBorder = BorderFactory.createLineBorder(Color.blue); JPanel[] panels; private JPanel getContent() { JLabel label = new JLabel(); label.setText("fffffffff"); label.setBounds(5, 5, 25, 25); JLabel label2 = new JLabel(); label2.setText("HHHHHHHHHH"); label2.setBounds(25, 25, 25, 25); JLabel label3 = new JLabel(); label3.setText("YYYYYYYY"); label3.setBounds(50, 50, 25, 25); JPanel mainPanel = new JPanel(); mainPanel.setSize(new Dimension(300,300)); JPanel panel1 = new JPanel(); panel1.add(label); JPanel panel2 = new JPanel(); panel2.add(label2); JPanel panel3 = new JPanel(); panel3.add(label3); panel1.setBackground(Color.WHITE); panel2.setBackground(Color.MAGENTA); panel3.setBackground(Color.orange); panel1.setBorder(emptyBorder); panel2.setBorder(emptyBorder); panel3.setBorder(emptyBorder); panels = new JPanel[] { panel1, panel2, panel3 }; mainPanel.add(panel1); mainPanel.add(panel2); mainPanel.add(panel3); return mainPanel; } public static void main(String[] args) { JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new CustomComponent().getContent()); frame.pack(); frame.setVisible(true); } }