import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.io.*;
import java.text.*;
class Frame1 extends JFrame implements ActionListener
{
JLabel lbl=new JLabel("FLIGHT RESERVATION SYSTEM");
Font f=new Font("Broadway",Font.BOLD,45);
Font f1=new Font("Comic Sans",Font.BOLD,15);
Font f2=new Font("Bradley Hand",Font.BOLD,24);
JLabel lblticket,lblseat,lblclass,lbldestination,lbldepar t,lblarrival,lbltotal,lbln,lblusa,lblcanada,lbls,l bla,lblae,lblbr,lblp;
JTextField txtticket,txtseat,txtclass,txtdestination,txtdepar t,txtarrival,txttotal;
JRadioButton rbFirst,rbeco, rbbus,rbw,rbo,rbh,rbm,rbar,rbmo,rbva,rbto,rbot,rbq ,rbb,rbs,rbf,rbca,rbboa,rbp,rbtac,rbpe,rbpu,rbtr,r bri,rbha,rbtab,rbji,rbasir;
JButton btncompute, btnadd,btnedit,btnsearch,btndelete;
JButton btnnext,btnprev,btnlast,btnfirst,btnexit;
String gen;
ResultSet rs=null;
Connection con=null;
Statement stmt=null;
Frame1()
{
super("FLIGHT RESERVATION DETAILS");
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
setLayout(null);
add(lbl);
lbl.setBounds(50,60,860,40);
// set the font of lbl label
lbl.setFont(f);
// initializa all the label which are declared in the example above with its caption name
lblticket=new JLabel("TICKETNO:");
lblseat=new JLabel("SEATNO:");
lblclass=new JLabel("CLASS");
lbldestination=new JLabel("DESTINATION");
lbln=new JLabel ("NORTH AMERICA");
lblusa=new JLabel("USA");
lblcanada= new JLabel("Canada");
lbls=new JLabel("SOUTH AMERICA");
lblbr=new JLabel("Brazil");
lblp= new JLabel("Peru");
lbla=new JLabel("ASIA");
lblae=new JLabel("UAE");
lbldepart=new JLabel("DEPART TIME");
lblarrival=new JLabel ("ARRIVAL TIME");
lbltotal=new JLabel("TOTAL:");
lblticket.setBounds(30,120,100,20);
lblseat.setBounds(30,160,100,20);
lblclass.setBounds(500,120,100,20);
lbldestination.setBounds(500,170,300,20);
lbln.setBounds(350,190,200,20);
lblusa.setBounds(320,220,200,20);
lblcanada.setBounds(430,220,200,20);
lblbr.setBounds(560,220,200,20);
lblp.setBounds(710,220,200,20);
lbls.setBounds(580,190,200,20);
lbla.setBounds(850,190,200,20);
lblae.setBounds(870,220,200,20);
lbldepart.setBounds(20,200,100,20);
lblarrival.setBounds(20,220,100,20);
lbltotal.setBounds(30,250,100,20);
add(lblticket);
add(lblseat);
add(lblclass);
add(lbldestination);
add(lbldepart);
add(lblarrival);
add(lbltotal);
add(lbln);
add(lblusa);
add(lblcanada);
add(lbls);
add(lblbr);
add(lblp);
add(lbla);
add(lblae);
lblticket.setFont(f1);
lblseat.setFont(f1);
lblclass.setFont(f2);
lbldestination.setFont(f2);
lbldepart.setFont(f1);
lblarrival.setFont(f1);
lbltotal.setFont(f1);
lbln.setFont(f1);
lbls.setFont(f1);
lblbr.setFont(f1);
lblp.setFont(f1);
lbla.setFont(f1);
lblae.setFont(f1);
lblusa.setFont(f1);
lblcanada.setFont(f1);
txtticket=new JTextField(10);
txtseat=new JTextField (10);
txtdepart=new JTextField(10);
txtarrival=new JTextField(10);
txttotal= new JTextField(10);
txtticket.setBounds(120,120,150,20);
txtseat.setBounds(120,160,150,20);
txtdepart.setBounds(120,200,150,20);
txtarrival.setBounds(120,220,150,20);
txttotal.setBounds(120,250,150,20);
add(txtticket);
add(txtseat);
add(txtdepart);
add(txtarrival);
add(txttotal);
rbFirst= new JRadioButton("First");
rbeco= new JRadioButton("Economy");
rbbus=new JRadioButton("Business");
rbw= new JRadioButton("Washington D.C");
rbo= new JRadioButton("Oklahama");
rbh= new JRadioButton("Honolulu");
rbar=new JRadioButton("Phoenix");
rbm=new JRadioButton("New Mexico");
rbmo=new JRadioButton("Montreal");
rbva=new JRadioButton("Vancouver");
rbto=new JRadioButton("Toronto");
rbot=new JRadioButton("Ottawa");
rbq=new JRadioButton("Quebec");
rbb=new JRadioButton("Brasilia");
rbs= new JRadioButton("Salvador");
rbf= new JRadioButton("Fortaleza");
rbca= new JRadioButton("Campo Grande");
rbboa=new JRadioButton("Boa Vista");
rbp=new JRadioButton("Lima");
rbtac =new JRadioButton("Tacha");
rbpu =new JRadioButton("Pucallpa");
rbpe =new JRadioButton("Peura");
rbtr =new JRadioButton("Trujillo");
rbri=new JRadioButton("Riyadh");
rbha =new JRadioButton("Hail");
rbtab =new JRadioButton("Tabuk");
rbji =new JRadioButton("Jizan");
rbasir =new JRadioButton("Asir");
rbFirst.setBounds(400,140,50,30);
rbeco.setBounds(500,140,100,30);
rbbus.setBounds(600,140,100,30);
rbw.setBounds(280,240,130,20);
rbo.setBounds(280,260,100,20);
rbh.setBounds(280,280,100,20);
rbar.setBounds(280,300,100,20);
rbm.setBounds(280,320,100,20);
rbmo.setBounds(420,240,100,20);
rbva.setBounds(420,260,100,20);
rbto.setBounds(420,280,100,20);
rbot.setBounds(420,300,100,20);
rbq.setBounds(420,320,100,20);
rbb.setBounds(550,240,100,20);
rbs.setBounds(550,260,100,20);
rbf.setBounds(550,280,100,20);
rbca.setBounds(550,300,130,20);
rbboa.setBounds(550,320,130,20);
rbp.setBounds(700,240,100,20);
rbtac.setBounds(700,260,130,20);
rbpu.setBounds(700,280,130,20);
rbpe.setBounds(700,300,130,20);
rbtr.setBounds(700,320,100,20);
rbri.setBounds(850,240,130,20);
rbha.setBounds(850,260,230,20);
rbtab.setBounds(850,280,230,20);
rbji.setBounds(850,300,230,20);
rbasir.setBounds(850,320,230,20);
add(rbFirst);
add(rbeco);
add(rbbus);
add(rbw);
add(rbo);
add(rbh);
add(rbar);
add(rbm);
add(rbb);
add(rbs);
add(rbf);
add(rbca);
add(rbboa);
add(rbp);
add(rbtac);
add(rbpe);
add(rbpu);
add(rbtr);
add(rbmo);
add(rbva);
add(rbto);
add(rbot);
add(rbq);
add(rbri);
add(rbha);
add(rbtab);
add(rbji);
add(rbasir);
rbFirst.addActionListener(this);
rbeco.addActionListener(this);
rbbus.addActionListener(this);
rbw.addActionListener(this);
rbo.addActionListener(this);
rbh.addActionListener(this);
rbm.addActionListener(this);
rbar.addActionListener(this);
rbmo.addActionListener(this);
rbot.addActionListener(this);
rbto.addActionListener(this);
rbva.addActionListener(this);
rbq.addActionListener(this);
rbb.addActionListener(this);
rbs.addActionListener(this);
rbf.addActionListener(this);
rbca.addActionListener(this);
rbboa.addActionListener(this);
rbp.addActionListener(this);
rbtac.addActionListener(this);
rbpe.addActionListener(this);
rbpu.addActionListener(this);
rbtr.addActionListener(this);
rbri.addActionListener(this);
rbha.addActionListener(this);
rbtab.addActionListener(this);
rbji.addActionListener(this);
rbasir.addActionListener(this);
btnadd=new JButton("Add");
btnedit=new JButton("Edit");
btnsearch=new JButton("Search");
btndelete=new JButton("Delete");
btnadd.setBounds(200,410,100,30);
btnedit.setBounds(310,410,100,30);
btnsearch.setBounds(420,410,100,30);
btndelete.setBounds(530,410,100,30);
add(btnadd);
add(btnedit);
add(btnsearch);
add(btndelete);
btnadd.addActionListener(this);
btnedit.addActionListener(this);
btnsearch.addActionListener(this);
btndelete.addActionListener(this);
btnfirst=new JButton("First");
btnnext=new JButton("Next");
btnprev=new JButton("Previous");
btnlast=new JButton("Last");
btnfirst.setBounds(200,450,100,30);
btnnext.setBounds(310,450,100,30);
btnprev.setBounds(420,450,100,30);
btnlast.setBounds(530,450,100,30);
add(btnfirst);
add(btnnext);
add(btnprev);
add(btnlast);
btnfirst.addActionListener(this);
btnnext.addActionListener(this);
btnprev.addActionListener(this);
btnlast.addActionListener(this);
btnexit=new JButton("EXIT");
btnexit.setBounds(360,510,100,30);
add(btnexit);
btnexit.addActionListener(this);
btncompute=new JButton("Compute");
btncompute.setToolTipText("Click this button to compute the total");
btncompute.setBounds(80,275,100,30);
add(btncompute);
btncompute.addActionListener(this);
dbOpen();
}
public void actionPerformed(ActionEvent ae)
{
try
{
if(ae.getActionCommand()=="Compute"){
double total = 0.0;
double date
if(rbFirst.isSelected()){
total +=5000;
}
if(rbeco.isSelected()){
total+=2500;
}
if(rbbus.isSelected()){
total+=1000;
}
if(rbw.isSelected()){
total+=38274;
date +=23;
}
if(rbo.isSelected()){
total+=52782;
date +=11;
}
if(rbb.isSelected()){
total+=93117;
date +=11;
}
if(rbs.isSelected()){
total+=104537;
date +=11;
}
if(rbf.isSelected()){
total+=40450;
date +=11;
}
if(rbmo.isSelected()){
total+=71610;
date +=23;
}
if(rbva.isSelected()){
total+=55440;
date +=30;
}
if(rbto.isSelected()){
total+=62920;
date +=24;
}
if(rbot.isSelected()){
total+=73850;
date +=24;
}
if(rbq.isSelected()){
total+=70660;
date +=23;
}
if(rbri.isSelected()){
total+=51790;
date +=19;
}
if(rbha.isSelected()){
total+=80720;
date +=24;
}
if(rbtab.isSelected()){
total+=63950;
date +=29;
}
if(rbji.isSelected()){
total+=102800;
date +=25;
}
if(rbasir.isSelected()){
total+=52480;
date +=23;
}
if(rbb.isSelected()){
total+=93117;
date +=33;
}
if(rbs.isSelected()){
total+=104537;
date +=39;
}
if(rbf.isSelected()){
total+=40450;
date +=41;
}
if(rbp.isSelected()){
total+=144100;
date +=27;
}
if(rbtac.isSelected()){
total+=125778;
date +=28;
}
if(rbpe.isSelected()){
total+=142662;
date +=48;
}
if(rbtr.isSelected()){
total+=144427;
date +=45;
}
if(rbb.isSelected()){
total+=139122;
date +=39;
}
if(rbs.isSelected()){
total+=144727;
date +=33;
}
if(rbf.isSelected()){
total+=152505;
date +=41;
}
if(rbboa.isSelected()){
total+=139122;
date +=56;
}
if(rbca.isSelected()){
total+=158319;
date +=42;
}
DecimalFormat dollars = new DecimalFormat("Php0.00");
txttotal.setText(dollars.format(total));
DateFormat sdf = new SimpleDateFormat("K:mm:ss a,z");
txtarrival.setText(sdf.format(date));
}
if(ae.getActionCommand()=="Add")
{
txtticket.setText("");
txtseat.setText("");
txtclass.setText("");
txtdestination.setText("");
txtdepart.setText("");
txtarrival.setText("");
}
if(ae.getActionCommand()=="Save")
{
stmt.executeUpdate("INSERT INTO STUDENTINFO VALUES('" + txtticket.getText() + "','" + txtseat.getText() + "','" + txtclass.getText() + "'," + txtdestination.getText() + "'," + txtarrival.getText() + "')");
dbClose();
dbOpen();
}
if(ae.getActionCommand()=="Delete")
{
stmt.executeUpdate("DELETE FROM STUDENTINFO WHERE ticket=" + txtticket.getText() + "");
dbClose();
dbOpen();
}
if(ae.getActionCommand()=="Search")
{
stmt.executeUpdate("SEARCH * FROM STUDENTINFO WHERE ticket=" + txtticket.getText() + "");
dbClose();
dbOpen();
}
if(ae.getActionCommand()=="Next")
{
if(rs.next())
{
setText();
}
else
{
JOptionPane.showMessageDialog(null, "You are already at Last Record", "Messarrival", JOptionPane.ERROR_MESSAGE);
}
}
if(ae.getActionCommand()=="Previous")
{
if(rs.previous())
{
setText();
}
else
{
JOptionPane.showMessageDialog(null, "You Are Already At First Record", "Messarrival", JOptionPane.ERROR_MESSAGE);
}
}
if (ae.getActionCommand()=="First")
{
if(rs.first())
{
setText();
}
}
if (ae.getActionCommand()=="Last")
{
if(rs.last())
{
setText();
}
}
if(ae.getActionCommand()=="EXIT")
{
System.exit(0);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void dbOpen()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbcdbc:mydsn");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SEN SITIVE,ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("Select * from STUDENTINFO");
if(rs.next())
setText();
}catch(Exception e){}
}
public void dbClose()
{
try{stmt.close();
rs.close();
con.close();
}catch(Exception e){}
}
public void setText(){
try{
txtticket.setText(rs.getString(1));
txtseat.setText(rs.getString(2));
txtclass.setText(rs.getString(3));
txtdestination.setText(rs.getString(4));
txtarrival.setText(rs.getString(5));
txtdepart.setText(rs.getString(6));
}catch(Exception ex){}
}
}
class Frame
{
public static void main(String arg[])throws Exception
{
Frame1 f1=new Frame1();
f1.setSize(1000,600);
f1.setVisible(true);
UIManager.setLookAndFeel("javax.swing.plaf.metal.M etalLookAndFeel");
}
}