Java

Movie Ticket Booking System in Java mysql

The Movie Ticket Book Inventory Management System is developed using Java and mysql.java best practice is must if you interested in java. The project is built to manage sales and transactions. To make a new transaction, fields such as: Movie Ticket type, qty,price and payment needs to be selected. If you like to learn point of sales systems step by step, this is the right place to learn from the beginning.

In this tutorial, you will learn  jasper reports step by step and designing the java print receipt.java coding practices is very important  for us to grow the knowledge in java day by day. how to be a good programmer in the future. Let go and learn the java mini projects step by step.i have attached the complete project video also how the flow works step by step below.

In order to create the system we have used NetBeans IDE and Mysql database as a backend.

Features

  1. Point of Sales
  2. Stock Management
  3. Java Receipt

Learn how to make this System Step by step

The first step Create the database named with “movieticket“. then established the database connection to download the mysql connector in order to connect Java & mysql.if you don’t  have an idea about  download the mysql connector you can follow this link.

To connect the database please refer the following code. To create the method name connect (); paste the below code inside the Connect () method.

public void Connect()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver"); // Register the mysql driver
            con = DriverManager.getConnection("jdbc:mysql://localhost/

movieticket

","root","");    
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
           ex.printStackTrace();
        }
    }

The system shall be able to select the relevant Movie ticket type.

 

Add the Product details into the JTable

After selected the relevant rice type the user has the option to add the qty by clicking the add button to see all Products details which will be shown in the below table.

Paste this code inside the add button

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) 
{                                         
        int sum = 0;
        int price;
        int qty;
        int tot;
        
        if(chk1.isSelected())
        {
            String odc = chk1.getText();
            price = 300;
            qty = Integer.parseInt(txtodc.getValue().toString());
             tot = price * qty;
             model = (DefaultTableModel)jTable1.getModel();
             model.addRow(new Object[] 
            {
                 odc,
                 price,
                 qty,
                 tot
             });
        }
        
        if(chk2.isSelected())
        {
            String Balcony = chk2.getText();
            price = 350;
            qty = Integer.parseInt(txtbalcony.getValue().toString());
             tot = price * qty;
             model = (DefaultTableModel)jTable1.getModel();
             model.addRow(new Object[] 
            {
                 Balcony,
                 price,
                 qty,
                 tot
             });  
        }
        
         if(chk3.isSelected())
        {
            String Box = chk3.getText();
            price = 400;
            qty = Integer.parseInt(txtbox.getValue().toString());
             tot = price * qty;
             model = (DefaultTableModel)jTable1.getModel();
             model.addRow(new Object[] 
            {
                 Box,
                 price,
                 qty,
                 tot
             });  
        }
        
        if(chk4.isSelected())
        {
            String Superbal = chk4.getText();
            price = 500;
            qty = Integer.parseInt(txtsbalcony.getValue().toString());
             tot = price * qty;
             model = (DefaultTableModel)jTable1.getModel();
             model.addRow(new Object[] 
            {
                 Superbal,
                 price,
                 qty,
                 tot
             });   
        }
        
        for(int i=0; i<jTable1.getRowCount(); i++)
        {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());
        }
        txtsub.setText(String.valueOf(sum));
    }

Calculating the Total and balance

After that  create the method Sales().we have to create two different tables to store data into the database.we also have to create the following tables from database.
sales tables consist of following colums – id,subtotal,pay,balance.
sales_products tables consist of following colums –id,sales_id,tickettype,qty,price,total

 public void sales() 
    {
        try {      
        String subtotal = txtsub.getText();
        String pay = txtpay.getText();
        String tot = txtbal.getText();
        
        int lastid =0;
        
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/movieticket","root","");
            String query = "insert into sales(subtotal,pay,balance)values(?,?,?)";
            ps1 = con.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);
            
            ps1.setString(1, subtotal);
            ps1.setString(2, pay);
            ps1.setString(3, tot);
            ps1.executeUpdate();
            
            ResultSet rs = ps1.getGeneratedKeys();
            
            if(rs.next())
            {
                lastid = rs.getInt(1);
            } 
            int rows = jTable1.getRowCount();
            
            String query1 = "insert into sales_product(sales_id,tickettype,qty,price,total)values(?,?,?,?,?)";
            ps2 = con.prepareStatement(query1);
            
            String tickettype = "";
            int price;
            int qty;
            int total = 0;
            
            for(int i=0; i<jTable1.getRowCount(); i++)
            {
                tickettype = (String)jTable1.getValueAt(i, 0);
                price = (int)jTable1.getValueAt(i, 1);
                qty = (int)jTable1.getValueAt(i, 2);
                total = (int)jTable1.getValueAt(i, 3);
                 ps2.setInt(1,lastid);
                 ps2.setString(2,tickettype);
                 ps2.setInt(3,qty);
                 ps2.setInt(4,price);
                 ps2.setInt(5,total);
                 ps2.executeUpdate();
 
            }
            
            JOptionPane.showMessageDialog(this, "Sales Completeeeeee");
            
            
            HashMap a = new HashMap();
            a.put("invo", lastid);
            
            try {
                JasperDesign jdesign = JRXmlLoader.load("C:\\Users\\kobinath\\Documents\\NetBeansProjects\\Movieticket\\src\\movieticket\\report1.jrxml");
                JasperReport jreport = JasperCompileManager.compileReport(jdesign);
                
                JasperPrint jprint = JasperFillManager.fillReport(jreport, a,con);
                
                JasperViewer.viewReport(jprint);
 
            } catch (JRException ex) {
                Logger.getLogger(movieticket.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(movieticket.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(movieticket.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

Call the Sales() method inside the Print Invoice button. after calculating the total Print receipt will be released. This print receipt designed by Jsper Reporting.

Paste this code inside the Print Invoice button

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) 
    {                                          
        int sub = Integer.parseInt(txtsub.getText());
        int pay = Integer.parseInt(txtpay.getText());
        int bal = pay - sub;
        txtbal.setText(String.valueOf(bal));
        sales();

    }

 

I have attached the video tutorial below it will help you  to do this  step by step.java projects with source codes will help you to learn java.

 

 

 

 

admin

Recent Posts

Creating Grocery Inventory App Using React

Introduction to Grocery Inventory Apps Managing grocery inventory can be a daunting task, but with…

2 days ago

Fish Inventory Shop Management System in Angular

This article explain how to make a Fish Inventory Management App in Angular.this app explain…

1 week ago

Fish Inventory Management with React

Introduction to Fish Inventory Management In the aquaculture industry, managing fish inventory is crucial for…

1 week ago

Java GUI CRUD for Beginners

Introduction to Java GUI CRUD Java is a powerful programming language widely used for building…

1 week ago

Creating Beautiful Login Form Design Using React

Introduction to Login Form Design Designing an effective and beautiful login form is crucial for…

2 weeks ago

Creating Responsive Login Form with React

Introduction In today creating a responsive login form is essential for providing a seamless user…

2 weeks ago