Académique Documents
Professionnel Documents
Culture Documents
*;
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,lday
1,lfare1,ldis1,limg1,limg2,limg3,limg4,limg5,limg6,limg7,limg8,limg9,limg10
,lbltn,lbltname,lbldt,lblat,lblss,lblds,lblrd,lblc,lblf,lbld,lblh,lblh3,lbl
p;
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);
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());
}
}
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);
}
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);
}
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.get
Text()+")";
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();
}
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();
}