Home Java Bakery Management System Project using Java

Bakery Management System Project using Java

6 min read
0
0
0

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();
Load More Related Articles
Load More By admin
Load More In Java

Leave a Reply

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

Check Also

Student Rank Calculation System using Java

In this tutorial i am going to teach the Rank Calculation System using Java step by step. …