SlideShare a Scribd company logo
The first part of the assignment involves creating very basic GUI controls: a frame, panel, and
slider.
Create a JFrame. Add a title to the frame called Flight Reservation. Set the frame size to 475 by
500 pixels. Create a JPanel inside of the frame. You will be adding all of your UI components to
this JPanel. [6 pts]
Inside of the panel, create a label that says "Choose Color." Right below it, make a slider that
changes the background color of the panel when the slider is moved to a particular color. The
slider values should be RGB color values from 0 to 255 (or black to white). Assume that the
RGB values for red, green, and blue are the same value - for instance: (240, 240, 240). The slider
label's text should be replaced with the RGB value that the slider is currently on. [8 pts]
Q2: Add functionality to search for an Itinerary.
Create labels and text fields that allow the user to enter an airline, a source airport, and a
destination airport, as well as the departure time and the arrival time to search for one or more
available flights in an Itinerary. Also, create a ComboBox that will allow the user to select from
a list of flight Itineraries. Each item in the ComboBox represents an Itinerary element, e.g. the
first comboBoxelement is the first Itinerary in the array. [15 pts]
Make sure all text fields have error checking and exception handling for invalid input. For
example, if the user enters an integer as a departure time instead of a String (ie 1200 instead of
12:00 PM), a JOptionPane error message should appear stating, "Incorrect format for departure
time." If the airline they entered is not in the Airline enum, then the option pane should say,
"Airline unavailable. Please choose a different airline." If the airport they entered is not in the
Airport enum, then the option pane should say, "Unknown city." Make sure the times are in
hh:mm format. [8 pts]
Q3: Create a button that says Search and a button that says View. When the user clicks Search,
the combobox will get populated. When the user clicks View, if all the fields are filled out and
have valid input, a JOptionPane with a message dialog should appear stating, "Flight search
successful!" The frame should open a new JFrame with the title, "Flight Information," and a
size of 475 by 500 pixels. This frame has the flight information displayed in a JTextArea. [6 pts]
Q4: On the Flight Information frame, you will need to display information for each Flight in the
Itinerary [7 points]:
Airline: Display the airline
Model: The model of the airplane should be generated from the Plane object inside of the Flight
class.
Departure Airport: Display the source airport
Departure City: Display the departure city based on the departure airport (use the
getAirportCity() method you implemented in the Unit 3 assignment to get the airport city)
Destination Airport: Display the destination airport
Destination City: Display the destination city based on the destination airport (use the
getAirportCity() method again)
Departure Time: Display the departure time
Arrival Time: Display the arrival time
Flight Number: A flight number should be selected based on the airline, followed by the Flight's
number.
Cost: Display the total cost, which should be computed by the Itinerary object.
Solution
I have given you the sample codes with inline commands.
The code shown below is for the question number 1 and the remaining answers you can do in
similar manner.
create panel for each module and add every module into the frame.
Pannel layout can be decided by setting the layout property
eg: " panel.setLayout(new GridLayout(6, 2, 15, 0));"
For better understanding please split all the classes into separate files.
void java.awt.Window.pack() method packs the panel properly into the frame eg:frame.pack(“)
it avoids missing the panel elements from the frame
ChangeListner extends event Listener so that it capture the changes in the slider and immediate
effect can be seen in the panel
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class test extends JFrame {
public test() {
JFrame frame = new JFrame("JFrame");
frame.setTitle("Flight Reservation");
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(new ColourPick());
frame.add(panel);
frame.setSize(475, 500);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
// add this code for packing the panel inside frame
frame.pack();
}
public static void main(String arg[]) {
new test();
}
}
class ColourPick extends JPanel {
DrawingCanvas canvas = new DrawingCanvas();
JLabel rgbValue = new JLabel("");
JSlider sliderR, sliderG, sliderB, sliderH, sliderS, sliderBr,
sliderAlpha;
public ColourPick() {
sliderR = getSlider(0, 255, 0, 50, 5);
sliderG = getSlider(0, 255, 0, 50, 5);
sliderB = getSlider(0, 255, 0, 50, 5);
sliderH = getSlider(0, 10, 0, 5, 1);
sliderS = getSlider(0, 10, 0, 5, 1);
sliderBr = getSlider(0, 10, 0, 5, 1);
sliderAlpha = getSlider(0, 255, 255, 50, 5);
JPanel panel = new JPanel();
JLabel label = new JLabel("Choose Color");
// add the panel size here according to your needs
panel.setLayout(new GridLayout(6, 2, 15, 0));
panel.add(label);
panel.add(new JLabel("R-G-B Sliders (0 - 255)"));
panel.add(new JLabel("H-S-B Sliders (ex-1)"));
panel.add(sliderR);
panel.add(sliderH);
panel.add(sliderG);
panel.add(sliderS);
panel.add(sliderB);
panel.add(sliderBr);
panel.add(new JLabel("Alpha Adjustment (0 - 255): ", JLabel.RIGHT));
panel.add(sliderAlpha);
panel.add(new JLabel("RGB Value: ", JLabel.RIGHT));
rgbValue.setBackground(Color.white);
rgbValue.setForeground(Color.black);
rgbValue.setOpaque(true);
panel.add(rgbValue);
add(panel, BorderLayout.SOUTH);
add(canvas);
}
public JSlider getSlider(int min, int max, int init, int mjrTkSp, int mnrTkSp) {
JSlider slider = new JSlider(JSlider.HORIZONTAL, min, max, init);
slider.setPaintTicks(true);
slider.setMajorTickSpacing(mjrTkSp);
slider.setMinorTickSpacing(mnrTkSp);
slider.setPaintLabels(true);
slider.addChangeListener(new SliderListener());
return slider;
}
class DrawingCanvas extends Canvas {
Color color;
int redValue, greenValue, blueValue;
int alphaValue = 255;
float[] hsbValues = new float[3];
public DrawingCanvas() {
setSize(350, 350);
color = new Color(0, 0, 0);
setBackgroundColor();
}
public void setBackgroundColor() {
color = new Color(redValue, greenValue, blueValue, alphaValue);
setBackground(color);
}
}
class SliderListener implements ChangeListener {
public void stateChanged(ChangeEvent e) {
JSlider slider = (JSlider) e.getSource();
if (slider == sliderAlpha) {
canvas.alphaValue = slider.getValue();
canvas.setBackgroundColor();
} else if (slider == sliderR) {
canvas.redValue = slider.getValue();
displayRGBColor();
} else if (slider == sliderG) {
canvas.greenValue = slider.getValue();
displayRGBColor();
} else if (slider == sliderB) {
canvas.blueValue = slider.getValue();
displayRGBColor();
} else if (slider == sliderH) {
canvas.hsbValues[0] = (float) (slider.getValue() * 0.1);
displayHSBColor();
} else if (slider == sliderS) {
canvas.hsbValues[1] = (float) (slider.getValue() * 0.1);
displayHSBColor();
} else if (slider == sliderBr) {
canvas.hsbValues[2] = (float) (slider.getValue() * 0.1);
displayHSBColor();
}
canvas.repaint();
}
public void displayHSBColor() {
canvas.color = Color.getHSBColor(canvas.hsbValues[0],
canvas.hsbValues[1], canvas.hsbValues[2]);
canvas.redValue = canvas.color.getRed();
canvas.greenValue = canvas.color.getGreen();
canvas.blueValue = canvas.color.getBlue();
sliderR.setValue(canvas.redValue);
sliderG.setValue(canvas.greenValue);
sliderB.setValue(canvas.blueValue);
canvas.color = new Color(canvas.redValue, canvas.greenValue,
canvas.blueValue, canvas.alphaValue);
canvas.setBackground(canvas.color);
}
public void displayRGBColor() {
canvas.setBackgroundColor();
Color.RGBtoHSB(canvas.redValue, canvas.greenValue, canvas.blueValue,canvas.hsbValues);
sliderH.setValue((int) (canvas.hsbValues[0] * 10));
sliderS.setValue((int) (canvas.hsbValues[1] * 10));
sliderBr.setValue((int) (canvas.hsbValues[2] * 10));
rgbValue.setText(Integer.toString(canvas.color.getRGB() & 0xffffff, 16));
}
}
}

More Related Content

Similar to The first part of the assignment involves creating very basic GUI co.pdf

Cs practical file
Cs practical fileCs practical file
Cs practical file
Shailendra Garg
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdf
atulkapoor33
 
Please help with creating a javascript file to produce the outcome bel.pdf
Please help with creating a javascript file to produce the outcome bel.pdfPlease help with creating a javascript file to produce the outcome bel.pdf
Please help with creating a javascript file to produce the outcome bel.pdf
info750646
 
Please help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdfPlease help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdf
pankajsingh316693
 
Java Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdfJava Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdf
SudhanshiBakre1
 
Ex32018.pdf
Ex32018.pdfEx32018.pdf
Ex32018.pdf
ssuser211b2b
 
Change transport system in SAP
Change transport system in SAP Change transport system in SAP
Change transport system in SAP
chinu141
 
I really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdfI really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdf
pasqualealvarez467
 
Training Storyboard
Training StoryboardTraining Storyboard
Training Storyboard
haven832
 
XIX PUG-PE - Pygame game development
XIX PUG-PE - Pygame game developmentXIX PUG-PE - Pygame game development
XIX PUG-PE - Pygame game development
matheuscmpm
 
Creating an Uber Clone - Part III - Transcript.pdf
Creating an Uber Clone - Part III - Transcript.pdfCreating an Uber Clone - Part III - Transcript.pdf
Creating an Uber Clone - Part III - Transcript.pdf
ShaiAlmog1
 
Csphtp1 07
Csphtp1 07Csphtp1 07
Csphtp1 07
HUST
 
Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1Muhammad Shebl Farag
 
Java Graphics
Java GraphicsJava Graphics
Java Graphics
Shraddha
 
Jetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning TourJetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning Tour
Matthew Clarke
 
Scala+swing
Scala+swingScala+swing
Scala+swingperneto
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Appletbackdoor
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16HUST
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
rajkumari873
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
Andi Simanjuntak
 

Similar to The first part of the assignment involves creating very basic GUI co.pdf (20)

Cs practical file
Cs practical fileCs practical file
Cs practical file
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdf
 
Please help with creating a javascript file to produce the outcome bel.pdf
Please help with creating a javascript file to produce the outcome bel.pdfPlease help with creating a javascript file to produce the outcome bel.pdf
Please help with creating a javascript file to produce the outcome bel.pdf
 
Please help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdfPlease help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdf
 
Java Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdfJava Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdf
 
Ex32018.pdf
Ex32018.pdfEx32018.pdf
Ex32018.pdf
 
Change transport system in SAP
Change transport system in SAP Change transport system in SAP
Change transport system in SAP
 
I really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdfI really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdf
 
Training Storyboard
Training StoryboardTraining Storyboard
Training Storyboard
 
XIX PUG-PE - Pygame game development
XIX PUG-PE - Pygame game developmentXIX PUG-PE - Pygame game development
XIX PUG-PE - Pygame game development
 
Creating an Uber Clone - Part III - Transcript.pdf
Creating an Uber Clone - Part III - Transcript.pdfCreating an Uber Clone - Part III - Transcript.pdf
Creating an Uber Clone - Part III - Transcript.pdf
 
Csphtp1 07
Csphtp1 07Csphtp1 07
Csphtp1 07
 
Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1
 
Java Graphics
Java GraphicsJava Graphics
Java Graphics
 
Jetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning TourJetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning Tour
 
Scala+swing
Scala+swingScala+swing
Scala+swing
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 

More from neerajsachdeva33

Can you please explain those risk management from Kaiser Permanente.pdf
Can you please explain those risk management from Kaiser Permanente.pdfCan you please explain those risk management from Kaiser Permanente.pdf
Can you please explain those risk management from Kaiser Permanente.pdf
neerajsachdeva33
 
A survey of 2630 musicians showed that 372 of them are left-handed. .pdf
A survey of 2630 musicians showed that 372 of them are left-handed. .pdfA survey of 2630 musicians showed that 372 of them are left-handed. .pdf
A survey of 2630 musicians showed that 372 of them are left-handed. .pdf
neerajsachdeva33
 
What is other disorder of arteries beside atherosclerosis What.pdf
What is other disorder of arteries beside atherosclerosis What.pdfWhat is other disorder of arteries beside atherosclerosis What.pdf
What is other disorder of arteries beside atherosclerosis What.pdf
neerajsachdeva33
 
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdfWhy is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
neerajsachdeva33
 
What type of relationship typically exists between the resident and t.pdf
What type of relationship typically exists between the resident and t.pdfWhat type of relationship typically exists between the resident and t.pdf
What type of relationship typically exists between the resident and t.pdf
neerajsachdeva33
 
What is the model for floral induction by day-lengthSolutionB.pdf
What is the model for floral induction by day-lengthSolutionB.pdfWhat is the model for floral induction by day-lengthSolutionB.pdf
What is the model for floral induction by day-lengthSolutionB.pdf
neerajsachdeva33
 
What is the difference between a semi-permeable and selectively perm.pdf
What is the difference between a semi-permeable and selectively perm.pdfWhat is the difference between a semi-permeable and selectively perm.pdf
What is the difference between a semi-permeable and selectively perm.pdf
neerajsachdeva33
 
what did Linnaeus contribute to taxonomySolutionThe classifica.pdf
what did Linnaeus contribute to taxonomySolutionThe classifica.pdfwhat did Linnaeus contribute to taxonomySolutionThe classifica.pdf
what did Linnaeus contribute to taxonomySolutionThe classifica.pdf
neerajsachdeva33
 
We are interested in whether the proportions of female suicide victim.pdf
We are interested in whether the proportions of female suicide victim.pdfWe are interested in whether the proportions of female suicide victim.pdf
We are interested in whether the proportions of female suicide victim.pdf
neerajsachdeva33
 
True or false Fruits attract animals that act as pollinators T.pdf
True or false Fruits attract animals that act as pollinators T.pdfTrue or false Fruits attract animals that act as pollinators T.pdf
True or false Fruits attract animals that act as pollinators T.pdf
neerajsachdeva33
 
the observed locations of integrated retroviral proviruses within ho.pdf
the observed locations of integrated retroviral proviruses within ho.pdfthe observed locations of integrated retroviral proviruses within ho.pdf
the observed locations of integrated retroviral proviruses within ho.pdf
neerajsachdeva33
 
The general name for something that binds to a protein is Select one.pdf
The general name for something that binds to a protein is  Select one.pdfThe general name for something that binds to a protein is  Select one.pdf
The general name for something that binds to a protein is Select one.pdf
neerajsachdeva33
 
serial communication, parallel communication, SPI and ADCs. Write .pdf
serial communication, parallel communication, SPI and ADCs. Write .pdfserial communication, parallel communication, SPI and ADCs. Write .pdf
serial communication, parallel communication, SPI and ADCs. Write .pdf
neerajsachdeva33
 
Suppose that a heap stores 210 elements. What is its height (show w.pdf
Suppose that a heap stores 210 elements. What is its height (show w.pdfSuppose that a heap stores 210 elements. What is its height (show w.pdf
Suppose that a heap stores 210 elements. What is its height (show w.pdf
neerajsachdeva33
 
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdf
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdfOxfam used its existing opt-in e-mail list only for this campaign; i.pdf
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdf
neerajsachdeva33
 
Please distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdfPlease distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdf
neerajsachdeva33
 
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdfJUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
neerajsachdeva33
 
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdfIn the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
neerajsachdeva33
 
Information about dengue fever is provided on the following pages. A.pdf
Information about dengue fever is provided on the following pages. A.pdfInformation about dengue fever is provided on the following pages. A.pdf
Information about dengue fever is provided on the following pages. A.pdf
neerajsachdeva33
 
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdfA toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
neerajsachdeva33
 

More from neerajsachdeva33 (20)

Can you please explain those risk management from Kaiser Permanente.pdf
Can you please explain those risk management from Kaiser Permanente.pdfCan you please explain those risk management from Kaiser Permanente.pdf
Can you please explain those risk management from Kaiser Permanente.pdf
 
A survey of 2630 musicians showed that 372 of them are left-handed. .pdf
A survey of 2630 musicians showed that 372 of them are left-handed. .pdfA survey of 2630 musicians showed that 372 of them are left-handed. .pdf
A survey of 2630 musicians showed that 372 of them are left-handed. .pdf
 
What is other disorder of arteries beside atherosclerosis What.pdf
What is other disorder of arteries beside atherosclerosis What.pdfWhat is other disorder of arteries beside atherosclerosis What.pdf
What is other disorder of arteries beside atherosclerosis What.pdf
 
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdfWhy is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
Why is a egg cell is much larger than a sperm cell Explain in 1-2 p.pdf
 
What type of relationship typically exists between the resident and t.pdf
What type of relationship typically exists between the resident and t.pdfWhat type of relationship typically exists between the resident and t.pdf
What type of relationship typically exists between the resident and t.pdf
 
What is the model for floral induction by day-lengthSolutionB.pdf
What is the model for floral induction by day-lengthSolutionB.pdfWhat is the model for floral induction by day-lengthSolutionB.pdf
What is the model for floral induction by day-lengthSolutionB.pdf
 
What is the difference between a semi-permeable and selectively perm.pdf
What is the difference between a semi-permeable and selectively perm.pdfWhat is the difference between a semi-permeable and selectively perm.pdf
What is the difference between a semi-permeable and selectively perm.pdf
 
what did Linnaeus contribute to taxonomySolutionThe classifica.pdf
what did Linnaeus contribute to taxonomySolutionThe classifica.pdfwhat did Linnaeus contribute to taxonomySolutionThe classifica.pdf
what did Linnaeus contribute to taxonomySolutionThe classifica.pdf
 
We are interested in whether the proportions of female suicide victim.pdf
We are interested in whether the proportions of female suicide victim.pdfWe are interested in whether the proportions of female suicide victim.pdf
We are interested in whether the proportions of female suicide victim.pdf
 
True or false Fruits attract animals that act as pollinators T.pdf
True or false Fruits attract animals that act as pollinators T.pdfTrue or false Fruits attract animals that act as pollinators T.pdf
True or false Fruits attract animals that act as pollinators T.pdf
 
the observed locations of integrated retroviral proviruses within ho.pdf
the observed locations of integrated retroviral proviruses within ho.pdfthe observed locations of integrated retroviral proviruses within ho.pdf
the observed locations of integrated retroviral proviruses within ho.pdf
 
The general name for something that binds to a protein is Select one.pdf
The general name for something that binds to a protein is  Select one.pdfThe general name for something that binds to a protein is  Select one.pdf
The general name for something that binds to a protein is Select one.pdf
 
serial communication, parallel communication, SPI and ADCs. Write .pdf
serial communication, parallel communication, SPI and ADCs. Write .pdfserial communication, parallel communication, SPI and ADCs. Write .pdf
serial communication, parallel communication, SPI and ADCs. Write .pdf
 
Suppose that a heap stores 210 elements. What is its height (show w.pdf
Suppose that a heap stores 210 elements. What is its height (show w.pdfSuppose that a heap stores 210 elements. What is its height (show w.pdf
Suppose that a heap stores 210 elements. What is its height (show w.pdf
 
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdf
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdfOxfam used its existing opt-in e-mail list only for this campaign; i.pdf
Oxfam used its existing opt-in e-mail list only for this campaign; i.pdf
 
Please distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdfPlease distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdf
 
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdfJUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
JUST DO QUESTION 4 1. When you are preparing a budget where could yo.pdf
 
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdfIn the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
In the paramyxoviruses, cleavage of the F0 protein into two subunits .pdf
 
Information about dengue fever is provided on the following pages. A.pdf
Information about dengue fever is provided on the following pages. A.pdfInformation about dengue fever is provided on the following pages. A.pdf
Information about dengue fever is provided on the following pages. A.pdf
 
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdfA toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
A toothcomb, rhinarium or moist nose, and vertical clinging and leapi.pdf
 

Recently uploaded

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 

Recently uploaded (20)

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 

The first part of the assignment involves creating very basic GUI co.pdf

  • 1. The first part of the assignment involves creating very basic GUI controls: a frame, panel, and slider. Create a JFrame. Add a title to the frame called Flight Reservation. Set the frame size to 475 by 500 pixels. Create a JPanel inside of the frame. You will be adding all of your UI components to this JPanel. [6 pts] Inside of the panel, create a label that says "Choose Color." Right below it, make a slider that changes the background color of the panel when the slider is moved to a particular color. The slider values should be RGB color values from 0 to 255 (or black to white). Assume that the RGB values for red, green, and blue are the same value - for instance: (240, 240, 240). The slider label's text should be replaced with the RGB value that the slider is currently on. [8 pts] Q2: Add functionality to search for an Itinerary. Create labels and text fields that allow the user to enter an airline, a source airport, and a destination airport, as well as the departure time and the arrival time to search for one or more available flights in an Itinerary. Also, create a ComboBox that will allow the user to select from a list of flight Itineraries. Each item in the ComboBox represents an Itinerary element, e.g. the first comboBoxelement is the first Itinerary in the array. [15 pts] Make sure all text fields have error checking and exception handling for invalid input. For example, if the user enters an integer as a departure time instead of a String (ie 1200 instead of 12:00 PM), a JOptionPane error message should appear stating, "Incorrect format for departure time." If the airline they entered is not in the Airline enum, then the option pane should say, "Airline unavailable. Please choose a different airline." If the airport they entered is not in the Airport enum, then the option pane should say, "Unknown city." Make sure the times are in hh:mm format. [8 pts] Q3: Create a button that says Search and a button that says View. When the user clicks Search, the combobox will get populated. When the user clicks View, if all the fields are filled out and have valid input, a JOptionPane with a message dialog should appear stating, "Flight search successful!" The frame should open a new JFrame with the title, "Flight Information," and a size of 475 by 500 pixels. This frame has the flight information displayed in a JTextArea. [6 pts] Q4: On the Flight Information frame, you will need to display information for each Flight in the Itinerary [7 points]: Airline: Display the airline Model: The model of the airplane should be generated from the Plane object inside of the Flight class. Departure Airport: Display the source airport Departure City: Display the departure city based on the departure airport (use the
  • 2. getAirportCity() method you implemented in the Unit 3 assignment to get the airport city) Destination Airport: Display the destination airport Destination City: Display the destination city based on the destination airport (use the getAirportCity() method again) Departure Time: Display the departure time Arrival Time: Display the arrival time Flight Number: A flight number should be selected based on the airline, followed by the Flight's number. Cost: Display the total cost, which should be computed by the Itinerary object. Solution I have given you the sample codes with inline commands. The code shown below is for the question number 1 and the remaining answers you can do in similar manner. create panel for each module and add every module into the frame. Pannel layout can be decided by setting the layout property eg: " panel.setLayout(new GridLayout(6, 2, 15, 0));" For better understanding please split all the classes into separate files. void java.awt.Window.pack() method packs the panel properly into the frame eg:frame.pack(“) it avoids missing the panel elements from the frame ChangeListner extends event Listener so that it capture the changes in the slider and immediate effect can be seen in the panel import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class test extends JFrame { public test() {
  • 3. JFrame frame = new JFrame("JFrame"); frame.setTitle("Flight Reservation"); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); panel.add(new ColourPick()); frame.add(panel); frame.setSize(475, 500); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // add this code for packing the panel inside frame frame.pack(); } public static void main(String arg[]) { new test(); } } class ColourPick extends JPanel { DrawingCanvas canvas = new DrawingCanvas(); JLabel rgbValue = new JLabel(""); JSlider sliderR, sliderG, sliderB, sliderH, sliderS, sliderBr, sliderAlpha; public ColourPick() { sliderR = getSlider(0, 255, 0, 50, 5); sliderG = getSlider(0, 255, 0, 50, 5); sliderB = getSlider(0, 255, 0, 50, 5); sliderH = getSlider(0, 10, 0, 5, 1); sliderS = getSlider(0, 10, 0, 5, 1); sliderBr = getSlider(0, 10, 0, 5, 1); sliderAlpha = getSlider(0, 255, 255, 50, 5); JPanel panel = new JPanel(); JLabel label = new JLabel("Choose Color"); // add the panel size here according to your needs
  • 4. panel.setLayout(new GridLayout(6, 2, 15, 0)); panel.add(label); panel.add(new JLabel("R-G-B Sliders (0 - 255)")); panel.add(new JLabel("H-S-B Sliders (ex-1)")); panel.add(sliderR); panel.add(sliderH); panel.add(sliderG); panel.add(sliderS); panel.add(sliderB); panel.add(sliderBr); panel.add(new JLabel("Alpha Adjustment (0 - 255): ", JLabel.RIGHT)); panel.add(sliderAlpha); panel.add(new JLabel("RGB Value: ", JLabel.RIGHT)); rgbValue.setBackground(Color.white); rgbValue.setForeground(Color.black); rgbValue.setOpaque(true); panel.add(rgbValue); add(panel, BorderLayout.SOUTH); add(canvas); } public JSlider getSlider(int min, int max, int init, int mjrTkSp, int mnrTkSp) { JSlider slider = new JSlider(JSlider.HORIZONTAL, min, max, init); slider.setPaintTicks(true); slider.setMajorTickSpacing(mjrTkSp); slider.setMinorTickSpacing(mnrTkSp); slider.setPaintLabels(true); slider.addChangeListener(new SliderListener()); return slider; } class DrawingCanvas extends Canvas { Color color; int redValue, greenValue, blueValue; int alphaValue = 255; float[] hsbValues = new float[3]; public DrawingCanvas() {
  • 5. setSize(350, 350); color = new Color(0, 0, 0); setBackgroundColor(); } public void setBackgroundColor() { color = new Color(redValue, greenValue, blueValue, alphaValue); setBackground(color); } } class SliderListener implements ChangeListener { public void stateChanged(ChangeEvent e) { JSlider slider = (JSlider) e.getSource(); if (slider == sliderAlpha) { canvas.alphaValue = slider.getValue(); canvas.setBackgroundColor(); } else if (slider == sliderR) { canvas.redValue = slider.getValue(); displayRGBColor(); } else if (slider == sliderG) { canvas.greenValue = slider.getValue(); displayRGBColor(); } else if (slider == sliderB) { canvas.blueValue = slider.getValue(); displayRGBColor(); } else if (slider == sliderH) { canvas.hsbValues[0] = (float) (slider.getValue() * 0.1); displayHSBColor(); } else if (slider == sliderS) { canvas.hsbValues[1] = (float) (slider.getValue() * 0.1); displayHSBColor(); } else if (slider == sliderBr) { canvas.hsbValues[2] = (float) (slider.getValue() * 0.1); displayHSBColor(); } canvas.repaint(); }
  • 6. public void displayHSBColor() { canvas.color = Color.getHSBColor(canvas.hsbValues[0], canvas.hsbValues[1], canvas.hsbValues[2]); canvas.redValue = canvas.color.getRed(); canvas.greenValue = canvas.color.getGreen(); canvas.blueValue = canvas.color.getBlue(); sliderR.setValue(canvas.redValue); sliderG.setValue(canvas.greenValue); sliderB.setValue(canvas.blueValue); canvas.color = new Color(canvas.redValue, canvas.greenValue, canvas.blueValue, canvas.alphaValue); canvas.setBackground(canvas.color); } public void displayRGBColor() { canvas.setBackgroundColor(); Color.RGBtoHSB(canvas.redValue, canvas.greenValue, canvas.blueValue,canvas.hsbValues); sliderH.setValue((int) (canvas.hsbValues[0] * 10)); sliderS.setValue((int) (canvas.hsbValues[1] * 10)); sliderBr.setValue((int) (canvas.hsbValues[2] * 10)); rgbValue.setText(Integer.toString(canvas.color.getRGB() & 0xffffff, 16)); } } }