Stadium Seat Booking System In Java | Java Project

by | Nov 22, 2022 | Coding, Java

Home » Coding » Stadium Seat Booking System In Java | Java Project

Introduction of the Project

In this coding project, we will create a Stadium Seat Booking System In Java that will book a seat for the user on the selected date. To implement this java project, we will apply a logic to assign a random seat number & keep track of seats booked. SQL database will be implemented to store information related to the booking, and the Swing module will enhance the user interface.

 

Objectives

  1. We have to apply a seat booking logic that provides a seat number & keeps track of seats available.
  2. Make the user interface more interactive with the Swing module.

Requirements

Source Code

package com.company;
import java.util.Random;
public class Main {
public static void main(String[] args) {
new MainGUI();
}
}
package com.company;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MainGUI {
private JPanel mainPanel;
private JButton NORMALButton;
private JButton RINGSIDEButton;
private JButton ENDSTANDSButton;
JFrame mainframe = new JFrame();
public MainGUI(){
mainframe.setDefaultCloseOperation(mainframe.EXIT_ON_CLOSE);
mainframe.setContentPane(mainPanel);
mainframe.pack();
mainframe.setLocationRelativeTo(null);
mainframe.setVisible(true);
NORMALButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainframe.dispose();
new Normal();
}
});
RINGSIDEButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainframe.dispose();
new RingSide();
}
});
ENDSTANDSButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainframe.dispose();
new EndStands();
}
});
}
}
package com.company;
import com.toedter.calendar.JDateChooser;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.util.Random;
public class Normal {
private JPanel normal;
private JButton BOOKNOWButton;
private JButton HOMEButton;
private JPanel datePanel;
private JLabel seats2;
private static int a =100;
JDateChooser dateChooser = new JDateChooser();
JFrame normalF = new JFrame();
public Normal(){
normalF.setDefaultCloseOperation(normalF.EXIT_ON_CLOSE);
normalF.setContentPane(normal);
normalF.pack();
normalF.setLocationRelativeTo(null);
normalF.setVisible(true);
datePanel.add(dateChooser);
seats2.setText(String.valueOf(a));
HOMEButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
normalF.dispose();
new MainGUI();
}
});
BOOKNOWButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(dateChooser.getDate()==null){
JOptionPane.showMessageDialog(null,"PLEASE CHOOSE A DATE");
}else {
String strDate = DateFormat.getDateInstance().format(dateChooser.getDate());
JOptionPane.showMessageDialog(null, "TICKETS BOOKED SUCCESSFULLY!");
JOptionPane.showMessageDialog(null, "MATCH IS ON: " + strDate + " & YOUR SEAT NO IS: " + seatNo());
a--;
String a1 = String.valueOf(a);
seats2.setText(a1);
}
}
});
}
public String seatNo(){
Random random = new Random();
int a = random.nextInt(100);
return String.valueOf(a);
}
}
package com.company;
import com.toedter.calendar.JDateChooser;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.util.Random;
public class EndStands {
private JPanel endStand;
private JButton HOMEButton;
private JButton BOOKNOWButton;
private JPanel endDate;
private JLabel seats1;
private static int a=100;
JFrame endF = new JFrame();
JDateChooser endDate1 = new JDateChooser();
public EndStands() {
endF.setDefaultCloseOperation(endF.EXIT_ON_CLOSE);
endF.setContentPane(this.endStand);
endF.pack();
endF.setLocationRelativeTo(null);
endF.setVisible(true);
endDate.add(endDate1);
seats1.setText(String.valueOf(a));
HOMEButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
endF.dispose();
new MainGUI();
}
});
BOOKNOWButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(endDate1.getDate()==null){
JOptionPane.showMessageDialog(null,"PLEASE CHOOSE A DATE");
}else {
String strDate = DateFormat.getDateInstance().format(endDate1.getDate());
JOptionPane.showMessageDialog(null, "TICKETS BOOKED SUCCESSFULLY!");
JOptionPane.showMessageDialog(null, "MATCH IS ON: " + strDate + " & YOUR SEAT NO IS: " + seatNo());
a--;
String a1 = String.valueOf(a);
seats1.setText(a1);
}
}
});
}
public String seatNo(){
Random random = new Random();
int a = random.nextInt(100);
return String.valueOf(a);
}
}
 package com.company;
import com.toedter.calendar.JDateChooser;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.util.Random;
public class RingSide {
private JPanel ringSide;
private JButton HOMEButton;
private JButton BOOKNOWButton;
private JPanel ringdate;
private JLabel seats;
private static int a =100;
JFrame ringF = new JFrame();
JDateChooser ringDate = new JDateChooser();
public RingSide() {
ringF.setDefaultCloseOperation(ringF.EXIT_ON_CLOSE);
ringF.setContentPane(ringSide);
ringF.pack();
ringF.setLocationRelativeTo(null);
ringF.setVisible(true);
ringdate.add(ringDate);
seats.setText(String.valueOf(a));
HOMEButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ringF.dispose();
new MainGUI();
}
});
BOOKNOWButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(ringDate.getDate()==null){
JOptionPane.showMessageDialog(null,"PLEASE CHOOSE A DATE ");
}
String strDate = DateFormat.getDateInstance().format(ringDate.getDate());
JOptionPane.showMessageDialog(null,"TICKETS BOOKED SUCCESSFULLY!");
JOptionPane.showMessageDialog(null,"MATCH IS ON: "+strDate+" & YOUR SEAT NO IS: "+seatNo());
a--;
String a1 = String.valueOf(a);
seats.setText(a1);
}
});
}
public String seatNo(){
Random random = new Random();
int a = random.nextInt(100);
return String.valueOf(a);
}
}

 

Explanation of the Code

Firstly GUI:

1. The main page consists of 3 buttons named Normal, End stands & Ringside, which will redirect to respective screens.

2. Each screen consists of 3 JLablels with seats available, Fare & Date of Game information. It has 2 buttons, one for redirecting to the main page and the other for booking a seat.

3. It also has a Jcalendar to select the date of the game.

Moving to the seat booking, we will apply the following rules:

1. Generate a random number between the range 1 to 100; that will be our seat number.

2. Showing popup with confirmation of seat booking.

3. Finally, updating the seats available on the home screen.

Output

Main Interface

Stadium Seat Booking System In Java | Java Project

Normal Seat Interface

Stadium Seat Booking System In Java | Java Project

Ringside Seat Interface

Stadium ring side Seat Booking

End Stand Seat Interface

Conclusion

We have implemented this tutorial of a Stadium Seat Booking System In Java that helps to book a seat for a game on a particular day using the Swing module. This is a very quick way to get your seats booked for a game you don’t want to miss out on!

More Java Projects>>>>>

You May Also Like To Create…

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *