Java Swing
Table of Content
|
Topic |
Page |
|
Introduction |
3 |
|
Software Resources: |
4 |
|
Hardware Resources |
4 |
|
Program Listing |
5 |
|
Sample output |
8 |
|
References |
10 |
Introduction
The Flight Application shows how to book a flight ticket, where the Passenger chooses the class he/she wants, number of seats , and one way or two way.
The program depending on the option entered below will calculate the price.
First class=5500 SAR
Business Class= 3200 SAR
Economy Class= 1000 SAR
Software Resources:
JCreator Program
Hardware Resources
Pentium 4 1GH Or above
Ram 1G
Program Listing
Hierarchy of the program
class Passenger
public String Pname;
public Passenger()
public Passenger(String Pname_2,String TClass_2,int seat_2,String way_2)
public double GetPrice()
public String GetPassenger()
Abstract Reserv
public int seat; public String way; public double price; public String TClass;
public Reserv (String TClass_2,int seat_2,String way_2)
public abstract double GetPrice();
public String GetInfo()
Interface Classes
public final int first_class= 5500; public final int business_class=3200; public final int economy_class=1000;
public String GetInfo();
Description :
To apply inheritance and produce an application we did it this way :
· The Reserv class implements the Classes interface
· The Passenger class extends Reserv class
The Flight Application :
· Extends the Jframe and implements the ActionListener
So we can use the SWING features which is GUI as result
Controls & containers components:
1- JComboBox to disply class options :
"First Class","Business Class","Economy Class"
2- ButtonGroup to hold directions :
JRadioButton one = new JRadioButton("One Way");
JRadioButton two = new JRadioButton("Two Way");
3- JTextField to display :
Name
Price
seats
4- JPanel to contain the componenets
5- JButton to interact with user click
The program logic :
When user chooses the options the program send the parameters through the Object :
Reserv passenger;
By using the constructor
public Passenger(String Pname_2,String TClass_2,int seat_2,String way_2)
The class receive parameters and do the calculations required depending on the :
A- TClass_2:
To calculate the price
B- way_2:
To return the price or double it if two way is selected
C- seat_2 :
Multiply price by no of seats
Program Exceptions:
1- Predefined Exception :
where Java ensure the input is correct
1-if the user leave the field empty
2-if the user puts negative value or zero
Sample output
If seat is left empty :
If seat number is negative or zero :
If none of the previous mistakes happened:
References
· Absolute Java 5th edition
· http://www.java2s.com/Tutorial/Java/0240__Swing/Settooltipforbutton.htm
· http://stackoverflow.com/questions/17314253/simple-jframe-with-a-combobox-and-a-textfield-and-a-result-in-a-label
1