0% found this document useful (0 votes)
23 views47 pages

Report Java

Uploaded by

sktaufik753
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views47 pages

Report Java

Uploaded by

sktaufik753
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 47

Introduction

The Online Train Reservation System integration is a robust and user-friendly application
designed to simplify and automate the process of booking train tickets online. Developed using
Java, the project employs Java Database Connectivity (JDBC) for efficient interaction with the
MySQL database. The system offers features such as user registration and login, train search and
booking, fare calculation.

Additionally, the project embraces principles of data security by encrypting sensitive user
information and employing secure authentication mechanisms. The admin panel offers
functionalities for managing train schedules, user accounts, and monitoring reservations. The
integration of JDBC ensures that any changes made through the admin panel are efficiently
reflected in the database.

 Java Swing
Java Swing is a set of graphical user interface (GUI) components for Java applications. It
provides a rich set of controls and components for building desktop applications with a
consistent look and feel.

In a Train Reservation System project developed in Java, the use of Java Swing provides a
graphical user interface (GUI) for a more user-friendly and interactive experience.It uses the
components like JTextFields, Jlabel, JButton, etc.

 JFrames and JPanels: Java Swing provides classes like JFrame and JPanel for creating
the main application window and organizing components within it. The overall structure
of the application is built using these containers.

 JLabels and JTextFields: Swing components like JLabel and JTextField are used for
displaying information and capturing user input. For example, labels can be used to show
information about the train, and text fields can be used for users to input details like
source, destination, and the number of passengers.

 JButtons: JButton components are used to create clickable buttons for actions like
searching for trains, booking tickets, or navigating between different sections of the
application.

 Java Database Connectivity (JDBC)


JDBC stands for Java Database Connectivity. JDBC is a Java API to connect and execute the
query with the database. It is a part of JavaSE (Java Standard Edition). JDBC API uses JDBC
drivers to connect with the database.
Key Concepts:

 Connection: Establishes a connection to the database.

 Statement: Executes SQL queries and updates.

 ResultSet: Represents the result of a database query.

 DriverManager: Manages a list of database drivers.

 PreparedStatement: It is a precompiled SQL statement that supports parameterized


queries.

Steps to establish connection with Database

 Load the Driver

 Establish the Connection

 Write and Execute the Query with the help of Statement and PreparedStatement

 Fetch the Result

 Connection Closed

 Event Handling
Event handling in Java refers to the mechanism by which events, such as user actions or system-
generated occurrences, are managed and responded to in a Java program. Java provides a robust
event-handling framework that allows developers to create responsive and interactive
applications.

In Java, event handling involves three main components: sources, listeners, and events. A source
is an object that generates an event, such as a button or a mouse click. A listener is an interface
or class that receives and processes events. Events are objects representing occurrences, and they
encapsulate information about the event, such as its type or source.

 ActionListener

The ActionListener interface in Java is a part of the java.awt.event package and is a key
component of the event-handling mechanism. It is used to handle action events, typically
generated by user interactions with graphical user interface (GUI) components like
buttons and menu items.
Program code :

// Source code is decompiled from a .class file using FernFlower decompiler.

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Container;

import java.awt.Font;

import java.awt.LayoutManager;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.BorderFactory;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JCheckBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTabbedPane;

import javax.swing.JTextField;

import javax.swing.UIManager;

import javax.swing.border.MatteBorder;

import javax.swing.plaf.ColorUIResource;

import javax.swing.plaf.InsetsUIResource;

public class ColoredJTabbedPane extends JFrame implements ActionListener {


JLabel header;

JLabel l1;

JLabel l2;

JTextField t1;

JPasswordField t2;

JButton submit;

JCheckBox c1;

JLabel user;

JLabel pass;

JLabel phone;

JLabel email;

JLabel renter;

JTextField nametxt;

JTextField mailtxt;

JTextField phntxt;

JButton register;

JPasswordField pfield;

JPasswordField rfield;

JCheckBox c2;

JCheckBox c3;

ColoredJTabbedPane() {

Container var1 = this.getContentPane();

var1.setLayout(new BorderLayout());

var1.setBackground(new Color(175, 212, 189));


var1.setBackground(new Color(175, 212, 189));

this.header = new JLabel("Train Reservation System");

this.header.setFont(new Font("Buffalo", 1, 30));

this.header.setForeground(new Color(175, 212, 189));

this.header.setBounds(80, 5, 400, 40);

var1.add(this.header);

UIManager.put("TabbedPane.background", new ColorUIResource(Color.RED));

JTabbedPane var2 = new JTabbedPane();

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

} catch (Exception var8) {

var8.printStackTrace();

UIManager.put("TabbedPane.background", new ColorUIResource(new Color(179,


216, 222)));

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

} catch (Exception var7) {

var7.printStackTrace();

JPanel var3 = new JPanel();


var3.setLayout((LayoutManager)null);

JPanel var4 = new JPanel();

var4.setLayout((LayoutManager)null);

var3.setBackground(new Color(179, 216, 222));

var4.setBackground(new Color(179, 216, 222));

var2.addTab("Login", new ImageIcon("images/loginnew.png"), var3);

var2.addTab("Register", new ImageIcon("images/usernew.png"), var4);

UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(1, 1, 1, 1));

UIManager.put("TabbedPane.contentAreaColor", new ColorUIResource(new


Color(175, 212, 189)));

this.getContentPane().add(var2);

MatteBorder var5 = BorderFactory.createMatteBorder(50, 50, 50, 50, new Color(219,


81, 109));

var2.setBorder(var5);

var1.add(var2);

Font var6 = new Font("Buffalo", 1, 15);

var2.setBackground(new Color(255, 253, 208));

this.l1 = new JLabel("USERNAME");

this.l1.setFont(var6);

this.l2 = new JLabel("PASSWORD");

this.l2.setFont(var6);

this.t1 = new JTextField(20);

this.t2 = new JPasswordField(8);

this.submit = new JButton("Login");

this.submit.setFont(var6);

this.c1 = new JCheckBox("Show");


this.c1.setBackground(new Color(179, 216, 222));

this.l1.setBounds(60, 100, 100, 25);

this.t1.setBounds(170, 100, 200, 25);

this.l2.setBounds(60, 135, 100, 25);

this.t2.setBounds(170, 135, 200, 25);

this.c1.setBounds(380, 135, 200, 25);

this.submit.setBounds(170, 180, 100, 25);

this.submit.setBackground(new Color(175, 212, 189));

this.submit.addActionListener(this);

var3.add(this.l1);

var3.add(this.l2);

var3.add(this.t1);

var3.add(this.t2);

var3.add(this.c1);

this.c1.addActionListener(this);

var3.add(this.submit);

this.user = new JLabel("User Name");

this.user.setFont(var6);

this.pass = new JLabel("Password");

this.pass.setFont(var6);

this.renter = new JLabel("Re-Enter Password:");

this.renter.setFont(var6);

this.email = new JLabel("Email ID:");

this.email.setFont(var6);

this.phone = new JLabel("Contact no.");


this.phone.setFont(var6);

this.nametxt = new JTextField(20);

this.mailtxt = new JTextField(25);

this.phntxt = new JTextField(10);

this.pfield = new JPasswordField(8);

this.rfield = new JPasswordField(8);

this.c2 = new JCheckBox("Show");

this.c3 = new JCheckBox("Show");

this.register = new JButton("Register");

this.user.setBounds(60, 60, 100, 25);

this.nametxt.setBounds(230, 60, 200, 25);

this.email.setBounds(60, 95, 100, 25);

this.mailtxt.setBounds(230, 95, 200, 25);

this.phone.setBounds(60, 130, 100, 25);

this.phntxt.setBounds(230, 130, 200, 25);

this.pass.setBounds(60, 165, 100, 25);

this.pfield.setBounds(230, 165, 200, 25);

this.c2.setBounds(370, 195, 100, 25);

this.renter.setBounds(60, 230, 150, 25);

this.rfield.setBounds(230, 230, 200, 25);

this.c3.setBounds(370, 260, 100, 25);

this.register.setBounds(180, 320, 100, 25);

this.c2.setBackground(new Color(179, 216, 222));

this.c3.setBackground(new Color(179, 216, 222));

this.register.setFont(var6);
var4.add(this.user);

var4.add(this.email);

var4.add(this.phone);

var4.add(this.pass);

var4.add(this.renter);

var4.add(this.nametxt);

var4.add(this.mailtxt);

var4.add(this.phntxt);

var4.add(this.pfield);

var4.add(this.rfield);

var4.add(this.register);

this.register.addActionListener(this);

this.c2.addActionListener(this);

this.c3.addActionListener(this);

var4.add(this.c2);

var4.add(this.c3);

public void actionPerformed(ActionEvent var1) {

String var2;

String var3;

if (var1.getSource() == this.register) {

System.out.println("Register Called");

var2 = this.nametxt.getText();

var3 = this.mailtxt.getText();
String var4 = this.phntxt.getText();

String var5 = this.pfield.getText();

String var6 = this.rfield.getText();

new Information(var2, var3, var4, var5, var6);

if (var1.getSource() == this.submit) {

if (this.t1.getText().isEmpty()) {

var2 = null;

} else {

var2 = this.t1.getText();

if (this.t2.getText().isEmpty()) {

var3 = null;

} else {

var3 = this.t2.getText();

System.out.println("S1 : " + var2 + " S2: " + var3);

new Information(var2, var3);

}
public static void main(String[] var0) {

ColoredJTabbedPane var1 = new ColoredJTabbedPane();

var1.setSize(600, 600);

var1.setVisible(true);

var1.setDefaultCloseOperation(3);

var1.setLocation(600, 100);

2) import javax.swing.*;

import javax.swing.plaf.basic.BasicTabbedPaneUI;

import java.awt.*;

public class CustomTabbedPaneDemo {

public static void main(String[] args) {

SwingUtilities.invokeLater(() -> {

JFrame frame = new JFrame("Custom TabbedPane Demo");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JTabbedPane tabbedPane = new JTabbedPane();

tabbedPane.addTab("Tab 1", new JPanel());

tabbedPane.addTab("Tab 2", new JPanel());

tabbedPane.addTab("Tab 3", new JPanel());

// Create a custom UI for the JTabbedPane


tabbedPane.setUI(new CustomTabbedPaneUI());

frame.add(tabbedPane);

frame.setSize(400, 300);

frame.setVisible(true);

});

class CustomTabbedPaneUI extends BasicTabbedPaneUI {

@Override

protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex) {

// Set the color for the upper line of panes

g.setColor(Color.RED); // Change to your desired color

// Determine the bounds of the tab area

Rectangle tabArea = tabbedPane.getBoundsAt(0);

tabArea.height = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);

// Paint the upper line of panes with the custom color

g.fillRect(tabArea.x, tabArea.y, tabArea.width, 2);

// Call the parent method to paint the tab content

super.paintTabArea(g, tabPlacement, selectedIndex);

}}
3) import javax.swing.*;

import java.awt.event.*;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import javax.swing.table.*;

import javafx.event.ActionEvent;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.awt.*;

public class DatabaseTableExample extends JPanel{

public DatabaseTableExample() {

// Define database connection parameters

String jdbcUrl = "jdbc:mysql://localhost:3306/train_reservation_system";

String username = "aniket";

String password = "aniket47";

setSize(700,700);
// Create the database connection

try (Connection connection = DriverManager.getConnection(jdbcUrl, username,


password)) {

// Create a statement for executing SQL queries

Statement statement = connection.createStatement();

// Define your SQL query

String sqlQuery = "SELECT * FROM Trains";

// Execute the query and retrieve the result set

ResultSet resultSet = statement.executeQuery(sqlQuery);

// Create a JTable to display the data

JTable table = new JTable(buildTableModel(resultSet));

table.setBackground(Color.green);

table.setBounds(20,20,700,500);

table.setFont(new Font("Ariel", Font.BOLD, 15));

// Set header background color

JTableHeader header = table.getTableHeader();

header.setDefaultRenderer(new HeaderRenderer(table));

table.setSize(700, 600);
table.setRowHeight(30); // Set cell height to 50

table.getColumnModel().getColumn(0).setPreferredWidth(100); // Set cell width for


column 0 to 100

// Add the table to a JScrollPane for scrollability

JScrollPane scrollPane = new JScrollPane(table);

scrollPane.setPreferredSize(new Dimension(800, 600));

this.add(scrollPane);

} catch (Exception e) {

e.printStackTrace();

public DefaultTableModel buildTableModel(ResultSet resultSet) throws SQLException


{

ResultSetMetaData metaData = resultSet.getMetaData();

// Get column names

int columnCount = metaData.getColumnCount();

String[] columnNames = new String[columnCount];

for (int column = 1; column <= columnCount; column++) {

columnNames[column - 1] = metaData.getColumnName(column);

}
// Create a DefaultTableModel and add data to it

DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0);

while (resultSet.next()) {

Object[] rowData = new Object[columnCount];

for (int i = 1; i <= columnCount; i++) {

rowData[i - 1] = resultSet.getObject(i);

tableModel.addRow(rowData);

tableModel.addColumn("Book ");

return tableModel;

private static class HeaderRenderer extends DefaultTableCellRenderer {

public HeaderRenderer(JTable table) {

setHorizontalAlignment(SwingConstants.CENTER);

setSize(100, 50);

setBackground(Color.YELLOW); // Set the header background color

}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {

return super.getTableCellRendererComponent(table, value, isSelected, hasFocus,


row, column);

}
4) import javax.swing.*;

import javax.swing.event.DocumentListener;

import javax.xml.crypto.dsig.spec.XPathType.Filter;

import javax.swing.event.DocumentEvent;

import javax.swing.event.DocumentListener;

import java.awt.*;

import java.text.SimpleDateFormat;

import java.util.*;

public class Filters extends JPanel{

public Filters() {

// Create a JComboBox and populate it with dates

JComboBox<String> dateComboBox = new JComboBox<>();

DefaultComboBoxModel<String> dateComboBoxModel = new


DefaultComboBoxModel<>();

// Create a date formatter to format the date as "dd/MM/yyyy"

SimpleDateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");

// Set the start date (January 12, 2023)


Calendar startDate = Calendar.getInstance();

startDate.set(2023, Calendar.JANUARY, 12);

// Set the end date (April 21, 2024)

Calendar endDate = Calendar.getInstance();

endDate.set(2024, Calendar.APRIL, 21);

// Add dates to the ComboBoxModel

while (startDate.before(endDate)) {

dateComboBoxModel.addElement(dateFormatter.format(startDate.getTime()));

startDate.add(Calendar.DATE, 1); // Increment date by one day

dateComboBox.setModel(dateComboBoxModel);

this.add(dateComboBox);

JComboBox<String> trainClassesComboBox = new JComboBox<>();

trainClassesComboBox.setModel(new
DefaultComboBoxModel<>(getIndianTrainClasses()));

this.add(trainClassesComboBox);

private static String[] getIndianTrainClasses() {

// Hardcoded list of Indian train classes


String[] trainClasses = {

"First AC (1A)",

"Second AC (2A)",

"Third AC (3A)",

"Sleeper Class (SL)",

"General Class (GN)",

"Chair Car (CC)",

"Second Seating (2S)"

};

return trainClasses;

}
5) import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.awt.event.*;

import javax.swing.border.*;

import javax.swing.plaf.*;

import javax.swing.plaf.basic.BasicTabbedPaneUI;

public class index extends JFrame //implements ActionListener

//panel 1

JLabel l1, l2;

JTextField t1;

JPasswordField t2;

JButton submit;

JCheckBox c1;

//panel 2

JLabel user, pass, phone, email, renter;

JTextField nametxt, mailtxt, phntxt;

JButton register;

JPasswordField pfield, rfield;

JCheckBox c2, c3;

index() {
Container c = getContentPane();

c.setLayout(new BorderLayout());

setBackground(new Color(255, 253, 208));

// JLabel user = new JLabel("Username");

UIManager.put("TabbedPane.background", new ColorUIResource(Color.RED));

JTabbedPane tabbedPane = new JTabbedPane();

tabbedPane.setUI(new BasicTabbedPaneUI() {

protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int


y, int w, int h, boolean isSelected) {

if (isSelected) {

g.setColor(new Color(255, 253, 208));

g.fillRect(x, y, w, h);

protected void paintTab(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int
h, boolean isSelected) {

if (isSelected) {

g.setColor(new Color(255, 253, 208));

g.fillRect(x, y, w, h);

});
try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

} catch (Exception e) {

e.printStackTrace();

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

} catch (Exception e) {

e.printStackTrace();

JPanel panel1 = new JPanel();

panel1.setLayout(null);

JPanel panel2 = new JPanel();

panel2.setLayout(null);

panel1.setBackground(new Color(255, 253, 208));

panel2.setBackground(new Color(255, 253, 208));

tabbedPane.addTab("Login", new ImageIcon("images/loginnew.png"), panel1);

tabbedPane.addTab("Register", new ImageIcon("images/usernew.png"), panel2);

UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(1, 1, 1, 1));

UIManager.put("TabbedPane.contentAreaColor", new ColorUIResource(

Color.BLACK));

getContentPane().add(tabbedPane);
Color creamColor = new Color(255, 253, 208);

Border upperBorder = BorderFactory.createMatteBorder(50, 50, 50, 50, creamColor);

tabbedPane.setBorder(upperBorder);

c.add(tabbedPane);

Font f1 = new Font(Font.SANS_SERIF, Font.BOLD, 15);

tabbedPane.setBackground(Color.RED);

//panel1

l1 = new JLabel("UserName");

l1.setFont(f1);

l2 = new JLabel("Password");

l2.setFont(f1);

t1 = new JTextField(20);

t2 = new JPasswordField(8);

submit = new JButton("Login");

submit.setFont(f1);

c1 = new JCheckBox("Show");

c1.setBackground(creamColor);

//c1.setBackground(new Color(255, 143, 135));

l1.setBounds(60, 100, 100, 25);

t1.setBounds(170, 100, 200, 25);

l2.setBounds(60, 135, 100, 25);

t2.setBounds(170, 135, 200, 25);


c1.setBounds(380, 135, 200, 25);

submit.setBounds(170, 180, 100, 25);

panel1.add(l1);

panel1.add(l2);

panel1.add(t1);

panel1.add(t2);

panel1.add(c1);

c1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (c1.isSelected()) {

t2.setEchoChar((char) 0);

} else {

t2.setEchoChar('*');

});

panel1.add(submit);

//panel2

user = new JLabel("User Name");

user.setFont(f1);

pass = new JLabel("Password");

pass.setFont(f1);

renter = new JLabel("Re-Enter Password:");


renter.setFont(f1);

email = new JLabel("Email ID:");

email.setFont(f1);

phone = new JLabel("Contact no.");

phone.setFont(f1);

nametxt = new JTextField(20);

mailtxt = new JTextField(25);

phntxt = new JTextField(10);

pfield = new JPasswordField(8);

rfield = new JPasswordField(8);

c2 = new JCheckBox("Show");

c3 = new JCheckBox("Show");

register = new JButton("Register");

user.setBounds(60, 60, 100, 25);

nametxt.setBounds(230, 60, 200, 25);

email.setBounds(60, 95, 100, 25);

mailtxt.setBounds(230, 95, 200, 25);

phone.setBounds(60, 130, 100, 25);

phntxt.setBounds(230, 130, 200, 25);

pass.setBounds(60, 165, 100, 25);

pfield.setBounds(230, 165, 200, 25);

c2.setBounds(370, 195, 100, 25);

renter.setBounds(60, 230, 150, 25);

rfield.setBounds(230, 230, 200, 25);

c3.setBounds(370, 260, 100, 25);


register.setBounds(180, 320, 100, 25);

c2.setBackground(creamColor);

c3.setBackground(creamColor);

panel2.add(user);

panel2.add(email);

panel2.add(phone);

panel2.add(pass);

panel2.add(renter);

panel2.add(nametxt);

panel2.add(mailtxt);

panel2.add(phntxt);

panel2.add(pfield);

panel2.add(rfield);

panel2.add(register);

c2.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

if (c2.isSelected()) {

pfield.setEchoChar((char) 0);

} else {

pfield.setEchoChar('*');

});

c3.addActionListener(new ActionListener() {
@Override

public void actionPerformed(ActionEvent e) {

if (c3.isSelected()) {

rfield.setEchoChar((char) 0);

} else {

rfield.setEchoChar('*');

});

panel2.add(c2);

panel2.add(c3);

public static void main(String[] args) {

index t1 = new index();

t1.setSize(600, 600);

t1.setVisible(true);

t1.setDefaultCloseOperation(EXIT_ON_CLOSE);

t1.setLocation(600, 100);

}
6)import java.awt.*;

import javax.swing.*;

import javax.swing.table.DefaultTableModel;

import javafx.event.ActionEvent;

import java.awt.event.*;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.awt.*;

public class Reservation extends JFrame {

//p1

JLabel header;

//p3

JLabel source,destination;

JTextField sourcein,destin;

//connection
String jdbcUrl = "jdbc:mysql://localhost:3306/train_reservation_system";

String username = "aniket";

String password = "aniket47";

Reservation(){

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

setSize(screenSize.width, screenSize.height);

setDefaultCloseOperation(EXIT_ON_CLOSE);

JPanel p1 = new JPanel();

p1.setSize(100,100);

p1.setPreferredSize(new Dimension(this.getWidth(), 100));

p1.setBackground(new Color(217,167,176));

JPanel p2 = new JPanel();

p2.setSize(100,100);

p2.setPreferredSize(new Dimension(500, this.getHeight()));

p2.setBackground(new Color(166,111,111));

JPanel p3 = new JPanel(null);

p2.setPreferredSize(new Dimension(500, 500));

p3.setBackground(new Color(167,203,217));
JPanel cenp = new JPanel();

cenp.setSize(700,800);

JPanel p4 = new JPanel();

p4.setSize(100,100);

p4.setPreferredSize(new Dimension(500, this.getHeight()));

p4.setBackground(new Color(242,224,213));

JPanel p5 = new JPanel();

p5.setSize(100,100);

p5.setPreferredSize(new Dimension(this.getWidth(), 200));

p5.setBackground(new Color(104,160,166));

Container c = getContentPane();

c.setLayout(new BorderLayout());

c.add(p1,BorderLayout.NORTH);

c.add(p2,BorderLayout.EAST);

c.add(p3,BorderLayout.CENTER);

c.add(p4,BorderLayout.WEST);

c.add(p5,BorderLayout.SOUTH);

//p1

header = new JLabel("Train Reservation System");


Font texts = new Font("TimesRoman", Font.BOLD, 50);

header.setFont(texts);

header.setBounds(300,20,800,70);

p1.add(header);

//p3

Font f1 = new Font("SansSerif", Font.ITALIC, 20);

source = new JLabel("Source: ");

source.setFont(f1);

destination = new JLabel("Destination: ");

destination.setFont(f1);

sourcein = new JTextField(20);

sourcein.setBackground(new Color(167,203,217));

destin = new JTextField(20);

destin.setBackground(new Color(167,203,217));

DatabaseTableExample t1 = new DatabaseTableExample();

source.setBounds(20,10,100,25);

sourcein.setBounds(130,10,150,25);

destination.setBounds(400,10,150,25);

destin.setBounds(550,10,150,25);

t1.setBounds(30,100,800,600);

p3.add(source);
p3.add(sourcein);

p3.add(destination);

p3.add(destin);

p3.add(t1);

//p2

Filters date = new Filters();

date.setBackground(new Color(242,224,213));

p4.add(date);

setVisible(true);

public static void main(String[] args) {

Reservation r1 = new Reservation();

}
7)import javax.swing.*;

import javax.swing.table.DefaultTableCellRenderer;

import java.awt.*;

public class sample {

public static void main(String[] args) {

JFrame frame = new JFrame("JTabbedPane Tooltip Color Example");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(400, 300);

JTabbedPane tabbedPane = new JTabbedPane();

// Create tabs with tooltips

JPanel tab1 = new JPanel();

tab1.setToolTipText("Tab 1 Tooltip");

tabbedPane.add("Tab 1", tab1);

JPanel tab2 = new JPanel();

tab2.setToolTipText("Tab 2 Tooltip");

tabbedPane.add("Tab 2", tab2);

// Create a custom tooltip renderer

DefaultTableCellRenderer customRenderer = new DefaultTableCellRenderer() {

@Override

public Component getTableCellRendererComponent(


JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int
column) {

Component component = super.getTableCellRendererComponent(table, value,


isSelected, hasFocus, row, column);

// Set the background color of the tooltip

component.setBackground(Color.YELLOW); // You can change the color as needed

return component;

};

// Apply the custom renderer to the tabbed pane

tabbedPane.setTabComponentAt(0, tab1);

tabbedPane.setTabComponentAt(1, tab2);

frame.add(tabbedPane);

frame.setVisible(true);

}
Output
1- Login Page

2- Register Page
:

3- Route Selection

On this page the user need to provide Source and Destination and according to it whether the
train is available or not will be shown to user.
4- Train Selection

This page will display the available train for the route mentioned by user and user need to select
the train according to his/her need.

5- Passenger Details

This page will request the user to enter the passenger. At first the user need to enter the no. of
passenger than new panel will display and on that the user need to give the name and age of the
passengers.
6- Payment Overview

7- Downloaded Ticket
Conclusion:

In this way, we completed our micro project and developed the Train Reservation System
which is user-friendly Java-based application that uses JDBC and Swing for efficient database
connectivity and a graphical interface.

You might also like