Design and implementation of supermarket commodity management system based on Mysql+JavaSwing

Design and implementation of supermarket commodity management system based on Mysql+JavaSwing

Preface:

As small supermarkets continue to expand in size, the number of goods has increased dramatically, and the amount of information about the goods has also increased exponentially. Supermarkets need to conduct statistical analysis on various product information at all times. However, the functions of large supermarket management systems are too powerful, which makes the operation cumbersome and reduces the work efficiency of small supermarkets. Supermarket management system is one of the most popular systems commonly used in supermarkets on the market. Since I have just learned Java knowledge, all functions are designed to be relatively simple, with only the addition, deletion, modification and query of product information. Realize comprehensive, dynamic and timely management of product information. This paper systematically analyzes the background and process of software development; first, it introduces the software development environment, and then introduces the detailed design process of this software: database design, design and implementation of each module, as well as the design and functions of specific interfaces. The supermarket inventory management system is based on Java eclipse as the development tool and Mysql as the backend database support. The development of supermarket inventory management system mainly involves the development of interface programs, the establishment of databases, and the maintenance of databases. The application should have complete functions, good human-computer interaction interface, and be easy to operate. At the same time, the JAVASwing language is simple, and it is possible to develop a program that is highly usable, fully functional, and easy to operate in a relatively short period of time, and it can also achieve connection with the database.

Main modules:

Product list data display, product information addition, product information modification, product information deletion, product information query by product name

1. Function Introduction

Functional screenshots:

Query product list information:

Add product information:

Modify product information:

Delete product information:

After deleting, you need to refresh the list data

​Query product information by number:

2. Key code

2.1 Home page functions

public class GoodsManage extends JFrame {
 private JTextField textField;
 Select select = new Select();
 Updata updata = new Updata();
 Object[] header= {"Product Number","Product Name","Quantity","Unit Price"};
 String sql = "SELECT goodsID,goodsname,num,price FROM goods";
 Object[][] data= select.getGoods(sql);
 DefaultTableModel df = new DefaultTableModel(data, header);
 int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
 int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
 
 public GoodsManage() {
  super("Product Management System");
  this.setBounds(0, 0, 700, 450);
  this.setLocationRelativeTo(null);//Let the window be displayed in the middle of the screen this.setResizable(false);//Let the window size not be changed getContentPane().setLayout(null);
  
  JTable jTable = new JTable(df);
  JScrollPane jsp=new JScrollPane(jTable,v,h);
  jsp.setBounds(10, 10, 515, 320);
  getContentPane().add(jsp);
  
  JButton button_1 = new JButton("Show all products");
  button_1.addActionListener(new ActionListener() {
   @Override
   public void actionPerformed(ActionEvent e) {
    String sql = "SELECT goodsID,goodsname,num,price FROM goods";
    Object[][] data = Select.getGoods(sql);
    df.setDataVector(data, header);
   }
  });
 
  button_1.setBounds(535, 80, 127, 30);
  getContentPane().add(button_1);
  
  JButton button_2 = new JButton("Modify product");
  button_2.setBounds(535, 140, 127, 30);
  getContentPane().add(button_2);
  button_2.addActionListener(new ActionListener() {
   @Override
   public void actionPerformed(ActionEvent e) {
    if (jTable.getSelectedColumn()<0) {
     JOptionPane.showMessageDialog(null, "Please select the data to be modified!");
    } else {
     int goodsID = Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 0).toString());
     String name = jTable.getValueAt(jTable.getSelectedRow(), 1).toString();
     int num = Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 2).toString());
     String price = jTable.getValueAt(jTable.getSelectedRow(), 3).toString();
     Goods goods = new Goods(goodsID,name,num,price);
     GoodsXG goodsXG = new GoodsXG(goods);
     goodsXG.setVisible(true);
    }
    
   }
  });
  
  JButton button_3 = new JButton("Delete product");
  button_3.setBounds(535, 200, 127, 30);
  getContentPane().add(button_3);
  button_3.addActionListener(new ActionListener() {
   @Override
   public void actionPerformed(ActionEvent e) {
    if (jTable.getSelectedColumn()<0) {
     JOptionPane.showMessageDialog(null, "Please select the data to be deleted!");
    } else {
     int goodsID = Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 0).toString());
     String sql="delete from goods where goodsid="+goodsID;
     int result = updata.addData(sql);
     if (result>0) {
      JOptionPane.showMessageDialog(null, "Deleted successfully!");
      JOptionPane.showMessageDialog(null, "Remember to refresh!");
     } else {
      JOptionPane.showMessageDialog(null, "Delete failed!");
     }
    }
   }
  });
  
  JButton button_4 = new JButton("Add product");
  button_4.setBounds(535, 258, 127, 30);
  getContentPane().add(button_4);
  button_4.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent arg0) {
    GoodsADD goodsAdd = new GoodsADD();
    goodsAdd.setVisible(true);
   }
  });
  
  JLabel label = new JLabel("Product Number:");
  label.setBounds(40, 354, 112, 32);
  getContentPane().add(label);
  
  textField = new JTextField();
  textField.setBounds(154, 358, 127, 26);
  getContentPane().add(textField);
  textField.setColumns(10);
  
  JButton button = new JButton("Query by number");
  button.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent arg0) {
    String sql = "SELECT goodsID,goodsname,num,price FROM goods WHERE goodsid LIKE '%"+textField.getText()+"%'";
    Object[][] data = Select.getGoods(sql);
    df.setDataVector(data, header);
   }
  });
  button.setBounds(305, 355, 112, 30);
  getContentPane().add(button);
  
  this.addWindowListener(new WindowAdapter() {
    
   public void windowClosing(WindowEvent e) {
    super.windowClosing(e);
    //Add action GoodsManagement m = new GoodsManagement();
    m.setVisible(true);
    }
  });
 }
 
 public static void main(String[] args) {
  GoodsManage t = new GoodsManage();
  t.setVisible(true);
 }
}

2.2 Add product information

public class GoodsADD extends JFrame {
 private JTextField id,name,num,price;
 private JButton button;
 private JButton button_1;
 
 public GoodsADD() {
  super("Product Management System");
  this.setBounds(0, 0, 400, 450);
  this.setLocationRelativeTo(null);//Let the window be displayed in the middle of the screen this.setResizable(false);//Let the window size not be changed getContentPane().setLayout(null);
  
  JLabel label = new JLabel("Product Number:");
  label.setBounds(85, 89, 87, 22);
  getContentPane().add(label);
  
  id = new JTextField();
  id.setBounds(147, 90, 142, 21);
  getContentPane().add(id);
  id.setColumns(10);
  
  JLabel label_1 = new JLabel("Product Name");
  label_1.setBounds(85, 139, 87, 22);
  getContentPane().add(label_1);
  
  name = new JTextField();
  name.setColumns(10);
  name.setBounds(147, 140, 142, 21);
  getContentPane().add(name);
  
  JLabel label_2 = new JLabel("Quantity:");
  label_2.setBounds(85, 193, 87, 22);
  getContentPane().add(label_2);
  
  num = new JTextField();
  num.setColumns(10);
  num.setBounds(147, 194, 142, 21);
  getContentPane().add(num);
  
  JLabel label_3 = new JLabel("Unit price:");
  label_3.setBounds(85, 241, 87, 22);
  getContentPane().add(label_3);
  
  price = new JTextField();
  price.setColumns(10);
  price.setBounds(147, 242, 142, 21);
  getContentPane().add(price);
  
  button = new JButton("OK");
  button.setBounds(78, 317, 93, 23);
  getContentPane().add(button);
  button.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent arg0) {
    String addId = id.getText();
    String addName = name.getText();
    String addNum = num.getText();
    String addPrice = num.getText();
    if (addName.equals("")||addName.equals("")||addNum.equals("")||addPrice.equals("")) {
     JOptionPane.showMessageDialog(null, "Please enter the data to be added completely");
    } else {
     String sql="INSERT INTO goods VALUES("+addId+",'"+addName+"','"+addNum+"','"+addPrice+"')";
     int result = Updata.addData(sql);
     if (result>0) {
      JOptionPane.showMessageDialog(null, "Added successfully!");
                  JOptionPane.showMessageDialog(null, "Remember to refresh!");
      dispose();
//GoodsManage i = new GoodsManage();
// i.setVisible(true);
     } else {
      JOptionPane.showMessageDialog(null, "Add failed!");
     }
    }
 
   }
  });
  
  button_1 = new JButton("Cancel");
  button_1.setBounds(208, 317, 93, 23);
  getContentPane().add(button_1);
  button_1.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent arg0) {
    dispose();
   }
  });
  
 }
}

2.3 Database Design

Product List

CREATE TABLE `NewTable` (
`goodsID` int(11) NOT NULL ,
`goodsName` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`num` int(11) NOT NULL ,
`price` decimal(10,4) NOT NULL ,
PRIMARY KEY (`goodsID`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
ROW_FORMAT=COMPACT
;

This is the end of this article about the design and implementation of a supermarket merchandise management system于Mysql+JavaSwing . For more information about the design and implementation of a supermarket merchandise management system based on Mysql+JavaSwing , please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Java (swing) + mysql to implement student information management system source code
  • Java+MySQL implements library management system (complete code)
  • Java implements tea sales mall system (java+SSM+JSP+EasyUi+mysql)
  • Eclipse+Java+Swing+MySQL to implement salary management system
  • Eclipse+Java+Swing+MySQL to implement movie ticket purchasing system (detailed code)
  • Java+swing+Mysql to implement commodity sales management system
  • Design coupon system by Java+MySQL

<<:  7 cool dynamic website designs for inspiration

>>:  24 Practical JavaScript Development Tips

Recommend

WeChat applet development form validation WxValidate usage

I personally feel that the development framework ...

About uniApp editor WeChat sliding problem

The uniapp applet will have a similar drop-down p...

Collapsed table row element bug

Let's take an example: The code is very simple...

How to add a certificate to docker

1. Upgrade process: sudo apt-get update Problems ...

Docker builds jenkins+maven code building and deployment platform

Table of contents Docker Basic Concepts Docker in...

How to get the size of a Linux system directory using the du command

Anyone who has used the Linux system should know ...

Vue uses better-scroll to achieve horizontal scrolling method example

1. Implementation principle of scrolling The scro...

Detailed explanation of how MySQL (InnoDB) handles deadlocks

1. What is deadlock? The official definition is a...

JS implementation of carousel carousel case

This article example shares the specific code of ...

How to set MySQL foreign keys for beginners

Table of contents The role of foreign keys mysql ...

The difference between Vue interpolation expression and v-text directive

Table of contents 1. Use plugin expressions 2. Us...

What are your principles for designing indexes? How to avoid index failure?

Table of contents Primary key index Create indexe...