Java

Bakery Management System Project using Java

This tutorial will teach you how to make a Bakery Management System Project using Java in Java step by step. This system will helpful you to learn Inventory Management System.

Paste the Code inside the Buttons

DefaultTableModel model;
    
    String name;
    int a,tot;
     
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        int sum = 0;
        name = "Buger 1";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 1000 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               1000,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));   
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    
          int sum = 0;
        name = "Buger 2";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 1000 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               2000,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));   
        
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          int sum = 0;
        name = "Buger 3";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 1500 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               2000,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));   
        
        
        
        
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          int sum = 0;
        name = "cake 1";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 1000 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               500,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));   
        
    }                                        

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        
          int sum = 0;
        name = "cake 2";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 1000 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               2000,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));   
        
    }                                        

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         

          int sum = 0;
        name = "cake 3";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 3000 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               2000,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));      
        
    }

Create Print Function

private void printBill() {
        PrinterJob printerJob = PrinterJob.getPrinterJob();
        printerJob.setPrintable(new Printable() {
            @Override
            public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
                if (pageIndex > 0) {
                    return NO_SUCH_PAGE;
                }

                Graphics2D g2d = (Graphics2D) graphics;
                g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

                // Set the terminal receipt width and start printing content
                Font font = new Font("Monospaced", Font.PLAIN, 12);
                g2d.setFont(font);

                int y = 20;
                g2d.drawString("            Tutusfunny", 10, y);
                y += 20;
                g2d.drawString("--------------------------------", 10, y);
                y += 20;
                g2d.drawString(String.format("%-15s %5s %5s %10s", "Item", "Price", "Qy", "Total"), 10, y);
                y += 20;
                g2d.drawString("--------------------------------", 10, y);
                y += 20;

                for (int i = 0; i < model.getRowCount(); i++) {
                    String item = model.getValueAt(i, 0).toString();
                    String price = model.getValueAt(i, 1).toString();
                    String quantity = model.getValueAt(i, 2).toString();
                    String total = model.getValueAt(i, 3).toString();
                    g2d.drawString(String.format("%-15s %5s %8s %10s", item, price, quantity, total), 10, y);
                    y += 20;
                }

                g2d.drawString("--------------------------------", 10, y);
                y += 20;
                g2d.drawString("              Thanks Come again", 10, y);
                y += 20;
                g2d.drawString("--------------------------------", 10, y);

                return PAGE_EXISTS;
            }
        });

        boolean doPrint = printerJob.printDialog();
        if (doPrint) {
            try {
                printerJob.print();
            } catch (PrinterException ex) {
                ex.printStackTrace();
            }
        }
    }

Call the Print Function inside the Button

printBill();
admin

Recent Posts

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

2 weeks ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

1 month ago

Build Your First Responsive Login Form Using HTML and CSS FlexBox

Creating a responsive login form is a crucial skill for any web developer. In this…

1 month ago

Build Crud API with Laravel 12

In this tutorial will teach  Laravel 12 CRUD API  by step. Laravel  10 CRUD Application …

1 month ago

laravel 12 image upload tutorial

In this lesson we talk about laravel 12 image uploading and display the image step…

2 months ago

Laravel 12 CRUD Application

In this tutorial will teach Laravel 12 CRUD Application step by step. Laravel  12 CRUD…

2 months ago