4-Java swing jdbc DBUtils:自己設(shè)計(jì)功能的原創(chuàng)收銀管理系統(tǒng)【詩書畫唱】

目錄:本篇含Java部分的第8,9,10,,11個Java文件

8

package shouYinXiTong;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
public class glyShangPinTypeGuanLi extends JFrame {
class spTypeShiJian implements MouseListener, ActionListener {
public glyShangPinTypeGuanLi jieShou = null;
public spTypeShiJian(glyShangPinTypeGuanLi chuanTi) {
this.jieShou = chuanTi;
}
@Override
public void actionPerformed(ActionEvent arg0) {
String getWenZi = arg0.getActionCommand();
if (getWenZi.equals("查詢類型")) {
String typeName = jieShou.typeWenBenKaung.getText();
//chuanZhiFangFa:傳值方法
jieShou.chuanZhiFangFa(typeName);
} else if (getWenZi.equals("修改類型")) {
String sp_typeid = jieShou.txt_id.getText();
String sp_typename = jieShou.typeWenBenKaung.getText();
String sql = "update sp_type set sp_typename='" + sp_typename
+ "' where sp_typeid='" + sp_typeid + "'";
if (DBUtils.ZSG(sql)) {
jieShou.chuanZhiFangFa(null);
JOptionPane.showMessageDialog(null, "修改成功");
} else {
JOptionPane.showMessageDialog(null, "修改失敗,請重試");
}
} else if (getWenZi.equals("增加類型")) {
String spId = jieShou.txt_id.getText();
String sp_typename = jieShou.typeWenBenKaung.getText();
String sql = "insert into sp_type values('" + sp_typename + "')";
if (DBUtils.ZSG(sql)) {
jieShou.chuanZhiFangFa(null);
JOptionPane.showMessageDialog(null, "增加成功");
} else {
JOptionPane.showMessageDialog(null, "增加失敗,"
+ "商品名稱不可重復(fù)");
}
} else if (getWenZi.equals("清空")) {
jieShou.txt_id.setText("");
jieShou.typeWenBenKaung.setText("");
}
}
@Override
public void mouseClicked(MouseEvent arg0) {
if (arg0.getClickCount() == 2) {
int row = jieShou.biaoGe.getSelectedRow();
jieShou.txt_id.setText(jieShou.biaoGe.getValueAt(row, 0).toString());
jieShou.typeWenBenKaung.setText(jieShou.biaoGe.getValueAt(row, 1).toString());
} else if (arg0.isMetaDown()) {
int row = jieShou.biaoGe.getSelectedRow();
String id = jieShou.biaoGe.getValueAt(row, 0).toString();
String sql = "delete sp_type where sp_typeid='" + id + "'";
int num = JOptionPane.showConfirmDialog(null, "確定要冊除這條信息嗎?");
if (num == 0) {
if (DBUtils.ZSG(sql)) {
JOptionPane.showMessageDialog(null, "刪除成功");
jieShou.chuanZhiFangFa(null);
return;
} else {
JOptionPane.showMessageDialog(null, "出現(xiàn)了未知的錯誤,請重試");
}
}
}
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
public static JButton btn1, btn2, btn3, btn4 = null;
public static DefaultTableModel dtm = null;
public static JPanel jp1, jp2 = null;
public static JLabel typeIdWenZi, typeNameWenZi = null;
public static JTable biaoGe = null;
public static JTextField txt_id, typeWenBenKaung = null;
public glyShangPinTypeGuanLi() {
this.setTitle("管理員商品類型管理");
this.setLayout(null);
this.setSize(600, 600);
this.setLocationRelativeTo(null);
jp2 = new JPanel();
jp2.setLayout(null);
jp2.setBounds(368, 10, 200, 350);
jp2.setBorder(BorderFactory.createLineBorder(Color.gray));
typeIdWenZi = new JLabel("類型id:");
typeNameWenZi = new JLabel("類型名稱:");
typeIdWenZi.setBounds(10, 20, 70, 30);
typeNameWenZi.setBounds(10, 60, 70, 30);
jp2.add(typeIdWenZi);
jp2.add(typeNameWenZi);
txt_id = new JTextField();
txt_id.setEditable(false);
typeWenBenKaung = new JTextField();
txt_id.setBounds(65, 20, 120, 30);
typeWenBenKaung.setBounds(65, 60, 120, 30);
jp2.add(txt_id);
jp2.add(typeWenBenKaung);
btn1 = new JButton("查詢類型");
btn2 = new JButton("修改類型");
btn3 = new JButton("增加類型");
btn4 = new JButton("清空");
btn1.setBounds(10, 100, 80, 30);
btn2.setBounds(110, 100, 80, 30);
btn3.setBounds(10, 140, 80, 30);
btn4.setBounds(110, 140, 80, 30);
btn1.addActionListener(new spTypeShiJian(this));
btn2.addActionListener(new spTypeShiJian(this));
btn3.addActionListener(new spTypeShiJian(this));
btn4.addActionListener(new spTypeShiJian(this));
jp2.add(btn1);
jp2.add(btn2);
jp2.add(btn3);
jp2.add(btn4);
this.add(jp2);
this.setVisible(true);
chuanZhiFangFa(null);
}
public glyShangPinTypeGuanLi(Object object) {
// TODO Auto-generated constructor stub
}
public void chuanZhiFangFa(String str) {
if (jp1 != null) {
this.remove(jp1);
}
String sql = "select * from sp_type where 1=1";
if (str != null) {
sql += "and sp_typename like '%" + str + "%'";
}
Vector<Object> v_head = new Vector<Object>();
v_head.add("類型編號");
v_head.add("類型名稱");
Vector<Vector<Object>> v_body = new Vector<Vector<Object>>();
ResultSet res = DBUtils.Select(sql);
try {
while (res.next()) {
Vector<Object> v = new Vector<Object>();
v.add(res.getInt("sp_typeid"));
v.add(res.getString("sp_typename"));
v_body.add(v);
}
} catch (SQLException e) {
e.printStackTrace();
}
dtm = new DefaultTableModel(v_body, v_head) {
@Override
public boolean isCellEditable(int a, int b) {
return false;
}
};
biaoGe = new JTable(dtm);
biaoGe.addMouseListener(new spTypeShiJian(this));
JScrollPane jsp = new JScrollPane(biaoGe);
jsp.setBounds(0, 0, 350, 400);
jp1 = new JPanel();
jp1.setLayout(null);
jp1.add(jsp);
jp1.setBounds(8, 0, 350, 400);
this.add(jp1);
}
}

9

package shouYinXiTong;
public class gongjvClass {
public static String uname = " ";
}

10

package shouYinXiTong;
import org.jb2011.lnf.beautyeye.
BeautyEyeLNFHelper;
public class mains {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
BeautyEyeLNFHelper.frameBorderStyle =?
BeautyEyeLNFHelper.FrameBorderStyle
.osLookAndFeelDecorated;
org.jb2011.lnf.beautyeye.
BeautyEyeLNFHelper.launchBeautyEyeLNF();
} catch (Exception e) {
}
new DengLu();
}
}

11

package shouYinXiTong;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
public class ptGuKeDengLu extends JFrame {
public static JButton xiuGaiAnNiu, quXiaoAnNiu = null;
public static DefaultTableModel dtm = null;
static JButton qieHuanAnNiu,shangPinCaoZuoJButton, JButton2, geRenXinXiJButton, exitJButton = null;
static JPanel topMianBan, leftBottomMianBan,
qieHuanYongHuMianBan,?
geRenXinXiXiuGaiMianBan, tuiChuXiTongMianBan = null;
static JLabel lb_title, lb_uname, lb_pwd, lb_name, lb_sex, lb_phone,
imgJLabel = null;
static JRadioButton rb1, rb2 = null;
public static JTable tb1 = null;
static JTextField unameWenBenKuang, pwdWenBenKuang,?
nameWenBenKuang, phoneWenBenKuang = null;
JTree JTree1 = null;
public ptGuKedengLu(String str) {
this.setTitle("普通顧客登錄");
this.setLayout(null);
this.setSize(700, 700);
this.setLocationRelativeTo(null);
topMianBan = new JPanel(null);
shangPinCaoZuoJButton = new JButton("商品操作", new ImageIcon("img//a.jpg"));
shangPinCaoZuoJButton.setForeground(Color.red);
//shangPinCaoZuoJButton.setBackground(Color.red);
shangPinCaoZuoJButton.setVerticalTextPosition(JButton.BOTTOM);
shangPinCaoZuoJButton.setHorizontalTextPosition(JButton.CENTER);
shangPinCaoZuoJButton.setBounds(100, 0, 120, 130);
JButton2 = new JButton("購物車操作", new ImageIcon("img//b.jpg"));
JButton2.setForeground(Color.orange);
//JButton2.setBackground(Color.orange);
JButton2.setVerticalTextPosition(JButton.BOTTOM);
JButton2.setHorizontalTextPosition(JButton.CENTER);
JButton2.setBounds(250, 0, 120, 130);
geRenXinXiJButton = new JButton("個人信息管理", new ImageIcon("img//c.jpg"));
geRenXinXiJButton.setForeground(Color.blue);
//geRenXinXiJButton.setBackground(Color.yellow);
geRenXinXiJButton.setVerticalTextPosition(JButton.BOTTOM);
geRenXinXiJButton.setHorizontalTextPosition(JButton.CENTER);
geRenXinXiJButton.setBounds(400, 0, 120, 130);
exitJButton = new JButton("退出系統(tǒng)", new ImageIcon("img//d.jpg"));
exitJButton.setForeground(Color.green);
//exitJButton.setBackground(Color.green);
exitJButton.setVerticalTextPosition(JButton.BOTTOM);
exitJButton.setHorizontalTextPosition(JButton.CENTER);
exitJButton.setBounds(550, 0, 120, 130);
topMianBan.add(shangPinCaoZuoJButton);
topMianBan.add(JButton2);
topMianBan.add(geRenXinXiJButton);
topMianBan.add(exitJButton);
leftBottomMianBan = new JPanel(null);
leftBottomMianBan.setBounds(0, 130, 150, 600);
qieHuanAnNiu=new JButton("切換用戶");
qieHuanAnNiu.setBounds(0, 0, 150, 600);
leftBottomMianBan.add(qieHuanAnNiu);
qieHuanAnNiu.addActionListener(new ptGuKedengLuShiJian(this));
qieHuanYongHuMianBan = new JPanel(null);
//guoWuCheCaozZuoMianBan = new JPanel(null);
geRenXinXiXiuGaiMianBan = new JPanel(null);
tuiChuXiTongMianBan = new JPanel(null);
shangPinCaoZuoJButton.addActionListener(new ptGuKedengLuShiJian(this));
JButton2.addActionListener(new ptGuKedengLuShiJian(this));
geRenXinXiJButton.addActionListener(new ptGuKedengLuShiJian(this));
exitJButton.addActionListener(new ptGuKedengLuShiJian(this));
topMianBan.setBounds(0, 0, 700, 130);
lb_title = new JLabel("個人信息修改");
lb_title.setFont(new Font("微軟雅黑", Font.BOLD, 30));
lb_title.setBounds(120, 40, 200, 30);
// JPanel_mianBan_GRXXXG.add(lb_title);
lb_uname = new JLabel("用戶名:");
lb_pwd = new JLabel("密碼:");
lb_name = new JLabel("真實(shí)姓名:");
lb_sex = new JLabel("性別:");
lb_phone = new JLabel("電話:");
lb_uname.setBounds(100, 90, 80, 30);
lb_pwd.setBounds(100, 130, 80, 30);
lb_name.setBounds(100, 170, 80, 30);
lb_sex.setBounds(100, 210, 80, 30);
lb_phone.setBounds(100, 250, 80, 30);
geRenXinXiXiuGaiMianBan.add(lb_uname);
geRenXinXiXiuGaiMianBan.add(lb_pwd);
geRenXinXiXiuGaiMianBan.add(lb_name);
geRenXinXiXiuGaiMianBan.add(lb_sex);
geRenXinXiXiuGaiMianBan.add(lb_phone);
geRenXinXiXiuGaiMianBan.add(lb_title);
pwdWenBenKuang = new JTextField();
nameWenBenKuang = new JTextField();
phoneWenBenKuang = new JTextField();
unameWenBenKuang = new JTextField();
unameWenBenKuang.setEditable(false);
xiuGaiAnNiu = new JButton("修改");
xiuGaiAnNiu.addActionListener(new ptGuKedengLuShiJian(this));
quXiaoAnNiu = new JButton("取消");
xiuGaiAnNiu.setBounds(120, 290, 70, 30);
quXiaoAnNiu.setBounds(240, 290, 70, 30);
unameWenBenKuang.setBounds(180, 90, 120, 30);
pwdWenBenKuang.setBounds(180, 130, 120, 30);
nameWenBenKuang.setBounds(180, 170, 120, 30);
phoneWenBenKuang.setBounds(180, 250, 120, 30);
rb1 = new JRadioButton("男", true);
rb2 = new JRadioButton("女", false);
ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
rb1.setBounds(180, 210, 60, 30);
rb2.setBounds(250, 210, 60, 30);
geRenXinXiXiuGaiMianBan.add(unameWenBenKuang);
geRenXinXiXiuGaiMianBan.add(pwdWenBenKuang);
geRenXinXiXiuGaiMianBan.add(nameWenBenKuang);
geRenXinXiXiuGaiMianBan.add(rb1);
geRenXinXiXiuGaiMianBan.add(rb2);
geRenXinXiXiuGaiMianBan.add(phoneWenBenKuang);
geRenXinXiXiuGaiMianBan.add(quXiaoAnNiu);
geRenXinXiXiuGaiMianBan.add(xiuGaiAnNiu);
imgJLabel = new JLabel();
imgJLabel.setBounds(0, 0, 532, 532);
imgJLabel.setIcon(new ImageIcon("img//圖書美女.png"));
//
//JPanel_mianBan_qieHuanYongHu.add(lb_img);
//
//JPanel_mianBan_qieHuanYongHu.setBounds(150, 130, 550, 600);
//
//JPanel_mianBan_qieHuanYongHu.setBounds(150, 130, 550, 600);
geRenXinXiXiuGaiMianBan.setBounds(150, 130, 550, 600);
tuiChuXiTongMianBan.setBounds(150, 130, 550, 600);
topMianBan.setBorder(BorderFactory.createLineBorder(Color.red));
leftBottomMianBan.setBorder(BorderFactory
.createLineBorder(Color.green));
geRenXinXiXiuGaiMianBan.setBorder(BorderFactory
.createLineBorder(Color.green));
tuiChuXiTongMianBan.setBorder(BorderFactory
.createLineBorder(Color.blue));
this.add(topMianBan);
this.add(leftBottomMianBan);
this.add(qieHuanYongHuMianBan);
this.add(geRenXinXiXiuGaiMianBan);
this.add(tuiChuXiTongMianBan);
String sqlSelect = "select * from yonghu where yh_uname='" + str + "'";
ResultSet resAgain = DBUtils.Select(sqlSelect);
try {
while (resAgain.next()) {
unameWenBenKuang.setText(resAgain.getString("yh_uname"));
pwdWenBenKuang.setText(resAgain.getString("yh_pwd"));
phoneWenBenKuang.setText(resAgain.getString("yh_phone"));
nameWenBenKuang.setText(resAgain.getString("yh_name"));
String sex = resAgain.getString("yh_sex");
if (sex.equals("男")) {
rb1.setSelected(true);
rb2.setSelected(false);
} else if (sex.equals("女")) {
rb2.setSelected(true);
rb1.setSelected(false);
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
class ptGuKedengLuShiJian implements ActionListener,
MouseListener {
public ptGuKeDengLu jieShouChuangTi = null;
public ptGuKeDengLuShiJian(ptGuKedengLu ChuangTi) {
jieShouChuangTi = ChuangTi;
}
@Override
public void actionPerformed(ActionEvent arg0) {
String getWenZi = arg0.getActionCommand();
if (arg0.getSource() == jieShouChuangTi.shangPinCaoZuoJButton) {
new ptshangPinCaoZuo();
jieShouChuangTi.qieHuanYongHuMianBan.setVisible(true);
} else if (getWenZi.equals("購物車操作")) {
new ptGuoWuCheCaozZuo();
}?
else if (getWenZi.equals("切換用戶")) {
new DengLu();
} else if (arg0.getSource() == jieShouChuangTi.geRenXinXiJButton) {
jieShouChuangTi.geRenXinXiXiuGaiMianBan.setVisible(true);
jieShouChuangTi.tuiChuXiTongMianBan.setVisible(false);
} else if (arg0.getSource() == jieShouChuangTi.exitJButton) {
System.exit(0);
} else if (arg0.getActionCommand().equals("修改")) {
String uname = jieShouChuangTi.unameWenBenKuang.getText();
String phone = jieShouChuangTi.phoneWenBenKuang.getText();
String name = jieShouChuangTi.nameWenBenKuang.getText();
String pwd = jieShouChuangTi.pwdWenBenKuang.getText();
String sex = "男";
if (jieShouChuangTi.rb2.isSelected()) {
sex = "女";
}
String sql = "update yonghu set yh_pwd='" + pwd + "', yh_name='"
+ name + "' , yh_phone= ' " + phone + "' , yh_sex='" + sex
+ "' where yh_uname='" + uname + "'";
if (DBUtils.ZSG(sql)) {
JOptionPane.showMessageDialog(null, "個人信息更新成功");
return;
} else {
JOptionPane.showMessageDialog(null, "出現(xiàn)了未知的錯誤,請重試");
}
}
}
@Override
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}


