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

📄 listsaleframe.java

📁 超市管理系统 运行环境JDK1.4以上 JB2006 源代码公开
💻 JAVA
字号:
package com.aptech.view;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Connection;
import com.aptech.connection.Tosql;

public class ListsaleFrame extends JFrame {
    String year;
    String month;
    String date;
    public ListsaleFrame(String year,String month,String date) {
        try {
            this.year=year;
            this.month=month;
            this.date=date;
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }


    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        jLabel1.setFont(new java.awt.Font("黑体", Font.BOLD, 22));
        jLabel1.setForeground(Color.red);
        jLabel1.setText("销售明细");
        setTitle("一切为了顾客");
        jLabel1.setBounds(new Rectangle(144, 13, 103, 29));
        this.getContentPane().setBackground(new Color(0, 250, 190));
        jLabel3.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
        jLabel3.setBounds(new Rectangle(154, 48, 161, 26));
        jLabel2.setForeground(Color.blue);
        jScrollPane1.setBounds(new Rectangle(10, 84, 383, 133));
        jButton1.setBackground(Color.cyan);
        jButton1.setBounds(new Rectangle(51, 230, 121, 22));
        jButton1.setText("浏览");
        jButton1.addActionListener(new ListsaleFrame_jButton1_actionAdapter(this));
        jTable1.setBackground(Color.yellow);
        jButton2.setBackground(Color.cyan);
        jButton2.setBounds(new Rectangle(237, 231, 121, 22));
        jButton2.setText("返回管理界面");
        jButton2.addActionListener(new ListsaleFrame_jButton2_actionAdapter(this));
        this.getContentPane().add(jLabel1);
        this.getContentPane().add(jLabel2);
        this.getContentPane().add(jLabel3);
        this.getContentPane().add(jScrollPane1);
        this.getContentPane().add(jButton1);
        this.getContentPane().add(jButton2);
        jScrollPane1.getViewport().add(jTable1);
        jLabel2.setText("日期:");
        jLabel2.setBounds(new Rectangle(87, 49, 65, 24));
        if(Integer.parseInt(month)<10&&Integer.parseInt(date)<10){
            jLabel3.setText(year+"-"+"0"+month+"-"+"0"+date);
        }
        else if(Integer.parseInt(month)>=10&&Integer.parseInt(date)>=10){
           jLabel3.setText( year+"-"+month+"-"+date);
        }
        else if(Integer.parseInt(month)>=10&&Integer.parseInt(date)<10){
            jLabel3.setText (year+"-"+month+"-"+"0"+date);
        }
        else if(Integer.parseInt(month)<10&&Integer.parseInt(date)>=10){
            jLabel3.setText(year+"-"+"0"+month+"-"+date);
        }






    }

    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JScrollPane jScrollPane1 = new JScrollPane();
    Object[][] cells = { {"", "", "", "", "", "", "", ""}, {"", "", "", "", "",
                       "", "", ""}, {"", "", "", "", "", "", "", ""}, {"", "",
                       "", "", "", "", "", ""}, {"", "", "", "", "", "", "", ""},
                       {"", "", "", "", "", "", "", ""}, {"", "", "", "", "",
                       "", "", ""}, {"", "", "", "", "", "", "", ""}, {"", "",
                       "", "", "", "", "", ""}, {"", "", "", "", "", "", "", ""},
                       {"", "", "", "", "", "", "", ""}, {"", "", "", "", "",
                       "", "", ""}, {"", "", "", "", "", "", "", ""}, {"", "",
                       "", "", "", "", "", ""}, {"", "", "", "", "", "", "", ""},
                       {"", "", "", "", "", "", "", ""}, {"", "", "", "", "",
                       "", "", ""}, {"", "", "", "", "", "", "", ""}
    };
    String[] colnames = {"商品编号", "商品名称", "数量", "金额", "会员", "销售时间"};

    JTable jTable1 = new JTable(cells,colnames);
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    public void jButton2_actionPerformed(ActionEvent e) {
        MainFrame mm=new MainFrame();
       mm.setSize(500,400);
       mm.setVisible(true);
       this.dispose();
       mm.setLocationRelativeTo(this);


    }

    public void jButton1_actionPerformed(ActionEvent e) {
         Tosql tt=new Tosql();
         Connection con=tt.tosql();
         String time=null;

        try {
            PreparedStatement ps = con.prepareStatement(
                    "select * from salegoods where saletime like '" +
                     jLabel3.getText()+"%'");
            ResultSet rs = ps.executeQuery();
            int i = 0;
            while (rs.next()) {
                rs.getString(1);
                jTable1.setValueAt(rs.getString(2), i, 0);
                jTable1.setValueAt(rs.getString(3), i, 1);
                jTable1.setValueAt(rs.getInt(4), i, 2);
                jTable1.setValueAt(rs.getFloat(5), i, 3);
                jTable1.setValueAt(rs.getInt(6), i, 4);
                jTable1.setValueAt(rs.getString(7), i, 5);
                i++;

            }
        } catch (SQLException ex) {
        }

    }

}


class ListsaleFrame_jButton2_actionAdapter implements ActionListener {
    private ListsaleFrame adaptee;
    ListsaleFrame_jButton2_actionAdapter(ListsaleFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
    }
}


class ListsaleFrame_jButton1_actionAdapter implements ActionListener {
    private ListsaleFrame adaptee;
    ListsaleFrame_jButton1_actionAdapter(ListsaleFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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