Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners railway reservation
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


shaikh sarfaraz
railway reservation
0 Answer(s)      2 years ago
Posted in : Java Beginners


hello sir, i am creating railway reservation application in jframe connectivity with sql server. i need a help in jcombo box in my program, when i select train number in jcombo box in other combo box it show the train name and when i select class then show the fare form sql database...... pls sir help me as soon because i want to submit my project in college as soon.

Here is my coding.

import javax.swing.*;
import java.awt.*;
import java.awt.Dimension;
import java.awt.event.*;
import java.sql.*;
import java.lang.*;
class Railway implements ActionListener
{
     Font fn1, fn2;
    JFrame frame1, frame2, frame3, frame4, frame5, frame6, frame7,frame8;
    JButton btn1, btn2, btnRes, btnsign,  btnEnq , btnCont ,  btnLoog, btn11,btn12, btn13, btn14, btnbook, btncancell,  btnback, btnsub, btncan,btnback1,btnb1,btnb2,btng2,btnc2;
    JLabel lbl1, lbl2, lbl3, lbl4,lbl20, lhea1, lfname, llname , lemail , lpwrd, lgend, ldob, lphone ,lblheading, ltrainno,  ltrainname,  lDOJ, lclass, lSf, lSt, lbord, lresvupto, lnameblock, lgen, lage, lmobile, lem, ldat, lheading2,lac,ltrain_no1,ltrain_name1,ldepart1,larrival1,lstat1,ldest1,lday1,lfare1,ldis1,limg1,limg2,limg3,limg4,limg5,limg6,limg7,limg8,limg9,limg10,lbltn,lbltname,lbldt,lblat,lblss,lblds,lblrd,lblc,lblf,lbld,lblh,lblh3,lblp;  
    JTextField txt1, txt2,txt12,txt18, txtfname, txtlname , txtemail, txtpwrd, txtdob, txtphone, txtadd, txttrainno,  txttrainname,  txtDOJ,  txtclass, txtSf, txtSt, txtbord, txtresvupto, txtnameblock, txtgen, txtage, txtmobile, txtem, txtdat ,txtac,txttrain_no1,txttrain_name1,txtdepart1,txtarrival1,txtstat1,txtdest1,txtday1,txtfare1,txtdis1,txttn,txttname,txtdt,txtat,txtss,txtds,txtrd,txtc,txtf,txtd,txtp;
    JRadioButton ma1,fe1;
    JComboBox cbo1, cbo2, cbo3,cbo4;  
     String gender;
    JTextArea title;
      String Time_Table[] = {"Train Number","Train Name","Departure Time","Arrival Time","Starting Station","Destination Station","Day of Departure","Class","Fare","Distance"};
      Object data[][] =  {
       {"02423","Rajdhani exp","5:20 a.m","6:00 p.m","Mumbai Central","Delhi","mon, wed, sat","1st A.c, 2nd A.c, 3rd A.c","1500,900,750,","800 k.m"},
       {"04116","Allhabad exp","12:00 a.m","10:00 p.m","Lokmaniya tilak mum","Allhabad jn","All day","1st A.c, 2nd A.c, 3rd A.c,Sleeper class","1590,1200,850,450","1500 k.m"},
        {"04601","Jammu tawi exp","10:40 a.m","12:15 p.m","Jammu tawi","Udhampur","All day","1st A.c, 2nd A.c, 3rd A.c,Sleeper class","1690,1300,1000,550","1800 k.m"},
       {"04727","Bikaner SF Special","15:00 p.m","12:55 p.m","Bandra Terminus","Bikaner Junction","mon,tue,wed","1st A.c, 2nd A.c, 3rd A.c,Sleeper class","1400,1100,750,350","1340 k.m"},
       {"06006","Kollam-Chennai SF Special","17:50 p.m","10:45 a.m","Kollam Junction","Chennai Central","mon,wed","1st A.c, 2nd A.c, 3rd A.c,Sleeper class","1400,1050,850,400","980 k.m"},
        {"06502","Garib Rath Special","20:15 p.m","11:25 a.m","Ahmedabad Junction","Yesvantpur Junction","mon,fri","1st A.c, 2nd A.c, 3rd A.c","1500,1200,850","1200 k.m"},
        {"07105","Ajmer exp","22:45 p.m","14:00 p.m","Ajmer Junction","Hyderabad Deccan","All Day","2nd A.c, 3rd A.c, sleeper class","1300,1100,400","1600 k.m"},
        {"08003","Howrah exp","16:10 p.m","05:00 a.m","Kolkata Howrah Junction","Mysore Junction","All Day","2nd A.c, 3rd A.c, sleeper class","1200,900,400","890 k.m"},
        {"08565","Visakhapatnam exp","19:40 p.m","09:00 a.m","Visakhapatnam Junction","Secunderabad Junction","mon,wed,sat","2nd A.c, 3rd A.c, sleeper class","1470,1350,550","1590 k.m"},
        {"09001","Mumbai Central sf","22:50 p.m","06:55 a.m","Mumbai Central","Ahmedabad Junction","mon,sat","1st A.c, 2nd A.c, 3rd A.c","1200,1000,800","450 k.m"},
        {"09562","Okha exp","11:25 a.m","05:35 a.m","OKHA","Bandra Terminus","mon,thurs,sat","2nd A.c, 3rd A.c, sleeper class","1200,900,400","980 k.m"}
};
     public Railway()
{
     fn1=new Font("GodOfWar",Font.BOLD,16);
     fn2=new Font("Bradley Hand ITC",Font.BOLD,40);
     ImageIcon abc = new ImageIcon("D:\\project\\Train_Icon_2.png");
     ImageIcon aaa = new ImageIcon("D:\\project\\pamban-bridge_1.jpg");
     ImageIcon bbb = new ImageIcon("D:\\project\\imagee.jpg");
     ImageIcon ccc = new ImageIcon("D:\\project\\images5.jpg");
     ImageIcon ddd = new ImageIcon("D:\\project\\4107.1348076329.jpg");
     ImageIcon eee = new ImageIcon("D:\\project\\image00.jpg");
     ImageIcon fff = new ImageIcon("D:\\project\\images6.jpg");
     ImageIcon ggg = new ImageIcon("D:\\project\\enqui.jpg");
     ImageIcon hhh= new ImageIcon("D:\\project\\images4.jpg");
     ImageIcon iii= new ImageIcon("D:\\project\\1572.1344322560.jpg");
     frame1 = new JFrame();
     frame2 = new JFrame();
     frame3 = new JFrame();
     frame4 = new JFrame();
     frame5 = new JFrame();
     frame6 = new JFrame();
     frame7 = new JFrame();
     frame8 = new JFrame();
     limg1 = new JLabel(abc);
     limg6 = new JLabel(eee);
     lbl1 = new JLabel("Indian Railway");
     lbl2 = new JLabel("User Name");
     txt1 = new JTextField();
     lbl3 = new JLabel("Password");
     txt2 = new JPasswordField();
     btn1 = new JButton("Login");
     btn2 = new JButton("Exit");
     btnsign = new JButton("Signup");
     limg5 = new JLabel(ddd);
     lbl4 = new JLabel("Reservation System");
     btnRes = new JButton("Reservation");
     btnEnq = new JButton("Enquiry");
     btnCont = new JButton("Contact us");
     btnLoog = new JButton("Logout");
     limg7 = new JLabel(fff);
     lblheading = new JLabel("Railway Reservation Requisition Form"); 
     ltrainno = new JLabel("Train No");
     txttrainno = new JTextField();
     ltrainname = new JLabel("Train Name");
     txttrainname = new JTextField(); 
     lDOJ = new JLabel("Date Of Journey");
     txtDOJ = new JTextField();
     lclass = new JLabel("Class");
     txtclass = new JTextField();
     lSf = new JLabel("Station From");
     txtSf = new JTextField();
     lSt = new JLabel("To Station");
     txtSt = new JTextField();
     lbord = new JLabel("Boarding at");
     txtbord = new JTextField();
     lresvupto = new JLabel("Reservation Upto");
     txtresvupto = new JTextField();
     lnameblock = new JLabel("Name In Block Letter");
     txtnameblock = new JTextField();
     lgen = new JLabel("Gender");
     txtgen = new JTextField();
     lage = new JLabel("Age");
     txtage = new JTextField();
     lmobile = new JLabel("Mobile No");
     txtmobile = new JTextField();
     lem = new JLabel("Email ID");
     txtem = new JTextField();
     ldat = new JLabel("Date");
     txtdat = new JTextField();
     lheading2 = new JLabel("For Office Use Only");
     lac = new JLabel("Amount Collected");
     txtac = new JTextField();
     btnbook = new JButton("Book Tickets");
     btncancell = new JButton("Cancellation");
     btnback = new JButton("Back");
       /* For Enquiry frame */
     limg3 = new JLabel(bbb);
     limg4 = new JLabel(ccc);
     lbl20 = new JLabel("Enter your train number");
     txt12 = new JTextField();
     btn12 = new JButton("Go");
     btn13 = new JButton("Back");
     btn14 = new JButton("Help");
        /* For signup page */
     limg2 = new JLabel(aaa);
    lhea1 = new JLabel("Sign up");
    lfname = new JLabel("First Name");
    txtfname = new JTextField();
    llname = new JLabel("Last Name");
    txtlname = new JTextField();
    lemail = new JLabel("Email ID");
    txtemail = new JTextField();
    lpwrd = new JLabel("Password");
    txtpwrd = new JPasswordField();
    lgend = new JLabel("Gender");
    ma1 = new JRadioButton("Male");
    fe1 = new JRadioButton("Female");
    ldob = new JLabel("D.O.B");
    txtdob = new JTextField();
    lphone = new JLabel("Phone Number");
    txtphone = new JTextField();
    btnsub = new JButton("Submit");
    btncan = new JButton("Cancel");  
        /*Coding for frame7*/
         limg8 = new JLabel(ggg);
         limg9 = new JLabel(hhh);   
         lblh = new JLabel("Your Query Result");
         lbltn = new JLabel("Train Number");
         txttn = new JTextField();
         lbltname = new JLabel("Train Name");
         txttname = new JTextField();
         lbldt = new JLabel("Departure Time");
         txtdt = new JTextField();
         lblat = new JLabel("Arrival Time");
         txtat = new JTextField();
         lblss = new JLabel("Starting Station");
         txtss = new JTextField();
         lblds = new JLabel("Destination Station");
         txtds = new JTextField();
         lblrd = new JLabel("Running Day");
         txtrd = new JTextField();
         lblc = new JLabel("Coach");
         txtc = new JTextField();
         lblf = new JLabel("Fare");
         txtf = new JTextField();
         lbld = new JLabel("Distance");
         txtd = new JTextField();
         btnb1 = new JButton("Back");
         btnb2 = new JButton("Go For Reservation Form");
         /* For frame 8*/
         limg10 = new JLabel(iii);
         lblh3 = new JLabel("Cancellation of Tickets");
         lblp = new JLabel("Enter The Pnr Number");
         txtp = new JTextField();
         btng2 = new JButton("Go");
         btnc2 = new JButton("cancel");
 }       
   public void reservation() 
{
          /* setbounds for frame1 */
         frame1.getContentPane().setBackground(new Color(195,186,133));
         frame1.getContentPane().setLayout(null);
         limg1.setBounds(12, 9,280, 144);
         limg6.setBounds(12, 135,1004, 438);
         lbl1.setBounds(343, 9,150,30);
         lbl2.setBounds(628, 9,65,35);
         txt1.setBounds(631, 36,191, 20);
         lbl3.setBounds(837, 9,70,35);
         txt2.setBounds(840, 36,191, 20);
         btn1.setBounds(631, 75,75,23);
         btn2.setBounds(729, 75,75,23);
         btnsign.setBounds(924, 75,133, 23);
                  /* setbounds for frame2 */
       frame2.getContentPane().setBackground(new Color(195,186,133));
       frame2.getContentPane().setLayout(null);
       limg2.setBounds(312, 48,241, 149);
       limg5.setBounds(146, 43,870, 530);
       lbl4.setBounds(324,20,200,25);
       btnRes.setBounds(37, 68,110,25);
       btnEnq.setBounds(37, 130,110,23);
       btnCont.setBounds(37, 196,110,23);
       btnLoog.setBounds(37, 268,110,23);
              /* setbounds for frame3*/
       frame3.getContentPane().setBackground(new Color(195,186,133));
       frame3.getContentPane().setLayout(null);
       limg7.setBounds(12, 9,256, 108);
       lblheading.setBounds(337, 9,439, 23);
       ltrainno.setBounds(134, 164,70, 13);
       //txttrainno.setBounds(256, 157,184, 20);

       ltrainname.setBounds(533, 157,70, 13); 
      // txttrainname.setBounds(638, 157,184, 20);
       lDOJ.setBounds(134, 214,110, 13);
       txtDOJ.setBounds(256, 207,184, 20);
       lclass.setBounds(533, 210,40, 13);
       //txtclass.setBounds(638, 203,184, 20);
       lSf.setBounds(134, 263,80,13);
       txtSf.setBounds(256, 256,184, 20);
       lSt.setBounds(532, 256,70, 13);
       txtSt.setBounds(638, 253,184, 20);
       lbord.setBounds(134, 309,80,13);
       txtbord.setBounds(256, 302,184, 20);
       lresvupto.setBounds(533, 305,120, 13);
       txtresvupto.setBounds(638, 302,184, 20);
       lnameblock.setBounds(134, 348,130, 13);
       txtnameblock.setBounds(256, 341,184, 20);  
       lgen.setBounds(533, 348,42, 13);
       txtgen.setBounds(638, 348,184, 20);
       lage.setBounds(532, 391,26, 13);
       txtage.setBounds(638, 391,184, 20);
       lmobile.setBounds(134, 387,55, 13);
       txtmobile.setBounds(256, 387,184, 20);
       lem.setBounds(134, 433,46, 13);
       txtem.setBounds(256, 434,184, 20);
       ldat.setBounds(532, 437,30, 13);
       txtdat.setBounds(638, 437,184, 20);
       lheading2.setBounds(134, 474,251, 17);
       lac.setBounds(134, 512,110, 13);
       txtac.setBounds(256, 505,184, 20);
       btnbook.setBounds(586, 512,124, 23);
       btncancell.setBounds(727, 512,127, 23);
       btnback.setBounds(870, 512,127, 23);
             /* setbounds for frame4 */
       frame4.getContentPane().setBackground(new Color(195,186,133));
       frame4.getContentPane().setLayout(null);
       limg3.setBounds(12, 161,1004, 412);
       limg4.setBounds(12, 9,321, 151);
       lbl20.setBounds(681, 9,150, 13);
       txt12.setBounds(684, 34,222, 20);
       btn12.setBounds(684, 69,75, 23);
       btn13.setBounds(869, 69,75, 23);
       btn14.setBounds(777, 69,75, 23);
               /* signup setbounds for frame5 */
       frame5.getContentPane().setBackground(new Color(195,186,133));
       frame5.getContentPane().setLayout(null);
       limg2.setBounds(459, 9,543, 352);
       lhea1.setBounds(264,9,198,38);
       lfname.setBounds(103, 134,80,13);
       txtfname.setBounds(230,134,195,20);
       llname.setBounds(103,180,70,13);
       txtlname.setBounds(230,177,195,20);
       lemail.setBounds(103,221,70,13);
       txtemail.setBounds(230,221,195,20);
       lpwrd.setBounds(103,262,70,13);
       txtpwrd.setBounds(230,262,195,20);
       lgend.setBounds(103,302,55,13);
       ma1.setBounds(230,302,90,18);
       fe1.setBounds(340,302,90,17);
       ldob.setBounds(104,339,40,13);
       txtdob.setBounds(230,339,195,20);
       lphone.setBounds(103,386,95,13);
        txtphone.setBounds(230,386,195,20);
       btnsub.setBounds(500, 389,80,23);
       btncan.setBounds(500, 445,80,23);
     /*Frame7 setBounds*/    
       frame7.getContentPane().setBackground(new Color(195,186,133));
       frame7.getContentPane().setLayout(null); 
        limg8.setBounds(403, 224,613, 349);
        limg9.setBounds(394, 9,399, 202);
        lblh.setBounds(134, 9,190,13);
        lbltn.setBounds(12, 72,80,13);
        txttn.setBounds(137, 69,222, 20);
        lbltname.setBounds(12, 111,80, 13);
        txttname.setBounds(137, 108,222,20);
        lbldt.setBounds(12, 151,90, 13); 
        txtdt.setBounds(137, 148,222,20);
        lblat.setBounds(12, 191,80, 13);
        txtat.setBounds(137, 191,222,20);
        lblss.setBounds(12, 231,90, 13);
        txtss.setBounds(137, 231,222,20);
        lblds.setBounds(12, 270,110, 13);
        txtds.setBounds(137, 270,222,20);
        lblrd.setBounds(12, 311,120, 13);
        txtrd.setBounds(137, 311,222,20);
        lblc.setBounds(12, 347,60, 13);
        txtc.setBounds(137, 347,222,20);
        lblf.setBounds(12, 387,60, 13);
        txtf.setBounds(137, 387,222,20);
        lbld.setBounds(12, 425,60,13);
        txtd.setBounds(137, 425,222,20);
        btnb1.setBounds(137, 472,75, 23);
        btnb2.setBounds(246, 472,190,23);
           /* setBounds for frame 8 */
       frame8.getContentPane().setBackground(new Color(195,186,133));
       frame8.getContentPane().setLayout(null);
        limg10.setBounds(12, 116,1004, 457);
        lblh3.setBounds(284, 9,300,23);
        lblp.setBounds(820, 18,150,13);
        txtp.setBounds(823, 51,193, 20);
        btng2.setBounds(823, 90,75,23);
        btnc2.setBounds(941, 90,75,23);
           /* object for button group */
       ButtonGroup obj =new ButtonGroup();
       obj.add(ma1);
       obj.add(fe1);
               /* object of  table  */
          JTable table = new JTable(data,Time_Table);
         /* adding font to label */
        lbl1.setFont(fn1);
        lbl4.setFont(fn1);
        lbl1.setFont(fn1);
        lhea1.setFont(fn2);
        lblheading.setFont(fn1);
        lheading2.setFont(fn1);
        lblh.setFont(fn1);
        lblh3.setFont(fn1);
        frame1.add(limg1);
        frame1.add(limg6);
        frame1.add(lbl1);
        frame1.add(lbl2);
        frame1.add(txt1);
        txt1.setToolTipText("xyz@gmail.com");
        frame1.add(lbl3);
        frame1.add(txt2);
        txt2.setToolTipText("Enter password");
        frame1.add(btn1);
        btn1.setToolTipText("Login");
        frame1.add(btn2);
        btn2.setToolTipText("Exit");
        frame1.add(btnsign);
        btnsign.setToolTipText("sign in");
        frame2.add(limg2);
        frame2.add(limg5);
        frame2.add(lbl4);
        frame2.add(btnRes);
        btnRes.setToolTipText("Reservation");
        frame2.add(btnEnq);
        btnEnq.setToolTipText("Enquiry");
        frame2.add(btnCont);
        btnCont.setToolTipText("Contact us");
        frame2.add(btnLoog);
        btnLoog.setToolTipText("Logout");
        frame3.add(limg7);
        frame3.add( lblheading);
        frame3.add(ltrainno);
        //frame3.add(txttrainno);

        frame3.add(ltrainname);
        frame3.add(txttrainname);
        frame3.add(lDOJ);
        frame3.add(txtDOJ);
        frame3.add(lclass);

        frame3.add(lSf);
        frame3.add(txtSf);
        frame3.add(lSt);  
        frame3.add(txtSt);
        frame3.add(lbord);
        frame3.add(txtbord);
        frame3.add(lresvupto);
        frame3.add(txtresvupto);
        frame3.add(lnameblock);
        frame3.add(txtnameblock);
        frame3.add(lgen);
        frame3.add(txtgen);
        frame3.add(lage);
        frame3.add(txtage);
        frame3.add(lmobile);
        frame3.add(txtmobile);
        frame3.add(lem);
        frame3.add(txtem);
        frame3.add(ldat);
        frame3.add(txtdat);
        frame3.add(lheading2);
        frame3.add(lac);
        //frame3.add(txtac);
        frame3.add(btnbook);
        btnbook.setToolTipText("Book Tickets");
        frame3.add(btncancell);
        btncancell.setToolTipText("Cancellation");
        frame3.add(btnback);
        btnback.setToolTipText("Back");
        frame4.add(limg3);
        frame4.add(limg4);
        frame4.add(lbl20);
        frame4.add(txt12);
        frame4.add(btn12);
        btn12.setToolTipText("Go");
        frame4.add(btn13);
       btn13.setToolTipText("Back");
        frame4.add(btn14);
        btn14.setToolTipText("Help");
        frame5.add(limg2);
        frame5.add(lhea1);
        frame5.add(lfname);
        frame5.add(txtfname);
        txtfname.setToolTipText("Please enter your First name");
        frame5.add(llname);
        frame5.add(txtlname);
        txtlname.setToolTipText("Please enter your Last name");
        frame5.add(lemail);
        frame5.add(txtemail);
        txtemail.setToolTipText("i.e,john@gmail.com");
        frame5.add(lpwrd);
        frame5.add(txtpwrd);
        txtpwrd.setToolTipText("Enter your password");
        frame5.add(lgend);
        frame5.add(ma1);
        frame5.add(fe1);
        frame5.add(ldob);
        frame5.add(txtdob);
        txtdob.setToolTipText("dd/mm/yyyy");
        frame5.add(lphone);
        frame5.add(txtphone);
        txtphone.setToolTipText("i.e, Enter a 10 digit mobile number");
        frame5.add(btnsub);
        btnsub.setToolTipText("Submit");
        frame5.add(btncan);
        btncan.setToolTipText("Cancel");
        frame6.add(table);
        frame6.add(table.getTableHeader(),BorderLayout.PAGE_START);
        frame7.add(limg8);
        frame7.add(limg9);
        frame7.add(lblh);
        frame7.add(lbltn);
        frame7.add(txttn);
        frame7.add(lbltname);
        frame7.add(txttname);
        frame7.add(lbldt);
        frame7.add(txtdt);
        frame7.add(lblat);
        frame7.add(txtat);
        frame7.add(lblss);
        frame7.add(txtss);
        frame7.add(lblds);
        frame7.add(txtds);
        frame7.add(lblrd);
        frame7.add(txtrd);
        frame7.add(lblc);
        frame7.add(txtc);
        frame7.add(lblf);
        frame7.add(txtf);
        frame7.add(lbld);
        frame7.add(txtd);
        frame7.add(btnb1);
        btnb1.setToolTipText("Back");
        frame7.add(btnb2);
         btnb2.setToolTipText("Go For Reservation Form");
        frame8.add(limg10);
        frame8.add(lblh3);
         frame8.add(lblp);
         frame8.add(txtp);
         txtp.setToolTipText("Enter your tickets pnr number i.e, 123456");
         frame8.add(btng2); 
         btng2.setToolTipText("Go");
         frame8.add(btnc2);
         btnc2.setToolTipText("Cancel");
        frame1.setTitle("Login Form");
        frame1.setSize(1044,620);
        frame1.setVisible(true);
        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
      lbl1.setBackground(Color.black);
      lbl1.setForeground(Color.blue);
      btn1.setBackground(Color.blue);
      btn1.setForeground(Color.white);
      btn2.setBackground(Color.blue);
      btn2.setForeground(Color.white);
      btnsign.setBackground(Color.blue);
      btnsign.setForeground(Color.white);
    /* Adding button into action listener */
      btn1.addActionListener(this);
      btn2.addActionListener(this);
      btnRes.addActionListener(this);
      btnEnq.addActionListener(this);
      btnCont.addActionListener(this);
      btnLoog.addActionListener(this);
      btn13.addActionListener(this);
      btnsign.addActionListener(this);
      btncan.addActionListener(this);
      btnsub.addActionListener(this);
      btnback.addActionListener(this);
      btnbook.addActionListener(this);
      btn14.addActionListener(this);
      btn12.addActionListener(this);
      btnb1.addActionListener(this);
      btnb2.addActionListener(this);
      btncancell.addActionListener(this);
      btng2.addActionListener(this);
      btnc2.addActionListener(this);
     frame1.getRootPane().setDefaultButton(btn1);
     frame4.getRootPane().setDefaultButton(btn12);
}

/*
public class myListener implements ActionListener
{
//combo box listener
public void itemStateChanged(ItemEvent ie)
{
        if(ie.getSource()==cbo1)
  {
         try
    {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection conn=DriverManager.getConnection("Jdbc:Odbc:Time_Table");
     String s = (String)cbo1.getSelectedItem();
  int no = Convert.ToInt32(s);   
    String t1="select Train_No, Train_Name, Fare from dbo.Time_Table where Train_No = "+no;

                   Statement s=conn.createStatement();
                   ResultSet rs=s.executeQuery(t1);  
                   String t_no, t_name, t_fare;
                   while(rs.next())
    {
    t_no=rs.getString(1);

                   t_name=rs.getString(2);

                   t_fare=rs.getString(3);                  
    }        
      cbo1.setSelectedItem(t_no);
      cbo2.setSelectedItem(t_name);
      cbo3.setSelectedItem(t_fare);
      cbo4.setSelectedItem(t_class);
      s.close();
     conn.close();
   }
   catch(Exception ex)
   {
     System.out.println("Error: "+ex.toString());
   }

  }    //if

 } //method

}
*/
      public void actionPerformed(ActionEvent e)
       /* matching the value */
{
    String value1 = txt1.getText();
    String value2 = txt2.getText();
    String c1,c2;
      /* Button2 for exit */
      if(e.getSource()==btn2)
{
    System.exit(0);
}
     /* For Login Button */
if(e.getSource()==btn1)
{

if(txt1.getText().length()==0)
{
     JOptionPane.showMessageDialog(null, "Enter Your UserName");
return;
}
   else if(txt2.getText().length()==0)
{
     JOptionPane.showMessageDialog(null, "Enter Your Password");
return;
}

try
{  
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("Jdbc:Odbc:rail");
String q="select * from signup where Email_ID like '"+value1+"'";
Statement s=conn.createStatement();
ResultSet rs=s.executeQuery(q);

while(rs.next())
{

c1=rs.getString(4);
c2=rs.getString(5);
System.out.println("-----------------------");
System.out.println("Username: "+c1);
System.out.println("Password: "+c2);
System.out.println("-----------------------");

if (c2.equals(value2))
{
   System.out.println("Logged In");
    frame2.setVisible(true);
    frame2.setSize(1044, 620);
    frame2.setTitle("Happy Journey");
    frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame1.setVisible(false);
}
else
{ 
JOptionPane.showMessageDialog(null, "User and password doesnt match");
}
}

rs.close();
s.close();
conn.close();
}
catch(Exception ex)
{
System.out.println("Error: "+ex.toString());
}
}  

/* Displaying Reservation Page */
   if(e.getSource()==btnRes)
{
    frame3.setSize(1044, 620);
    frame3.setVisible(true);
    frame3.setTitle("Indian Railway");
    frame1.setVisible(false);
    String t1;
    String a1[]={"","","","",""};
                   String a2[]={"","","","",};
                   String a3[]={"","","","",};
                   String a4[ ]={"","",""};
    int count=11;

    try
{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection conn=DriverManager.getConnection("Jdbc:Odbc:Time_Table");
      t1="select count(Train_No) from Time_Table";
      Statement s1=conn.createStatement();
                     ResultSet rs1=s1.executeQuery(t1);
      if(rs1.next())
      {
      count = rs1.getInt(1);  
      }


                   t1="select * from Time_Table";


                   Statement s=conn.createStatement();
                   ResultSet rs=s.executeQuery(t1);  
                   int i=0;

         a1 = new String[count];
         a2 = new String[count];
         a3 = new String[count];
                                       a4 = new String[count];
      while(rs.next())
    {
    t1=rs.getString(1);
    a1[i]=t1;
                   t1=rs.getString(2);
                   a2[i]=t1;
                   t1=rs.getString(9);
                   a3[i]=t1;
                   t1 = rs.getString(8);
                   a4[i]=t1;
    i++;
    }

     s1.close();

      s.close();
     conn.close();
}
catch(Exception ex)
{
System.out.println("Error: "+ex.toString());
}
cbo1 = new JComboBox (a1);

       cbo1.setBounds(256, 157,184, 20);
        frame3.add(cbo1);

cbo2 = new JComboBox (a2);
                       cbo2.setBounds(638, 157,184, 20);
                        frame3.add(cbo2);

cbo3 = new JComboBox (a3);
                       cbo3.setBounds(256, 505,184, 20);
                        frame3.add(cbo3);
cbo4 = new JComboBox (a4);
                        frame3.add(cbo4);
                        cbo4.setBounds(638, 203,184, 20);
}
   /* Displaying Enquiry Page */
   if(e.getSource()==btnEnq)
{
    frame4.setSize(1080,720);
    frame4.setVisible(true);
    frame4.setTitle("Get Your Query");
}
     /*   Displaying Contact   */
   if(e.getSource()==btnCont)
{
   JOptionPane.showMessageDialog
(frame2,"If any problem please contact us\n this number 8291191313\n& Email ID: sarfaraz3d@gmail.com");
}
   /* Logout Button All The Page may Clear */
   if(e.getSource()==btnLoog)
{
    frame1.setVisible(true);
    txt1.setText("");
    txt2.setText("");
    frame2.dispose();
    frame3.dispose();
    frame4.dispose();
}
    /* retrive from database all information */
    if(e.getSource()==btn12)
{
   if(txt12.getText().length()==0)
{
    JOptionPane.showMessageDialog(null,"Please Enter the Train number");
}
{
try
{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection conn=DriverManager.getConnection("Jdbc:Odbc:Time_Table");
      String qu="select * from Time_Table where Train_No = "+txt12.getText();
      Statement s=conn.createStatement();
      ResultSet rs=s.executeQuery(qu);   
      while(rs.next())
 {
    qu = "" + rs.getInt(1);
    txttn.setText(qu);
    txttname.setText(rs.getString(2));
    txtdt.setText(rs.getString(3)); 
    txtat.setText(rs.getString(4));
    txtss.setText(rs.getString(5));
    txtds.setText(rs.getString(6));
    txtrd.setText(rs.getString(7));
    txtc.setText(rs.getString(8));
    txtf.setText(rs.getString(9));
    txtd.setText(rs.getString(10));
     txt12.setText("");
    frame7.setVisible(true);
    frame7.setSize(1080,720);
JOptionPane.showMessageDialog(null,"Your Train Details are.......");

}
     s.close();
     conn.close();
}
catch(Exception ex)
{
System.out.println("Error: "+ex.toString());
}
}
}
   if(e.getSource()==btnb1)
{
    frame7.dispose();
}
   if(e.getSource()==btnb2)
{
    frame7.dispose();
    frame3.setVisible(true);
    frame3.setSize(1080,720);
}
   if(e.getSource()==btn13)
{
   frame4.dispose(); 
}
    if(e.getSource()==btn14)
{
     frame6.setVisible(true);
    frame6.setSize(1080,720);
}
  if(e.getSource()==btnsign)
{
   frame5.setVisible(true);
   frame5.setSize(1044, 620);
   frame1.setVisible(false);
}
  if(e.getSource()==btncan)
{
    txtfname.setText("");
    txtlname.setText("");
    txtemail.setText("");
    txtpwrd.setText("");
    txtdob.setText("");
    txtphone.setText("");
    frame1.setVisible(true);
}
    /* For Submitting sign up page*/

     if(e.getSource()==btnsub)
{
try
{
     if (ma1.isSelected())
{
      gender = "Male";
}
else
{
      gender = "Female";
}

if(cbo1.getSelectedItem().equals("") | txtlname.getText().equals("") | txtemail.getText().equals("")| txtpwrd.getText().equals("")|txtdob.getText().equals("")|txtphone.getText().equals(""))
{
    JOptionPane.showMessageDialog(null, "Error entering data - All fields must be filled.");
    return;
}

String u1="",u2,dis="";
try
{  
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("Jdbc:Odbc:rail");
String q1="select * from signup where User_ID = (select max(User_ID) from signup)";
String q="insert into signup values ('"+txtfname.getText()+"','"+txtlname.getText()+"','"+txtemail.getText()+"','"+txtpwrd.getText()+"','"+gender+"','"+txtdob.getText()+"',"+txtphone.getText()+")";
Statement s=conn.createStatement();
s.executeUpdate(q);
ResultSet rs=s.executeQuery(q1);

while(rs.next())
{
System.out.println("-----------------------");
u1=rs.getString(4);
System.out.println(u1);
u2=rs.getString(5);
System.out.println(u2);
System.out.println("-----------------------");
}
dis = "Successfully Regestered your account\n your password will be provided within 2 hour on " +u1+ "\n thank you for registration";

rs.close();
s.close();
conn.close();
}
catch(Exception e1)
{
System.out.println("Error: "+e1.toString());
}

JOptionPane.showMessageDialog(frame5,dis);
}
 catch(Exception ex)
{
System.out.println(ex);
}
}
   if(e.getSource()==   btnback)
{
    frame3.dispose();
}

     /* For Ticket booking */
     if(e.getSource()==btnbook)
{
try
{
     if(txttrainno.getText().equals("") | txttrainname.getText().equals("") | txtDOJ.getText().equals("")| txtclass.getText().equals("")|txtSf.getText().equals("")|txtSt.getText().equals("")|txtbord.getText().equals("")|txtresvupto.getText().equals("")|txtnameblock.getText().equals("")|txtgen.getText().equals("")|txtage.getText().equals("")|txtmobile.getText().equals("")|txtem.getText().equals("")|txtdat.getText().equals("")|txtac.getText().equals(""))
{
    JOptionPane.showMessageDialog(null, "Error entering data - All fields must be filled.");
}

   if(txttrainname.getText().length()==0)
{
     JOptionPane.showMessageDialog(null,"Please Enter your Train Name");
    return;
}
     else if(txtDOJ.getText().length()==0)
{

     JOptionPane.showMessageDialog(null,"Please Enter your Date Of Journey");
    return;
}
      else if(txtclass.getText().length()==0)
{
   JOptionPane.showMessageDialog(null,"Please Enter your Class");    
    return;
}
    else if(txtSf.getText().length()==0)
{
     JOptionPane.showMessageDialog(null,"Please Enter your Station From");  
    return;
}
     else if(txtSt.getText().length()==0)
{
      JOptionPane.showMessageDialog(null,"Please Enter your Station To");  
    return;
}
    else if(txtbord.getText().length()==0)
{
    JOptionPane.showMessageDialog(null,"Please Enter your Boarding at");
    return;
}
   else if(txtresvupto.getText().length()==0)
{
     JOptionPane.showMessageDialog(null,"Please Enter Your Reservation Upto");
      return;
}
   else if(txtnameblock.getText().length()==0)
{
    JOptionPane.showMessageDialog(null,"Please Enter Your Name");
     return;
}
     else if(txtgen.getText().length()==0)
{
      JOptionPane.showMessageDialog(null,"Please Enter Your Gender");
       return;
}   
     else if(txtage.getText().length()==0)
{
     JOptionPane.showMessageDialog(null,"Please Enter Your Age");
       return;
}
     else if(txtmobile.getText().length()==9)
{
     JOptionPane.showMessageDialog(null,"Please Enter Your Mobile Number");  
      return;
}
    else if(txtem.getText().length()==0) 
{
     JOptionPane.showMessageDialog(null,"Please Enter Your Email ID"); 
      return;
}
    else if(txtdat.getText().length()==0) 
{
      JOptionPane.showMessageDialog(null,"Please Enter Your Current Date"); 
}
     else if(txtac.getText().length()==0) 
{
       JOptionPane.showMessageDialog(null,"Please Enter Your Tickets Fare"); 
         return;
}
   String u1="",dis="";
   try
{  
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("Jdbc:Odbc:reservation");
String q1="select * from Reservation where PNR_No = (select max(PNR_No) from Reservation)";
/*int fare;
fare = txtFare.getselecteditemt();
if (txt1.getText() == "First")
{
  fare = fare + 1200;
}*/
String q="insert into Reservation(Train_No,Train_Name,Date_Of_Journey,Class,Station_From,Station_To,Boarding_at,Reservation_Upto,Name_In_Block_Letter,Gender,Age,Mobile_No,Email_ID,Date,Amount_Collected) values ('"+cbo1.getSelectedItem()+"','"+cbo2.getSelectedItem()+"','"+txtDOJ.getText()+"','"+txtclass.getText()+"','"+txtSf.getText()+"','"+txtSt.getText()+"','"+txtbord.getText()+"','"+txtresvupto.getText()+"','"+txtnameblock.getText()+"','"+txtgen.getText()+"','"+txtage.getText()+"','"+txtmobile.getText()+"','"+txtem.getText()+"','"+txtdat.getText()+"',"+txtac.getText()+")";
Statement s=conn.createStatement();
s.executeUpdate(q);
ResultSet rs=s.executeQuery(q1);   
while(rs.next())
{
System.out.println("-----------------------");
u1=rs.getString(15);
System.out.println(u1);
System.out.println("-----------------------");
}

dis = "Successfully Reservation is done.... your  Pnr No is " +u1+ "\n Thank you for visting to ur railway site";

rs.close();
s.close();
conn.close();
}
catch(Exception f1)
{
System.out.println("Error: "+f1.toString());
}
JOptionPane.showMessageDialog(frame3,dis);
txttrainno.setText("");
txttrainname.setText("");
txtDOJ.setText("");
txtclass.setText("");
txtSf.setText("");
txtSt.setText("");
txtbord.setText("");
txtresvupto.setText("");
txtnameblock.setText("");
txtgen.setText("");
txtage.setText("");
txtmobile.setText("");
txtmobile.setText("");
txtac.setText("");
txtem.setText("");
txtdat.setText("");
}
 catch(Exception ex)
{
System.out.println(ex);
}
}
   if(e.getSource()==btncancell)
{
     frame8.setVisible(true);
     frame8.setSize(1080,720);
}

if(e.getSource()==btng2)
{

try
{  
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("Jdbc:Odbc:reservation");
String q="delete from Reservation where PNR_No = "+txtp.getText();
Statement s=conn.createStatement();
s.executeUpdate(q);
s.close();
conn.close();
}
catch(Exception ex)
{
System.out.println("Error: "+ex.toString());
JOptionPane.showMessageDialog(frame8,"Successfully cancel the tickets");
}
}
   if(e.getSource()==btnc2)
{
      frame8.dispose();
}


}

     public static void main(String args[])
{
   Railway rail = new Railway();
   rail.reservation();
}
}

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Railway reservation
Railway reservation  Railway Department wants to automate the ticket reservation process. Customer should be able to check the availability of a train by giving the source and destination. Assume that there is no booking
railway reservation
railway reservation  hello sir, i am creating railway reservation... = new JLabel(fff); lblheading = new JLabel("Railway Reservation Requisition... java.lang.*; class Railway implements ActionListener { Font fn1, fn2
Advertisements
railway reservation
railway reservation  hello sir, i am creating railway reservation... = new JLabel(fff); lblheading = new JLabel("Railway Reservation Requisition... java.lang.*; class Railway implements ActionListener { Font fn1, fn2
Railway Reservation
Railway Reservation  i've a project on railway reservation... i need to connect netbeans and mysql with the help of jdbc driver... then i need to design the frame... aftr clickg run i need to enter data to ma frame and the data
coding for railway reservation project
coding for railway reservation project  i want to help for creating coding in visual basic for railway reservation project
railway reservation system - Java Beginners
railway reservation system  help me develop a code on a railway reservation system which maintains records of passengers traveling in the different..., the reservation of the passengers is made by supplying the train number or the the name
how to prepare railway reservation form using core java concepts
how to prepare railway reservation form using core java concepts  write code for online railway reservation form: The following constraints are: a) Fix the no.of Tickets alloted for online reservation b) on each ticket booking
railway rsrvation system
railway rsrvation system   Java coding for railway reservation system
reservation system - Java Beginners
reservation system  hi help me write a program on a railway reservation system that records the destination of the passengers.It should be decided by the date on which they are to arrive on their destinations and also the number
coding for online reservation
coding for online reservation  coding for online reservation
online bus reservation
online bus reservation   online bus reservation using jsp coding
airline reservation - Java Beginners
airline reservation example  (Airline Reservation System) A small airline has just purchases a computer for its new automated reservations system...). Please give an example of reservation
place reservation in plane
place reservation in plane   hi,how can i write a program in Java programming to place reservation in air plane from the menu let the user to inter his/her name, age, date of traveling, and the seat in the plane
reservation of seat in plane
reservation of seat in plane  hi,how can i write a program in Java programming to place reservation in air plane from the menu let the user to inter his/her name, age, date of traveling, and the seat in the plane
History about National Railway Museum Delhi
History about National Railway Museum Delhi Established on the 1st February, 1977, the National Railway Museum of New Delhi is located in the heart... of the railways in India. The National Railway Museum exhibits many models of steam engines
airline reservation java code - Java Beginners
airline reservation java code   Write a program that simulates the booking of seats on board a small airplane. The layout of the aircraft is illustrated below. You will be required to create a menu based system
project
project  sir i want to a project on railway reservation,sir plz give me the source code   plz give me the source code of railway reservation
Servlets - JSP-Servlet
Servlets  i have to create a database in SQL server 2005 on railway reservation system.please help me do
java - Java Beginners
java  how to get the details railway reservation details and passengers reserved for a particular train using java
What is CICS?
, colleges and universities, airline reservation systems, insurance companies
want a project
want a project  i want to make project in java on railway reservation using applets and servlets and ms access as database..please provide me code and how i can compile and run
project
project  sir i want a java major project in railway reservation plz help me and give a project source code with entire validation thank you
Java - JSP-Servlet
Java  hi i m biginner in java programming language.please help me.my question is- i have to create a project on Railway reservation system in servlets and jsp.please design the structure of the project in details with coding
hi
hi  sir i've a project on railway reservation... i need to connect netbeans and mysql with the help of jdbc driver... then i need to design the frame... aftr clickg run i need to enter data to ma frame and the data which i enter
hi
hi  sir i've a project on railway reservation... i need to connect netbeans and mysql with the help of jdbc driver... then i need to design the frame... aftr clickg run i need to enter data to ma frame and the data which i enter
Web services using eclipse helios and apache tomcat-7
things that i need. I have made a form for railway reservation and for that i
Testcases - JUNIT
Testcases   Hi iam doiing project on online reservation i want to know how to write the testcases for this online reservation..........will u help me
test case - JUNIT
test case  Hi i am doing project on online reservation i want to know how to write the test case template for this online reservation
jsp coding
jsp coding  what is the simple jsp code for bus ticket reservation system
hi.......
hi.......  i've a project on railway reservation... i need to connect netbeans and mysql with the help of jdbc driver... then i need to design the frame... aftr clickg run i need to enter data to ma frame and the data which i
 

 

 

DMCA.com