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
g.
History Class XII Ch. 3 Kinship, Caste and Class (1).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();
}