⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 电子秤.txt

📁 一个适用于超市的电子秤系统
💻 TXT
📖 第 1 页 / 共 2 页
字号:
        }

    }

    public void actionPerformed(ActionEvent e) {

        if (e.getSource() == bt11) {
            i++;
            this.second();
            if (wupin.equals(jcb.getSelectedItem().toString())) {
                double dan = Double.parseDouble(danjia);
                jine[i] = dan * Integer.parseInt(tf12.getText());
                tr2.append("您购买了" + tf12.getText() + "千克的" +
                           jcb.getSelectedItem().toString() + "应付款" +
                           jine[i] + "元" +
                           "\n");

                tf12.setText("");
            } else {
                JOptionPane.showMessageDialog(this, "您所要购买的物品不存在,请重新输入");
            }
        }
        if (e.getSource() == bt30) {
            for (int c = i; c > 0; c--) {
                sum = sum + jine[c];
            }
            tr2.append("您总共购买了" + sum + "元的物品,请你付账" + "\n");
        }
        if (e.getSource() == bt31) {
            if (aa == 1 && !(tr2.getText().equals(""))) {

                Shuaka shua = new Shuaka();
                shua.setVisible(true);
                this.dispose();

            } else if (aa == 2 && !(tr2.getText().equals(""))) {

                Xianjin xianjin = new Xianjin();
                xianjin.setVisible(true);
                this.setVisible(false);

            } else if (tr2.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "您还未进行购物,请先购物在付账");
            } else if (aa == 0) {
                JOptionPane.showMessageDialog(this, "您还未选择支付方式,请先选择付款方式");
            }

        }
        if (e.getSource() == bt32) {
            Gouwu gou = new Gouwu();
            gou.setVisible(true); //实现清屏
        }
        if (e.getSource() == bt33) {
            this.setVisible(false);
            Denglu deng = new Denglu();
            deng.setVisible(true);
        }
    }

    private class Win extends WindowAdapter {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    }


    public static void main(String[] args) {
        Gouwu gouwu = new Gouwu();
        gouwu.setVisible(true);
    }

    //实现数据库链接
    public void second() {

        String ur1 = "jdbc:odbc:db2Access";

        Connection conn;
        Statement statement;
        ResultSet resultSet = null;
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            conn = DriverManager.getConnection(ur1, "", "");
            statement = conn.createStatement();
            query = "select*from  物品单价 ";
            resultSet = statement.executeQuery(query);
            while (resultSet.next()) {
                wupin = resultSet.getString("品名");
                danjia = resultSet.getString("单价");

                if (jcb.getSelectedItem().toString().equals(wupin)) {
                    break;
                }
            }
            resultSet.close();
            statement.close();
            conn.close();

        } catch (Exception e) {
            e.printStackTrace();

        }

    }
}









package chaoshi;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class Shuaka extends JDialog implements ActionListener {
    JPanel pan1 = new JPanel();
    JPanel pan2 = new JPanel();
    JPanel pan3 = new JPanel();
    JPanel pan4 = new JPanel();
    JPanel pan5 = new JPanel();
    JPanel pan6 = new JPanel();
    JPanel pan7 = new JPanel();
    JLabel lab1 = new JLabel("卡号");
    JLabel lab2 = new JLabel("密码");
    JLabel lab4 = new JLabel("卡中剩余金额");
    JLabel lab51 = new JLabel("应付金额");
    JLabel lab52 = new JLabel("实需付金额");
    JLabel lab6 = new JLabel("消费积分");
    JButton bt31 = new JButton("确定");
    JButton bt32 = new JButton("取消");
    JButton bt33=new JButton("冲值");
    JButton bt51 = new JButton("确定付款");
    JButton bt52 = new JButton("返回");
    JTextField tf1 = new JTextField(20);
    JPasswordField tf2 = new JPasswordField(20);
    JTextField tf4 = new JTextField(15);
    JTextField tf51 = new JTextField(10);
    JTextField tf52 = new JTextField(10);
    JTextField tf6 = new JTextField(15);
    double c,d;
    String query;
    int kahao, mima;
   double shengyu, jifen;
    int a = 0;
    double m;
    Gouwu gou1 = null;
    public Shuaka() {
        this.setSize(400, 400);
        this.setLocation(100, 100);
        this.addWindowListener(new Win());
        this.getContentPane().setLayout(new GridLayout(7, 1));
        this.getContentPane().add(pan1);
        this.getContentPane().add(pan2);
        this.getContentPane().add(pan3);
        this.getContentPane().add(pan4);
        this.getContentPane().add(pan5);
        this.getContentPane().add(pan6);
        this.getContentPane().add(pan7);
        pan1.add(lab1);
        pan1.add(tf1);
        pan2.add(lab2);
        pan2.add(tf2);
        pan3.add(bt31);
        bt31.addActionListener(this);
        pan3.add(bt32);
        bt32.addActionListener(this);
        pan3.add(bt33);
        bt33.addActionListener(this);
        pan4.add(lab4);
        pan4.add(tf4);

        pan5.add(lab51);
        pan5.add(tf51);
        pan5.add(lab52);
        pan5.add(tf52);
        pan6.add(lab6);
        pan6.add(tf6);
        pan7.add(bt51);
        bt51.addActionListener(this);
        pan7.add(bt52);
        bt52.addActionListener(this);
        tf4.setEditable(false);
        tf51.setEditable(false);
        tf52.setEditable(false);
        tf6.setEditable(false);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == bt31) {
            a = 1;
            second();
            if (Integer.toString(mima).equals(tf2.
                                getText())) {
            tf4.setText(Double.toString(shengyu));
            tf51.setText(Double.toString(c));
            }
        }

        if (e.getSource() == bt32) {
            tf1.setText(null);
            tf2.setText(null);
            tf4.setText(null);
            tf51.setText(null);
            tf52.setText(null);
        }
        if(e.getSource()==bt33){
         Chongzhi chong=new Chongzhi();
        chong.setVisible(true);
     }

        if (e.getSource() == bt51) {
            a = 2;
            this.second();

            this.third();
           this.dispose();
        }


        if (e.getSource() == bt52) {
            this.setVisible(false);
            Gouwu gou = new Gouwu();
            gou.setVisible(true);
        }

    }

    private class Win extends WindowAdapter {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    }


    public static void main(String[] args) {
        Shuaka shuaka = new Shuaka();
        shuaka.setVisible(true);
    }

    //下面是数据库的链接
    public void second() {

        String ur1 = "jdbc:odbc:db2Access";

        Connection conn;
        Statement statement;
        ResultSet resultSet = null;
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            conn = DriverManager.getConnection(ur1, "", "");
            statement = conn.createStatement();
            query = "select*from  支付卡 ";
            resultSet = statement.executeQuery(query);
            while (resultSet.next()) {
                c = gou1.sum;
                kahao = resultSet.getInt("卡号");
                mima = resultSet.getInt("密码");
                shengyu = resultSet.getDouble("卡中金额");
                jifen = resultSet.getDouble("消费积分");

                if (a == 1) {
                    if (Integer.toString(kahao).equals(tf1.getText())) {

                        if (Integer.toString(mima).equals(tf2.
                                getText())) {
                            if (jifen >= 0 && jifen < 100) {
                                tf52.setText(Double.toString(c));
                            } else if (jifen >= 100) {
                                tf52.setText(Double.toString(c * 0.95));
                            } else if (jifen > 100 && jifen < 500) {
                                tf52.setText(Double.toString(c * 0.9));
                            } else if (jifen >= 500 && jifen < 1000) {
                                tf52.setText(Double.toString(c * 0.85));

                            } else if (jifen >= 1000 && jifen < 5000) {
                                tf52.setText(Double.toString(c * 0.8));
                            } else if (jifen >= 5000) {
                                tf52.setText(Double.toString(c * 0.75));
                            }
                            d=jifen+Double.parseDouble(tf52.getText());
                            tf6.setText(Double.toString(jifen));
                            break;
                        } else if (!Integer.toString(mima).equals(tf2.
                                getText())) {
                            JOptionPane.showMessageDialog(this,
                                    "密码不正确,请重新输入");
                        }
                    }

                }
                if (a == 2) {
                    if (Integer.toString(kahao).equals(tf1.getText())) {

                        if (Integer.toString(mima).equals(tf2.getText())) {
                            m = shengyu - Double.parseDouble(tf52.getText());

                            if (m < 0) {

                                JOptionPane.showMessageDialog(this,
                                        "卡中金额不足,请再付" + (c - m) + "元的现金");
                                m = 0;
                            } else if (m > 0) {

                                JOptionPane.showMessageDialog(this, "付款成功!");

                            }
                            break;
                        } else if (!Integer.toString(mima).equals(tf2.
                                getText())) {
                            JOptionPane.showMessageDialog(this,
                                    "密码不正确,请重新输入");
                        }
                    }

                }
            }

            resultSet.close();
            statement.close();
            conn.close();

        } catch (Exception e) {
            e.printStackTrace();

        }

    }

    //再次连接数据库,将其更新,插入消费后的卡中金额

    public void third() {

        String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
        String ur1 = "jdbc:odbc:db2Access";

        Connection conn;

        Statement statement;

        try {

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            conn = DriverManager.getConnection(ur1, "", "");

            statement = conn.createStatement();
            statement.executeUpdate("update 支付卡 set 卡中金额=" + m +
                                    " where 卡号=" +
                                    tf1.getText());
            statement.executeUpdate("update 支付卡 set 消费积分=" + d +
                                    " where 卡号=" +
                                    tf1.getText());

        } catch (Exception e) {
            e.printStackTrace();

        }
    }
}








package chaoshi;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Guanli extends JDialog implements ActionListener {
    JPanel pan1 = new JPanel();
    JPanel pan2 = new JPanel();
    JPanel pan3 = new JPanel();
    JButton bt1 = new JButton("查看本日的营业总额");
    JButton bt2 = new JButton("查看物品的销售状况");

    public Guanli() {
        this.setTitle("销售状况");
        this.setSize(400, 400);
        this.setLocation(100,100);
        this.getContentPane().setLayout(new GridLayout(2,1));
        this.getContentPane().add(pan1);
        pan1.add(bt1);
        bt1.addActionListener(this);
        this.getContentPane().add(pan2);
        pan2.add(bt2);
        bt2.addActionListener(this);

    }
    private class Win extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }
}


    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == bt1) {

        }
        if (e.getSource() == bt2) {

        }

    }

    public static void main(String[] args) {
        Guanli guanli = new Guanli();
        guanli.setVisible(true);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -