Professional Documents
Culture Documents
Train Booking SYSTEM
Train Booking SYSTEM
ABSTRACT
Summary :
2
Train Booking System is a project which aims in developing a computerized system to maintain all
the work of Train Travelling. This project has many features which are generally not availiable in
normal Train Booking Systems like facility of user login and a facility of Signup and changing
password.
This project have various types of facilities panel to manage Train travelling related operation. This
project having various kinds of panel like Login, Signup, Book Ticket, Add Passenger information,
Train, Passenger information panel, create new registration of Passenger and view Passenger
information Train wise, Date wise, Passenger name wise etc. This project provide very simple
mode to update information and delete records of Passenger where passenger can cancel the ticket.
Here we have very information panel where we can views entire passenger and Train related
information.
This project have Change password facility to change old password if password is not secure.
Overall view it is completely very good project for Managinig Train Depot, Ticket, view Passenger
related information of Train.
TABLE OF CONTENTS
Page
ACKNOWLEDGEMENTS .................................................................................................... 3
ABSTRACT ............................................................................................................................ 4
1. INTRODUCTION.................................................................................................. 6
2. (Statement of Problem) ………………………………………………………….. 7
3. Proposed Solutions ………………………………………………………………. 8
3
4. Database Layer …...................................................................................... 10-13
4.1 E-R Diagram /DFD .................................................................... 10
4.2 Table …………………………………………………………. 11-13
5. External Interface…………………………………………………………. 14
5.1 Hardware Interface …………………………………………….. 14
5.2 Software Interface ……………………………………………… 15
6. Process Logic Layer ………………………………………………………. 16
6.1 Input Specification ………………………………………………. 17
6.2 Output Specification………………………………………………. 18
6.3 Coding …………………………………………………………….. 20
6.3.1. Login input and coding.................................................. 20 – 28
6.3.2 Signup input and coding ................................................ 29 – 41
6.3.3 Home Deskpanel and coding.......................................... 42-57
6.3.4 Traindisplay form and coding …...................................... 58-77
6.3.5. Trainticket information panel and coding……………… 78-89
6.3.6 Travel details panel and coding………….……………. 90-108
6.3.7 Payment form and……………………………………. 110-127
6.3.8 Trasaction no. and Ticket No. form and code……....... 128-134
8.3.9. Display passenger information panel and code.……... 135-147
8.3.10 Add Train Panel and coding…………………………… 148-160
7. Book Ticket (Working Process of Project) ……………………………… 161-166
8. Future Scope ……………………………………………………………. 167
9. References ………………………………………………………………. 168 -169
Chepter 1 – INTRODUCTION
This chapter gives an overview about the aim , objectives ,background and operation environment
of the system.
Traines are the most frequently available and most used vehicle for going from small distance trip
to very long trip. They’re a no. of types of Traines available in the market according to the private
or public.
According to ac or no ac. Apart from this interstate, shrine or inter country also possible. What the
problem here arises about the ticket is everyone has to take a card and want seats.
5
But it’s not possible. The Traines which will register on our system will have the option to give
their customers an option to select the seats of the Train according to their wish as many places
depending on the availability.
Making the system more useful unique tickets will be generated as its seats confirmed. Here we are
with a system which can facilitate the users to which they can get their seats prior.
As staff will decide the seat availability and here we have other users like the staff of the Train and
driver with the owner who together collaborates in smooth functioning of the Train ticket booking
system.
The module of the Train Booking System is made of the combination of modules which work with
collaboration with each other and make it beneficial to accomplish the main aim of the scheme.
Ticket Booking:
This module of the project is for the users who want to book the tickets for the journey they want to
do at the time of their desire.
6
They fill the details accordingly like time of travel no. Of people they want to go they select the
seats which are available for the booking as the seats which are booked already will be blocked
their and remaining seats are available.
They get a digital ticket, and they can board the Train at the time given.
Payment:
They may make payment online through their debit card they use this module to pay as the ticket
shows the amount in the account of the owner of the Train.As he makes the payment, the card
becomes confirmed and ready to be used.
Ticket Checking :
The verification of the cards is done by the conductor of the Train, he comes to the user and asks for
a ticket no. As they take it, he checks and confirms their booking and let them ride.
Registration:
Users information have to be compelled to be registered within the system thus on establish every
of them unambiguously and do the required group acts as the real potential. Like on the name of the
bill are issued.
On the far side, this plenty of things require measure there wherever we will reference him. Without
registration, there are few options and pages one user can see which are landing on the home page
and taking the features read but he won’t be allowed to use those.
For use, he will have to register. One person needs to put his all the details correctly and precisely
as it will be helpful in identifying them and believing that he is the real person who has booked for
the same.
It also includes driver license for them who is driving and parameter too.
Log in:
After registration one will register within the system because of the operator of the system either on
behalf of the user. When this he has the different helpful interfaces accessible for any actions.
Here either bride or groom both have to log in with their unique identity and passwords. After this,
they will be directed to the primary user interface from where they have further options.
Change password:
This is quite often that people tend to change the password they keep for the login. So this could be
very tedious and hectic to change the password manually.
So to overcome this problem we have this module named as change a password and using this
module user can change their password in seconds.
Admin:
Admin has the official powers to control the flow of the data from one part of the system to the
other. He can manipulate the access of the users to the data.
The primary purpose of this account is to make the user data relevant and then giving the inputs to
the other interface module and make it work optimistically and get the time table according to the
wish we want to create for a particular type of inputs.
Hence all the data will be reflected in clean and well data in the interfaces.
7
You can also check Train Booking System.
Trainsignup
amount
username address
8
Trainpayment
Password1 dob
Password2 lastname
transid cvv
4.2 DataBase and Tables
9
Tables Design
Train Table
10
Trainsignup Table
Traintraveller Table
11
Chepter 5 – External Interface
12
5.1 Hardware Interface
HARDWARE REQUIREMENTS
Intel dual core 2nd generation is used as a processor because it is fast than other processors an
provide reliable and stable and we can run our pc for longtime. By using this processor we can keep
on developing our project without any worries.
Ram 1 gb is used as it will provide fast reading and writing capabilities and will in turn support in
processing
13
Operating System Window Xp / 7 / 8 / 10
SOFTWARE REQUIREMENTS
Operating system- Windows 7 is used as the operating system as it is stable and supports more
features and is more user friendly
Database MYSQL- MYSQL is used as database as it easy to maintain and retrieve records by
simple queries which are in English language which are easy to understand and easy to write.
Development tools and Programming language- JAVA Programming is used to write the whole
code and develop Train Booking System with MySql.
Login Process
14
Enter Username
Singup Home
password
(Create new account) (Dashboard)
(Login Panel)
(trdb DataBase)
Booking
Train Ticket
Done
Infromation
trdb DataBase
Traditional specifications are ‘input specifications’. They are prescriptive, that is, they describe
in detail the products, materials and work (the inputs) required by a contract. Typically,
thedevelopment of the solution required by the contract is complete and no (or little) further
development is required by the supplier. The specification is considered to be a ‘closed
specification’.
Prescriptive input specifications give the client certainty about the end product when
makinginvestment decisions, but place a greater burden on them to ensure the product has been
thoroughly considered, developed and described. They tend to be used where a very specific end
result required.
16
Output specifications define only the outcomes (or outputs) that are required by the contract, that is,
what it will enable the client to do. They are open specifications that do not attempt to address how
those outputs might be achieved. The standard for what is required might be defined,
18
import java.awt.Color;
import java.awt.Frame;
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JoptionPane;
public Login()
{
initComponents();
this.setLocationRelativeTo(null);
try
{
Class.forName(“java.sql.Driver”);
con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/trdb” , “root” , “root”);
}
19
catch(ClassNotFoundException | SQLException ex1)
{ }
@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(255, 255, 255));
setUndecorated(true);
jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/Copy of
Transpo_XcelsiorChargeCharging_TA.jpg”))); // NOI18N
23
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 568,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
Short.MAX_VALUE)))
);
pack();
}// </editor-fold>
user1.setText(“”);
pass1.setText(“”);
}
int d = 0;
while(rs.next())
{
u1 = rs.getString(“username”);
p1 = rs.getString(“password”);
if(u1.equals(userinput))
{
if(p1.equals(passinput))
{
JoptionPane.showMessageDialog(this, “Login Successfully Done “);
d = 1;
break;
}
}
}
if(d == 0)
{
JoptionPane.showMessageDialog(this, “Account Not Found…”);
user1.setText(“”);
pass1.setText(“”);
25
}
System.exit(0);
}
this.setState(Login.ICONIFIED);
}
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“NimTrain”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
26
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
27
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import javax.swing.JoptionPane;
Connection con;
Statement st;
public signup()
{
initComponents();
this.setLocationRelativeTo(null);
try
{
Class.forName(“java.sql.Driver”);
con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/trdb” , “root” , “root”);
}
@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
30
.addComponent(mini, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
34
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(dob1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.BASELINE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 39,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 39,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jLabel10))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jLabel4)
.addComponent(d1))
.addGap(12, 12, 12))
);
pack();
}// </editor-fold>
fname1.setText(“”);
lname1.setText(“”);
username1.setText(“”);
password1.setText(“”);
password2.setText(“”);
dob1.setText(“”);
address1.setText(“”);
n1 = fname1.getText();
n2 = lname1.getText();
u1 = username1.getText();
36
p1 = password1.getText();
p2 = password2.getText();
dob = dob1.getText();
add1 = address1.getText();
else
if(p1.equals(p2))
{
String qur = “insert into Trainsignup values (‘”+n1+”’ , ‘”+n2+”’ , ‘”+u1+”’ , ‘”+p1+”’ ,
‘”+p2+”’ , ‘”+dob+”’ , ‘”+add1+”’) “ ;
try
{
st = con.createStatement();
st.execute(qur);
JoptionPane.showMessageDialog(this, “Registration Successfully Done … “);
}
catch(HeadlessException | SQLException ex2)
{
}
fname1.setText(“”);
lname1.setText(“”);
username1.setText(“”);
password1.setText(“”);
password2.setText(“”);
dob1.setText(“”);
address1.setText(“”);
}
else
{
JoptionPane.showMessageDialog(this, “Missmatch Password…”);
password1.setText(“”);
password2.setText(“”);
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the NimTrain look and feel */
//<editor-fold defaultstate=”collapsed” desc=” Look and feel setting code (optional) “>
/* If NimTrain (introduced in Java SE 6) is not available, stay with the default look and feel.
37
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“NimTrain”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(signup.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(signup.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(signup.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(signup.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
try
{
new signup().setVisible(true);
}
catch(Exception e1)
{
}
}
});
}
39
40
6.3.3 – Home Panel
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JoptionPane;
/**
* Creates new form Home
*/
public Home() {
initComponents();
this.setLocationRelativeTo(null);
one.setSelected(true);
return1.setEnabled(false);
from2.setEnabled(false);
to2.setEnabled(false);
from1.removeAllItems();
from1.addItem(“KOTA”);
from1.addItem(“HANUMANGARH”);
from1.addItem(“JAIPUR”);
41
from1.addItem(“AJMER”);
from1.addItem(“ALWAR”);
to1.removeAllItems();
to1.addItem(“KOTA”);
to1.addItem(“HANUMANGARH”);
to1.addItem(“JAIPUR”);
to1.addItem(“AJMER”);
to1.addItem(“ALWAR”);
travel1.removeAllItems();
travel1.addItem(“AC CLASS”);
travel1.addItem(“NON-AC CLASS”);
travel1.addItem(“AC-SLEEPER CLASS”);
travel1.addItem(“NON-AC SLEEPER CLASS”);
}
@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
private void initComponents() {
jMenu1.setText(“jMenu1”);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
setResizable(false);
jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/Train2.jpg”))); //
NOI18N
buttonGroup1.add(multi);
multi.setFont(new java.awt.Font(“Calibri”, 1, 18)); // NOI18N
multi.setText(“MULTI CITY”);
multi.setOpaque(false);
multi.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
multiMouseClicked(evt);
}
});
multi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
multiActionPerformed(evt);
}
});
buttonGroup1.add(one);
one.setFont(new java.awt.Font(“Calibri”, 1, 18)); // NOI18N
one.setText(“ONEWAY”);
one.setOpaque(false);
one.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oneActionPerformed(evt);
}
});
buttonGroup1.add(round);
round.setFont(new java.awt.Font(“Calibri”, 1, 18)); // NOI18N
round.setText(“ROUND TRIP”);
round.setOpaque(false);
round.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
roundActionPerformed(evt);
43
}
});
44
travel1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “Item 1”, “Item
2”, “Item 3”, “Item 4” }));
45
.addComponent(dep1, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.PREFERRED_SIZE, 186,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(paneoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING)
.addGroup(paneoneLayout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATE
D)
.addGroup(paneoneLayout.createParallelGroup(javax.swing.GroupLayout.Al
ignment.LEADING)
.addComponent(return1, javax.swing.GroupLayout.PREFERRED_SIZE,
182, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(to1, javax.swing.GroupLayout.PREFERRED_SIZE, 186,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(jLabel9)))
.addGroup(paneoneLayout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(jLabel6))))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
paneoneLayout.setVerticalGroup(
paneoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(paneoneLayout.createSequentialGroup()
.addGap(29, 29, 29)
.addGroup(paneoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jLabel3)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(paneoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(from1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(to1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(paneoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jLabel9)
.addComponent(jLabel10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(paneoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(from2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(to2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
46
.addGroup(paneoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addComponent(jLabel6)
.addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(paneoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(dep1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(return1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(travel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61,
Short.MAX_VALUE)
.addComponent(jButton1))
);
pack();
}// </editor-fold>
if(from1.getSelectedItem().equals(to1.getSelectedItem()))
{
JoptionPane.showMessageDialog(this, “Same City ! Plese Select Right Cities “);
}
else
{
String f1, t1, f2=””, t2=””, ddate, rdate=””, tclass;
int opt = 0;
if(one.isSelected())
{
opt = 1;
f1 = (String) from1.getSelectedItem();
t1 = (String) to1.getSelectedItem();
Date dvalue = dep1.getDate();
tclass =(String) travel1.getSelectedItem();
else
52
if(round.isSelected())
{
if(return1.getEditor().getText().equals(“”) || return1.getDate().before(date1))
JoptionPane.showMessageDialog(this, “Please Select Return Date”);
else
JoptionPane.showMessageDialog(this, “Sorry ! Round Trip is not available”);
}
else
if(multi.isSelected())
{
if(from2.getSelectedItem().equals(to2.getSelectedItem()))
JoptionPane.showMessageDialog(this, “Same City ! Please select Right Cities “);
else
if(return1.getEditor().getText().equals(“”) || return1.getDate().before(date1))
JoptionPane.showMessageDialog(this, “Please Select Return Date”);
else
JoptionPane.showMessageDialog(this, “Sorry ! Multicity is not available”);
}
}
logout.setEnabled(false);
JoptionPane.showMessageDialog(this, “Thanks to visit…”);
53
private void multiMouseClicked(java.awt.event.MouseEvent evt)
{
from2.removeAllItems();
from2.addItem(“KOTA”);
from2.addItem(“HANUMANGARH”);
from2.addItem(“JAIPUR”);
from2.addItem(“AJMER”);
from2.addItem(“ALWAR”);
to2.removeAllItems();
to2.addItem(“KOTA”);
to2.addItem(“HANUMANGARH”);
to2.addItem(“JAIPUR”);
to2.addItem(“AJMER”);
to2.addItem(“ALWAR”);
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
56
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JoptionPane;
import javax.swing.table.DefaultTableModel;
Connection con;
Statement st;
public TrainDisplay() {
initComponents();
this.setLocationRelativeTo(null);
ticket.setEnabled(false);
57
d1.setText(“Today :” + d2);
one.setSelected(true);
return1.setEnabled(false);
from2.setEnabled(false);
to2.setEnabled(false);
from1.removeAllItems();
from1.addItem(“KOTA”);
from1.addItem(“HANUMANGARH”);
from1.addItem(“JAIPUR”);
from1.addItem(“AJMER”);
from1.addItem(“ALWAR”);
to1.removeAllItems();
to1.addItem(“KOTA”);
to1.addItem(“HANUMANGARH”);
to1.addItem(“JAIPUR”);
to1.addItem(“AJMER”);
to1.addItem(“ALWAR”);
travel1.removeAllItems();
travel1.addItem(“AC CLASS”);
travel1.addItem(“NON-AC CLASS”);
travel1.addItem(“AC-SLEEPER CLASS”);
travel1.addItem(“NON-AC SLEEPER CLASS”);
public TrainDisplay(int opt, String f1, String t1, String f2, String t2, Date ddate, String rdate,
String tclass)
{
initComponents();
this.setLocationRelativeTo(null);
ticket.setEnabled(false);
from1.removeAllItems();
from1.addItem(“KOTA”);
from1.addItem(“HANUMANGARH”);
from1.addItem(“JAIPUR”);
from1.addItem(“AJMER”);
from1.addItem(“ALWAR”);
from1.setSelectedItem(f1);
58
to1.removeAllItems();
to1.addItem(“KOTA”);
to1.addItem(“HANUMANGARH”);
to1.addItem(“JAIPUR”);
to1.addItem(“AJMER”);
to1.addItem(“ALWAR”);
to1.setSelectedItem(t1);
travel1.removeAllItems();
travel1.addItem(“AC CLASS”);
travel1.addItem(“NON-AC CLASS”);
travel1.addItem(“AC-SLEEPER CLASS”);
travel1.addItem(“NON-AC SLEEPER CLASS”);
travel1.setSelectedItem(tclass);
dep1.setDate(ddate);
if(opt == 1)
{
one.setSelected(true);
return1.setEnabled(false);
from2.setEnabled(false);
to2.setEnabled(false);
try
{
Class.forName(“java.sql.Driver”);
con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/trdb” , “root” , “root”);
st = con.createStatement();
while(rs.next())
{
String fno = rs.getString(“Train”);
String dep = rs.getString(“departure”);
String arv = rs.getString(“arrival”);
String dtime = rs.getString(“deptime”);
String atime = rs.getString(“artime”);
String p = rs.getString(“price”);
int price = 0;
price = Integer.parseInt(p);
if(tclass.equals(“AC CLASS”))
{
59
price = price + 75;
}
else
if(tclass.equals(“AC-SLEEPER CLASS”))
{
price = price + 150;
}
else
if(tclass.equals(“NON-AC SLEEPER CLASS”))
{
price = price + 75;
}
else
{
price = Integer.parseInt(p);
}
p = “” + price;
}
@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
private void initComponents() {
jMenu1.setText(“jMenu1”);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
setResizable(false);
62
.addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 16,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel11)
.addGap(22, 22, 22))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jLabel14)
.addComponent(jLabel12)
.addComponent(jLabel11))
.addGap(0, 0, Short.MAX_VALUE))
);
buttonGroup1.add(multi);
multi.setFont(new java.awt.Font(“Calibri”, 1, 18)); // NOI18N
multi.setText(“MULTI CITY”);
multi.setOpaque(false);
multi.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
multiMouseClicked(evt);
}
});
multi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
multiActionPerformed(evt);
}
});
buttonGroup1.add(one);
one.setFont(new java.awt.Font(“Calibri”, 1, 18)); // NOI18N
one.setText(“ONEWAY”);
one.setOpaque(false);
one.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oneActionPerformed(evt);
}
});
buttonGroup1.add(round);
round.setFont(new java.awt.Font(“Calibri”, 1, 18)); // NOI18N
round.setText(“ROUND TRIP”);
round.setOpaque(false);
round.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
63
roundActionPerformed(evt);
}
});
},
new String [] {
67
“TRAIN NUMBER”, “DEPARTURE”, “ARRIVAL”, “DEPARTURE TIME”,
“ARRIVAL TIME”, “PRICE”
}
));
tb1.setRowHeight(70);
tb1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tb1MouseClicked(evt);
}
});
jScrollPane3.setViewportView(tb1);
pack();
}// </editor-fold>
System.exit(0);
}
this.setState(Home.ICONIFIED);
}
from2.removeAllItems();
from2.addItem(“KOTA”);
from2.addItem(“HANUMANGARH”);
from2.addItem(“JAIPUR”);
from2.addItem(“AJMER”);
from2.addItem(“ALWAR”);
to2.removeAllItems();
to2.addItem(“KOTA”);
to2.addItem(“HANUMANGARH”);
to2.addItem(“JAIPUR”);
to2.addItem(“AJMER”);
to2.addItem(“ALWAR”);
70
return1.setEnabled(true);
from2.setEnabled(true);
to2.setEnabled(true);
}
return1.setEnabled(false);
from2.setEnabled(false);
to2.setEnabled(false);
return1.setEnabled(true);
from2.setEnabled(false);
to2.setEnabled(false);
logout.setEnabled(false);
JoptionPane.showMessageDialog(this, “Thanks to visit…”);
if(from1.getSelectedItem().equals(to1.getSelectedItem()))
{
JoptionPane.showMessageDialog(this, “Same City ! Plese Select Right Cities “);
}
else
{
Date date1 = new Date();
71
if(dep1.getDate().before(date1))
{
JoptionPane.showMessageDialog(this, “Please Select Departure Date”);
}
else
if(one.isSelected())
{
return1.setEnabled(false);
from2.setEnabled(false);
to2.setEnabled(false);
try
{
String tclass = travel1.getSelectedItem().toString();
Class.forName(“java.sql.Driver”);
con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/trdb” , “root” ,
“root”);
st = con.createStatement();
while(rs.next())
{
String fno = rs.getString(“Train”);
String dep = rs.getString(“departure”);
String arv = rs.getString(“arrival”);
String dtime = rs.getString(“deptime”);
String atime = rs.getString(“artime”);
String p = rs.getString(“price”);
int price = 0;
price = Integer.parseInt(p);
if(tclass.equals(“AC CLASS”))
{
price = price + 75;
}
else
if(tclass.equals(“AC-SLEEPER CLASS”))
{
price = price + 150;
72
}
else
if(tclass.equals(“NON-AC SLEEPER CLASS”))
{
price = price + 75;
}
else
{
price = Integer.parseInt(p);
}
p = “” + price;
}
catch(ClassNotFoundException | SQLException ex1)
{
}
}
else
if(round.isSelected())
{
if(return1.getEditor().getText().equals(“”))
JoptionPane.showMessageDialog(this, “Please Select Return Date…”);
else
JoptionPane.showMessageDialog(this, “Sorry ! Round Trip is not available”);
}
else
if(multi.isSelected())
{
JoptionPane.showMessageDialog(this, “Sorry ! Multicity is not available”);
}
}
}
ticket.setEnabled(true);
// TODO add your handling code here:
}
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
76
import java.util.Date;
String Trainname1;
String departure1;
String arrival1;
String departuretime1;
String arrivaltime1;
String price1;
Date depdate1;
String tclass1;
public BookTicket() {
initComponents();
this.setLocationRelativeTo(null);
Trainname1 = Trainname;
departure1 = departure;
arrival1 = arrival;
77
departuretime1 = departuretime;
arrivaltime1 = arrivaltime;
price1 = price;
depdate1 = depdate;
tclass1 = tclass;
ddate2.setText(“”+depdate);
from.setText(departure);
to.setText(arrival);
trclass.setText(tclass);
dtime.setText(“Departure : “ + departuretime);
ddate.setText(“Departure Date : “ + depdate);
dcity.setText(“Departure City : “ + departure);
dairport.setText(“”);
atime.setText(“Arrival : “ + arrivaltime);
adate.setText(“Arrival Date : “ + depdate);
acity.setText(“Arrival City : “ + arrival);
aairport.setText(“”);
@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBounds(new java.awt.Rectangle(0, 0, 0, 0));
setUndecorated(true);
setResizable(false);
81
.addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(to)
.addComponent(from))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(trclass))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(12, 12, 12)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.BASELINE)
.addComponent(jLabel10)
.addComponent(jLabel5))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
);
84
jLabel14.setBackground(new java.awt.Color(0, 51, 153));
jLabel14.setFont(new java.awt.Font(“Tahoma”, 1, 14)); // NOI18N
jLabel14.setForeground(new java.awt.Color(255, 255, 255));
jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/Trainicon.png”))); //
NOI18N
jLabel14.setText(“Train Booking System”);
85
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 352,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(437, 437, 437)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 176,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(110, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32,
Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 40,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addGap(10, 10, 10)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addGap(26, 26, 26))
);
pack();
}// </editor-fold>
System.exit(0);
}
this.setState(Home.ICONIFIED);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the NimTrain look and feel */
//<editor-fold defaultstate=”collapsed” desc=” Look and feel setting code (optional) “>
/* If NimTrain (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“NimTrain”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(BookTicket.class.getName()).log(java.util.logging.Level.SEVE
RE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(BookTicket.class.getName()).log(java.util.logging.Level.SEVE
RE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(BookTicket.class.getName()).log(java.util.logging.Level.SEVE
RE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(BookTicket.class.getName()).log(java.util.logging.Level.SEVE
RE, null, ex);
}
//</editor-fold>
87
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new BookTicket().setVisible(true);
}
});
}
String Code1;
String Trainname1;
String departure1;
String arrival1;
String departuretime1;
String arrivaltime1;
String price1;
String depdate1;
String tclass1;
Connection con;
Statement st;
public TravellerDetails() {
89
initComponents();
setLocationRelativeTo(null);
addinfo.setEnabled(false);
try
{
Class.forName(“java.sql.Driver”);
con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/trdb” , “root” , “root”);
}
addinfo.setEnabled(false);
Trainname1 = Trainname;
departure1 = departure;
arrival1 = arrival;
departuretime1 = departuretime;
90
arrivaltime1 = arrivaltime;
price1 = price;
depdate1 = “”+ depdate;
tclass1 = tclass;
try
{
Class.forName(“java.sql.Driver”);
con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/trdb” , “root” , “root”);
}
try
{
String qur = “select * from Traintraveller”;
st = con.createStatement();
ResultSet rs = st.executeQuery(qur);
while(rs.next())
{
if(Trainname1.equals(rs.getString(“Trainname”)) &&
depdate1.equals(rs.getString(“depdate”)))
{
for(int i = 1 ; i <= 50 ; i++)
{
String sh1 = “”+i;
if(sh1.equals(rs.getString(“sheetno”) ) )
{
s1.removeItem(sh1);
}
}
}
}
}
catch(SQLException ex2)
{
}
@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
private void initComponents() {
91
buttonGroup1 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.Jpanel();
jPanel11 = new javax.swing.Jpanel();
jLabel7 = new javax.swing.Jlabel();
check1 = new javax.swing.JcheckBox();
jPanel12 = new javax.swing.Jpanel();
fname9 = new javax.swing.Jlabel();
n1 = new javax.swing.JtextField();
fname10 = new javax.swing.Jlabel();
n2 = new javax.swing.JtextField();
male = new javax.swing.JradioButton();
female = new javax.swing.JradioButton();
jLabel8 = new javax.swing.Jlabel();
fname11 = new javax.swing.Jlabel();
cat = new javax.swing.JcomboBox();
fname12 = new javax.swing.Jlabel();
s1 = new javax.swing.JcomboBox();
jPanel10 = new javax.swing.Jpanel();
fname5 = new javax.swing.Jlabel();
m1 = new javax.swing.JtextField();
fname6 = new javax.swing.Jlabel();
e1 = new javax.swing.JtextField();
jLabel6 = new javax.swing.Jlabel();
fname7 = new javax.swing.Jlabel();
m2 = new javax.swing.JtextField();
from = new javax.swing.Jlabel();
generatecode = new javax.swing.Jbutton();
booking = new javax.swing.Jlabel();
logout = new javax.swing.Jbutton();
addinfo = new javax.swing.Jbutton();
jPanel4 = new javax.swing.Jpanel();
jLabel11 = new javax.swing.Jlabel();
jLabel12 = new javax.swing.Jlabel();
jLabel14 = new javax.swing.Jlabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
pack();
}// </editor-fold>
name1 = n1.getText();
name2 = n2.getText();
mobile1 = m1.getText();
mobile2 = m2.getText();
email = e1.getText();
category1 = (String) cat.getSelectedItem();
sheet1 = (String) s1.getSelectedItem();
if(male.isSelected())
gender = “male”;
else
if(female.isSelected())
gender = “female”;
else
gender = “”;
else
try
{
st = con.createStatement();
101
st.execute(qur);
JoptionPane.showMessageDialog(this, “Information Submitted … “);
n1.setText(“”);
n2.setText(“”);
m1.setText(“”);
m2.setText(“”);
e1.setText(“”);
cat.setSelectedIndex(0);
s1.setSelectedIndex(0);
male.setSelected(false);
female.setSelected(false);
check1.setSelected(false);
new Payment(Code1).setVisible(true);
this.dispose();
}
catch(HeadlessException | SQLException ex2)
{
}
}
else
JoptionPane.showMessageDialog(this, “Check Acknowledgement …”);
switch(day1)
{
case 1:
s3 = “MNY”;
break;
case 2:
s3 = “TDY”;
102
break;
case 3:
s3 = “WSY”;
break;
case 4:
s3 = “TSY”;
break;
case 5:
s3 = “FIY”;
break;
case 6:
s3 = “SRY”;
break;
case 0:
s3 = “SNY”;
break;
default:
s3 = “DNF”;
}
if(s1==null || s2==null)
JoptionPane.showMessageDialog(this, “Sorry ! Unable to Generate Booking Code …”);
else
{
Code1 =s3+mm+s2+hh+s1;
try
{
String qur = “insert into Trainbookingcode values(‘”+s1+”’, ‘”+s2+”’ , ‘”+Code1+”’)”;
st = con.createStatement();
st.execute(qur);
}
catch(SQLException e1)
{ }
addinfo.setEnabled(true);
generatecode.setEnabled(false);
logout.setEnabled(false);
}
logout.setEnabled(false);
System.exit(0);
}
this.setState(Home.ICONIFIED);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the NimTrain look and feel */
//<editor-fold defaultstate=”collapsed” desc=” Look and feel setting code (optional) “>
/* If NimTrain (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“NimTrain”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TravellerDetails.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (InstantiationException ex) {
104
java.util.logging.Logger.getLogger(TravellerDetails.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TravellerDetails.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TravellerDetails.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
}
//</editor-fold>
Booking code is being created now Enter all the informations of the traveller
106
107
6.3.7 – Payment Panel
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JoptionPane;
import javax.swing.table.DefaultTableModel;
Connection con;
Statement st;
ResultSet rs;
String d1;
String departure1;
String arrival1;
String Train1;
String name1;
108
String category1;
String gender1;
String contact1;
String email1;
String sheetno1;
String BookingCode;
public Payment()
{
initComponents();
this.setLocationRelativeTo(null);
try
{
Class.forName(“java.sql.Driver”);
con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/trdb” , “root” , “root”);
}
month.removeAllItems();
month.addItem(“Month”);
for(int i=1 ; i <= 12 ; i++)
{
month.addItem(“”+i);
}
year.removeAllItems();
year.addItem(“Year”);
for(int i=2020 ; i<=2050 ; i++)
{
year.addItem(“”+i);
}
}
month.removeAllItems();
month.addItem(“Month”);
for(int i=1 ; i <= 12 ; i++)
109
{
month.addItem(“”+i);
}
year.removeAllItems();
year.addItem(“Year”);
for(int i=2020 ; i<=2050 ; i++)
{
year.addItem(“”+i);
}
try
{
Class.forName(“java.sql.Driver”);
con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/trdb” , “root” , “root”);
}
try
{
st = con.createStatement();
rs = st.executeQuery(qur);
while(rs.next())
{
BookingCode = rs.getString(“booking”);
d1 = rs.getString(“depdate”);
departure1 = rs.getString(“departure”);
arrival1 = rs.getString(“arrival”);
Train1 = rs.getString(“Trainname”);
name1 = rs.getString(“name1”);
category1 = rs.getString(“category”);
gender1 = rs.getString(“gender”);
contact1= rs.getString(“mobile1”);
email1 = rs.getString(“email”);
sheetno1 = rs.getString(“sheetno”);
price = Integer.parseInt(rs.getString(“price”));
date1.setText(“Date : “ + d1);
departure.setText(“Departure : “ + departure1);
110
arrival.setText(“Arrival : “ + arrival1);
flight.setText(“Train : “ + Train1);
}
catch(HeadlessException | NumberFormatException | SQLException e1)
{} }
@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
setResizable(false);
},
new String [] {
“Name”, “Category”, “Gender”, “Contact”, “Email”, “Sheetno.”
}
));
tb1.setRowHeight(45);
jScrollPane1.setViewportView(tb1);
112
atotal.setFont(new java.awt.Font(“Calibri”, 1, 24)); // NOI18N
atotal.setForeground(new java.awt.Color(255, 51, 51));
atotal.setText(“Total”);
120
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(25, 25, 25))
);
pack();
}// </editor-fold>
if(cardnumber.getText().equals(“”) || nameoncard.getText().equals(“”) ||
cvvcode.getText().equals(“”) || month.getSelectedItem().equals(“Month”) ||
year.getSelectedItem().equals(“Year”) )
{
JoptionPane.showMessageDialog(this, “Please fill all the deatils…”);
}
else
if(cnumber.length() == 16 && cvvcode.getText().length() == 3)
{
for(int i = 0 ; i < cnumber.length() ; i++)
{
int c1 =(int) cnumber.charAt(i);
if(c1 >= 48 && c1 <= 57)
{
}
else
{
JoptionPane.showMessageDialog(this, “Fill Only number in Card Number…”);
cardnumber.setText(“”);
check1 = 1;
break;
}
}
}
catch(Exception e1)
{
}
}
}
else
{
JoptionPane.showMessageDialog(this, “Wrong Information… “);
cardnumber.setText(“”);
cvvcode.setText(“”);
}
122
private void monthMouseClicked(java.awt.event.MouseEvent evt) {
System.exit(0);
}
this.setState(Home.ICONIFIED);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the NimTrain look and feel */
//<editor-fold defaultstate=”collapsed” desc=” Look and feel setting code (optional) “>
/* If NimTrain (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“NimTrain”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Payment.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Payment.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Payment.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Payment.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
}
123
//</editor-fold>
}
});
}
public LastForm() {
initComponents();
this.setLocationRelativeTo(null);
}
tk1.setText(b1);
tr1.setText(t1);
}
@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
setResizable(false);
127
jLabel14.setBackground(new java.awt.Color(0, 51, 153));
jLabel14.setFont(new java.awt.Font(“Tahoma”, 1, 14)); // NOI18N
jLabel14.setForeground(new java.awt.Color(255, 255, 255));
jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource(“/Trainicon.png”))); //
NOI18N
jLabel14.setText(“Train Booking System”);
pack();
130
}// </editor-fold>
logout.setEnabled(false);
JoptionPane.showMessageDialog(this, “Thanks to visit…”);
System.exit(0);
}
this.setState(Home.ICONIFIED);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LastForm().setVisible(true);
}
});
131
}
132
Select search option and enter search related information then search record.
import java.sql.Connection;
133
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.util.Date;
import javax.swing.table.DefaultTableModel;
Connection con;
Statement st;
ResultSet rs;
public Passenger()
{
initComponents();
this.setLocationRelativeTo(null);
l1.setVisible(false);
t1.setVisible(false);
b1.setVisible(false);
list1.removeAllItems();
list1.addItem(“Search By “);
list1.addItem(“Passenger Name “);
list1.addItem(“Ticket Number “);
list1.addItem(“Contact Number “);
list1.addItem(“Train Number “);
list1.addItem(“Departure Date “);
try
{
Class.forName(“java.sql.Driver”);
con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/trdb” , “root” , “root”);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings(“unchecked”)
134
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
setResizable(false);
135
t1.setFont(new java.awt.Font(“Calibri”, 0, 18)); // NOI18N
pack();
}// </editor-fold>
if(list1.getSelectedIndex() == 1)
{
l1.setVisible(true);
t1.setVisible(true);
138
b1.setVisible(true);
t1.setText(“”);
l1.setText(“Enter Passenger First&Middle Name “);
}
else
if(list1.getSelectedIndex() == 2)
{
l1.setVisible(true);
t1.setVisible(true);
b1.setVisible(true);
t1.setText(“”);
l1.setText(“Enter Ticket Number “);
}
else
if(list1.getSelectedIndex() == 3)
{
l1.setVisible(true);
t1.setVisible(true);
b1.setVisible(true);
t1.setText(“”);
l1.setText(“Enter Contact Number “);
}
else
if(list1.getSelectedIndex() == 4)
{
l1.setVisible(true);
t1.setVisible(true);
b1.setVisible(true);
t1.setText(“”);
l1.setText(“Enter Train Number | RJ20-Number “);
}
else
if(list1.getSelectedIndex() == 5)
{
l1.setVisible(true);
t1.setVisible(true);
b1.setVisible(true);
t1.setText(“”);
l1.setText(“Enter Train Date Number | DD/MM/YY “);
}
139
else
{
l1.setVisible(false);
t1.setVisible(false);
b1.setVisible(false);
}
// TODO add your handling code here:
}
}
}
catch(SQLException e1)
{
}
}
else
if(list1.getSelectedIndex() == 2)
{
String qur = “select * from Traintraveller where booking = ‘”+t1.getText()+”’”;
try{
st = con.createStatement();
rs = st.executeQuery(qur);
140
DefaultTableModel model = (DefaultTableModel) tab1.getModel();
model.setNumRows(0);
while(rs.next())
{
String row1[] = {rs.getString(“booking”), rs.getString(“name1”),
rs.getString(“mobile1”), rs.getString(“Trainname”), rs.getString(“departure”),
rs.getString(“arrival”), rs.getString(“departuretime”), rs.getString(“arrivaltime”),
rs.getString(“sheetno”), rs.getString(“depdate”)};
model.addRow(row1);
}
}
catch(SQLException e1)
{
}
}
else
if(list1.getSelectedIndex() == 3)
{
String qur = “select * from Traintraveller where mobile1 = ‘”+t1.getText()+”’”;
try{
st = con.createStatement();
rs = st.executeQuery(qur);
while(rs.next())
{
String row1[] = {rs.getString(“booking”), rs.getString(“name1”),
rs.getString(“mobile1”), rs.getString(“Trainname”), rs.getString(“departure”),
rs.getString(“arrival”), rs.getString(“departuretime”), rs.getString(“arrivaltime”),
rs.getString(“sheetno”), rs.getString(“depdate”)};
model.addRow(row1);
}
}
catch(SQLException e1)
{
}
}
141
else
if(list1.getSelectedIndex() == 4)
{
String qur = “select * from Traintraveller where Trainname = ‘”+t1.getText()+”’”;
try{
st = con.createStatement();
rs = st.executeQuery(qur);
while(rs.next())
{
String row1[] = {rs.getString(“booking”), rs.getString(“name1”),
rs.getString(“mobile1”), rs.getString(“Trainname”), rs.getString(“departure”),
rs.getString(“arrival”), rs.getString(“departuretime”), rs.getString(“arrivaltime”),
rs.getString(“sheetno”), rs.getString(“depdate”)};
model.addRow(row1);
}
}
catch(SQLException e1)
{
}
}
else
if(list1.getSelectedIndex() == 5)
{
String qur = “select * from Traintraveller where depdate = ‘”+t1.getText()+”’”;
try{
st = con.createStatement();
rs = st.executeQuery(qur);
while(rs.next())
{
String row1[] = {rs.getString(“booking”), rs.getString(“name1”),
rs.getString(“mobile1”), rs.getString(“Trainname”), rs.getString(“departure”),
142
rs.getString(“arrival”), rs.getString(“departuretime”), rs.getString(“arrivaltime”),
rs.getString(“sheetno”), rs.getString(“depdate”)};
model.addRow(row1);
}
}
catch(SQLException e1)
{}
}
}
System.exit(0);
}
this.setState(Home.ICONIFIED);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the NimTrain look and feel */
//<editor-fold defaultstate=”collapsed” desc=” Look and feel setting code (optional) “>
/* If NimTrain (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“NimTrain”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
143
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Passenger.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Passenger.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Passenger.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Passenger.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
}
//</editor-fold>
144
145
6.3.10 - Add Train Panel
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import javax.swing.JOptionPane;
Connection con;
Statement st;
public Train()
{
initComponents();
this.setLocationRelativeTo(null);
dep1.removeAllItems();
dep1.addItem("KOTA");
dep1.addItem("BUNDI");
dep1.addItem("JAIPUR");
146
dep1.addItem("AJMER");
dep1.addItem("ALWAR");
ar1.removeAllItems();
ar1.addItem("KOTA");
ar1.addItem("BUNDI");
ar1.addItem("JAIPUR");
ar1.addItem("AJMER");
ar1.addItem("ALWAR");
try
{
Class.forName("java.sql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/trdb" , "root" , "root");
}
catch(ClassNotFoundException | SQLException ex1)
{
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
149
.addComponent(ar1, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(price1)
.addComponent(Train1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel2Layout.createSequentialGroup()
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 148,
Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 121,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(deptime1, javax.swing.GroupLayout.PREFERRED_SIZE, 120,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(artime1, javax.swing.GroupLayout.PREFERRED_SIZE, 120,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(127, 127, 127))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(38, 38, 38)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(Train1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jLabel6)
.addComponent(dep1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(deptime1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jLabel9)
.addComponent(ar1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
150
.addComponent(jLabel11)
.addComponent(artime1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jLabel8)
.addComponent(price1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 39,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 39,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(47, Short.MAX_VALUE))
);
151
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 212,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 786,
Short.MAX_VALUE)
.addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 16,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel12)
.addGap(22, 22, 22))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)
.addComponent(jLabel14)
.addComponent(jLabel13)
.addComponent(jLabel12))
);
pack();
}// </editor-fold>
f1 = Train1.getText();
d1 = (String) dep1.getSelectedItem();
d1time = deptime1.getText();
a1 = (String) ar1.getSelectedItem();
a1time = artime1.getText();
p1 = price1.getText();
else
{
153
try{
String qur = "insert into Train values('"+f1+"' , '"+d1+"' , '"+a1+"' , '"+p1+"' ,
'"+d1time+"' , '"+a1time+"')";
st = con.createStatement();
st.execute(qur);
JOptionPane.showMessageDialog(this, "Train Added..");
Train1.setText("");
dep1.setSelectedIndex(0);
ar1.setSelectedIndex(0);
deptime1.setText("");
artime1.setText("");
price1.setText("");
}
catch(Exception e1)
{
System.exit(0);
}
this.setState(Home.ICONIFIED);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the NimTrain look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If NimTrain (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("NimTrain".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Train.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Train.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Train.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Train.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
}
}
});
}
156
Now check your Train is added or not
157
Your Train has been added | Now Book a ticket
158
Chepter 7 - Future Scope of this project
We can add printer in future for generating printed ticket for the traveler.
We can give more advanced Train Booking System software including more
facilities.
We can add functionality for sending a message to the traveler related to ticket,
Train, travelling information etc.
159
Chepter - 9 References
160
6. Effective Java
(Written by Joshua Bloch) Yes, this amazing book is also on our list. It does justice with its name
“Effective Java”.
It is also actually very effective. Whoever reads it or go through this, just fall in love with it.
You will learn so much about Java and its API that you could imagine. Any programmer from any experience
level can enjoy it and we can proudly admit that this is among best java books.
8. Clean Code( Written by Robert Cecil Martin ) As you can judge by the name it’s an amazing book. Its
title clearly portrays its purpose as it teaches you how to write clean or better code.
And in our honest opinion, it’s easy to learn java but difficult to write clean code of java. So this book surely
helps in that.
So, yes we can say that it satisfies the term best book for java for some advanced developers as beginners
won’t be able to write code before learning its basics.
9. Test Driven
(Written by Lasse Koskela) when it comes to the testing phase, automation testing is an important skill.
For developers, it all starts with unit testing and luckily this book is blessed with Junit from the start.
So, If you are serious about code quality and writing unit and automation test then this book is a must read
in 2018. Its indeed the best book for java in the form of testing as well.
161
Thanks
162