(14-16)Java:swing淘寶或超市等的收銀和商品管理系統(tǒng)(完善美化版)【詩書畫唱】

14

package shouYinXiTong;
public class yonghu {
private String yh_A;
private int yh_id;
private String yh_name;
private String yh_phone;
private String yh_pwd;
private String yh_Q;
private String yh_sex;
private String yh_typename;
private String yh_uname;
public yonghu() {
}
public yonghu(String yh_Q, int yh_id, String yh_uname,?
String yh_name,
String yh_phone, String yh_pwd, String yh_sex, String yh_typename,
String yh_A) {
this.yh_Q = yh_Q;
this.yh_id = yh_id;
this.yh_uname = yh_uname;
this.yh_name = yh_name;
this.yh_phone = yh_phone;
this.yh_pwd = yh_pwd;
this.yh_sex = yh_sex;
this.yh_typename = yh_typename;
this.yh_A = yh_A;
}
public String getYh_A() {
return yh_A;
}
public int getYh_id() {
return yh_id;
}
public String getYh_name() {
return yh_name;
}
public String getYh_phone() {
return yh_phone;
}
public String getYh_pwd() {
return yh_pwd;
}
public String getYh_Q() {
return yh_Q;
}
public String getYh_sex() {
return yh_sex;
}
public String getYh_typename() {
return yh_typename;
}
public String getYh_uname() {
return yh_uname;
}
public void setYh_A(String yh_A) {
this.yh_A = yh_A;
}
public void setYh_id(int yh_id) {
this.yh_id = yh_id;
}
public void setYh_name(String yh_name) {
this.yh_name = yh_name;
}
public void setYh_phone(String yh_phone) {
this.yh_phone = yh_phone;
}
public void setYh_pwd(String yh_pwd) {
this.yh_pwd = yh_pwd;
}
public void setYh_Q(String yh_Q) {
this.yh_Q = yh_Q;
}
public void setYh_sex(String yh_sex) {
this.yh_sex = yh_sex;
}
public void setYh_typename(String yh_typename) {
this.yh_typename = yh_typename;
}
public void setYh_uname(String yh_uname) {
this.yh_uname = yh_uname;
}
@Override
public String toString() {
return "users [yh_Q=" + yh_Q + ", yh_id=" + yh_id +
", yh_uname="
+ yh_uname + ", yh_name=" + yh_name + ", yh_phone=" + yh_phone
+ ", yh_pwd=" + yh_pwd + ", yh_sex=" + yh_sex
+ ", yh_typename=" + yh_typename + ", yh_A=" + yh_A + "]";
}
}
15

package shouYinXiTong;
import java.awt.Color;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
class zhaoHuiMiMaShiJian implements
FocusListener, ActionListener {
public zhaoHuiMiMa jieShouChuangTi = null;
public zhaoHuiMiMaShiJian(zhaoHuiMiMa ChuangTi) {
this.jieShouChuangTi = ChuangTi;
}
@Override
public void actionPerformed(ActionEvent arg0) {
if(arg0.getActionCommand()
.equals("確認(rèn)且回答正確后跳轉(zhuǎn)重置密碼頁面")){
String uname = jieShouChuangTi.unameWenBenKuang
.getText().trim();
String wenTi = jieShouChuangTi.wenTiWenBenKuang
.getText().trim();
String daAn = jieShouChuangTi.daAnWenBenKuang
.getText().trim();
String sql = "select * from yonghu where "
+ "yh_Uname='" + uname
+ "'and yh_Q='" + wenTi + "'and yh_A='" + daAn
+ "'";
ResultSet res = DBUtils.Select(sql);
try {
if (res.next()) {
new chongZhiMiMa();
gongjvClass.uname = uname;
} else {
JOptionPane.showMessageDialog(null, "答案輸入錯(cuò)誤");
jieShouChuangTi.daAnWenZi2.setText("答案輸入錯(cuò)誤");
jieShouChuangTi.daAnWenZi2.setForeground(Color.red);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
else if (arg0.getActionCommand()
.equals("取消")) {
JOptionPane.showMessageDialog(null,?
"點(diǎn)擊了取消按鈕");
jieShouChuangTi.setVisible(false);
}
}
@Override
public void focusGained(FocusEvent arg0) {
}
@Override
public void focusLost(FocusEvent arg0) {
String uname = jieShouChuangTi.unameWenBenKuang.
getText().trim();
String sql = "select * from yonghu where yh_uname='"?
+ uname + "'";
ResultSet res = DBUtils.Select(sql);
try {
if (res.next()) {
String wenTi = res.getString("yh_Q");
jieShouChuangTi.wenTiWenBenKuang.setText(wenTi);
jieShouChuangTi.unameWenZi2.setText("");
} else {
jieShouChuangTi.unameWenZi2.setText("用戶名錯(cuò)誤");
jieShouChuangTi.unameWenZi2.setForeground(Color.red);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public class zhaoHuiMiMa extends JFrame {
static JButton queRenAnNiu, quXiaoAnNiu = null;
static JLabel unameWenZi1, wenTiWenZi1,?
daAnWenZi1 = null;
static JLabel unameWenZi2, wenTiWenZi2,?
daAnWenZi2 = null;
static JTextField unameWenBenKuang, wenTiWenBenKuang,?
daAnWenBenKuang = null;
public zhaoHuiMiMa() {
this.setTitle("找回密碼頁面");
this.setLayout(null);
this.setSize(500, 500);
this.setLocationRelativeTo(null);
unameWenZi1 = new JLabel("用戶名");
wenTiWenZi1 = new JLabel("問題");
daAnWenZi1 = new JLabel("答案");
unameWenZi2 = new JLabel("請輸入用戶名");
daAnWenZi2 = new JLabel("請輸入答案");
unameWenBenKuang = new JTextField();
wenTiWenBenKuang = new JTextField();
daAnWenBenKuang = new JTextField();
unameWenBenKuang.addFocusListener
(new zhaoHuiMiMaShiJian(this));
unameWenZi2.setForeground(Color.blue);
daAnWenZi2.setForeground(Color.blue);
unameWenZi1.setBounds(100, 100, 100, 30);
wenTiWenZi1.setBounds(100, 140, 100, 30);
daAnWenZi1.setBounds(100, 180, 100, 30);
unameWenZi2.setBounds(310, 105, 100, 30);
daAnWenZi2.setBounds(310, 185, 100, 30);
this.add(unameWenZi1);
this.add(wenTiWenZi1);
this.add(daAnWenZi1);
this.add(unameWenZi2);
this.add(daAnWenZi2);
unameWenBenKuang.setBounds(210, 100, 100, 30);
wenTiWenBenKuang.setBounds(210, 140, 100, 30);
wenTiWenBenKuang.setEditable(false);
daAnWenBenKuang.setBounds(210, 180, 100, 30);
this.add(unameWenBenKuang);
this.add(wenTiWenBenKuang);
this.add(daAnWenBenKuang);
queRenAnNiu = new JButton("確認(rèn)且回答正確后跳轉(zhuǎn)重置密碼頁面");
queRenAnNiu.addActionListener(new zhaoHuiMiMaShiJian(this));
quXiaoAnNiu = new JButton("取消");
quXiaoAnNiu.addActionListener(new zhaoHuiMiMaShiJian(this));
queRenAnNiu.setBounds(10, 230, 290, 30);
quXiaoAnNiu.setBounds(340, 230, 70, 30);
this.add(queRenAnNiu);
this.add(quXiaoAnNiu);
this.setVisible(true);
}
}
16

package shouYinXiTong;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
class zhuCeShiJian implements ActionListener {
public static zhuCe jieShouChuangTi = null;
public zhuCeShiJian(zhuCe ChuangTi) {
this.jieShouChuangTi = ChuangTi;
}
@Override
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null, "點(diǎn)擊了注冊按鈕");
String uname = jieShouChuangTi.unameKuang.getText();
String pwd1 = jieShouChuangTi.pwdKuang1.getText();
String pwd2 = jieShouChuangTi.pwdKuang2.getText();
String name = jieShouChuangTi.nameKuang.getText();
String age = jieShouChuangTi.xiaLaKuang.
getSelectedItem()
.toString();
String sex = "男";
if (jieShouChuangTi.rb2.isSelected()) {
sex = "女";
}
String StringPhone = jieShouChuangTi.
phoneKuang.getText();
ArrayList<String> jiHe = new ArrayList<String>();
if (jieShouChuangTi.diZhiFuxuanKaung1.isSelected()) {
jiHe.add(jieShouChuangTi.diZhiFuxuanKaung1.getText());
}
if (jieShouChuangTi.diZhiFuxuanKaung2.isSelected()) {
jiHe.add(jieShouChuangTi.diZhiFuxuanKaung2.getText());
}
if (jieShouChuangTi.diZhiFuxuanKaung3.isSelected()) {
jiHe.add(jieShouChuangTi.diZhiFuxuanKaung3.getText());
}
String StringAddress = " ";
for (int i = 0; i < jiHe.size(); i++) {
StringAddress += jiHe.get(i) + " ";
}
String StringJieShao = jieShouChuangTi.
jieshaoWenBenYu.getText();
String String_Q = jieShouChuangTi.wenTiKaung.getText();
String String_A = jieShouChuangTi.daAnKuang.getText();
if (!pwd1.equals(pwd2)) {
JOptionPane.showMessageDialog(null,?
"兩次密碼輸入不一致, 請重新輸入");
return;
}
String sql = "select * from "
+ "yonghu where yh_uname='"
+ uname + "'";
ResultSet res_select_uname = DBUtils.
Select(sql);
try {
if (res_select_uname.next()) {
JOptionPane.showMessageDialog(null,?
"用戶名已經(jīng)存在了,請重新輸入");
return;
}
} catch (SQLException e) {
e.printStackTrace();
}
String sqlInsert = "insert into yonghu(yh_uname,"
+ "yh_pwd,yh_Name"
+ ",yh_age,yh_sex,yh_phone,yh_address"
+ ",yh_jieshao,yh_Q,yh_A,yh_type) values('"?
+ uname+ "','"+ pwd1 + "','"
+ name + "'," + age + ",'" + sex
+ "','" + StringPhone + "','" + StringAddress?
+ "','"+ StringJieShao + "','" + String_Q + "','"?
+ String_A + "'"
+ ",'普通用戶')";
if (DBUtils.ZSG(sqlInsert)) {
JOptionPane.showMessageDialog(null, "注冊成功");
} else {
JOptionPane.showMessageDialog(null,?
"出現(xiàn)了未知的錯(cuò)誤,請重試");
}
}
}
public class zhuCe extends JFrame {
static JCheckBox diZhiFuxuanKaung1,
diZhiFuxuanKaung2,
diZhiFuxuanKaung3 = null;
public static JButton zhuCeAnNiu = null;
static JComboBox xiaLaKuang = null;
public static JPasswordField pwdKuang1,
pwdKuang2 = null;
static JTextArea jieshaoWenBenYu = null;
public static JTextField unameKuang, nameKuang,
phoneKuang, jieShaoKuang, wenTiKaung,
daAnKuang = null;
public static JLabel unameWenZi, pwdWenZi,?
queRenPwdWenZi,
nameWenZi, ageWenZi, sexWenZi,
phoneWenZi, addressWenZi, jieShaoWenZi,?
QWenZi, AWenZi = null;
static JRadioButton rb1, rb2 = null;
public zhuCe() {
this.setLayout(null);
this.setSize(600, 700);
this.setTitle("注冊界面(只有普通用戶才要注冊)");
this.setLocationRelativeTo(null);
unameWenZi = new JLabel("用戶名");
pwdWenZi = new JLabel("用戶密碼");
queRenPwdWenZi = new JLabel("確認(rèn)密碼");
nameWenZi = new JLabel("真實(shí)姓名");
ageWenZi = new JLabel("年齡");
sexWenZi = new JLabel("性別");
phoneWenZi = new JLabel("電話");
addressWenZi = new JLabel("地址");
jieShaoWenZi = new JLabel("介紹");
QWenZi = new JLabel("問題");
AWenZi = new JLabel("答案");
unameWenZi.setBounds(80, 100, 70, 30);
pwdWenZi.setBounds(80, 140, 70, 30);
queRenPwdWenZi.setBounds(80, 180, 70, 30);
nameWenZi.setBounds(80, 220, 70, 30);
ageWenZi.setBounds(80, 260, 70, 30);
sexWenZi.setBounds(80, 300, 70, 30);
phoneWenZi.setBounds(80, 340, 70, 30);
addressWenZi.setBounds(80, 380, 70, 30);
jieShaoWenZi.setBounds(80, 420, 70, 30);
QWenZi.setBounds(80, 460, 70, 30);
AWenZi.setBounds(80, 500, 70, 30);
this.add(unameWenZi);
this.add(pwdWenZi);
this.add(queRenPwdWenZi);
this.add(nameWenZi);
this.add(ageWenZi);
this.add(sexWenZi);
this.add(phoneWenZi);
this.add(addressWenZi);
this.add(jieShaoWenZi);
this.add(QWenZi);
this.add(AWenZi);
unameKuang = new JTextField();
pwdKuang1 = new JPasswordField();
pwdKuang2 = new JPasswordField();
nameKuang = new JTextField();
rb1 = new JRadioButton("男", true);
rb2 = new JRadioButton("女");
this.add(rb1);
this.add(rb2);
xiaLaKuang = new JComboBox();
ButtonGroup anNiuFenZu = new ButtonGroup();
//anNiuFenZu按鈕分組
anNiuFenZu.add(rb1);
anNiuFenZu.add(rb2);
for (int i = 18; i < 60; i++) {
xiaLaKuang.addItem(i);
}
this.add(xiaLaKuang);
phoneKuang = new JTextField();
diZhiFuxuanKaung1 = new JCheckBox("中國", true);
diZhiFuxuanKaung2 = new JCheckBox("日本");
diZhiFuxuanKaung3 = new JCheckBox("美國");
wenTiKaung = new JTextField();
daAnKuang = new JTextField();
jieshaoWenBenYu = new JTextArea();
jieshaoWenBenYu.setColumns(8);
jieshaoWenBenYu.setRows(4);
jieshaoWenBenYu.setLineWrap(true);
this.add(jieshaoWenBenYu);
unameKuang.setBounds(160, 100, 140, 30);
pwdKuang1.setBounds(160, 140, 140, 30);
pwdKuang2.setBounds(160, 180, 140, 30);
nameKuang.setBounds(160, 220, 140, 30);
xiaLaKuang.setBounds(160, 260, 140, 30);
rb1.setBounds(160, 300, 50, 30);
rb2.setBounds(220, 300, 50, 30);
phoneKuang.setBounds(160, 340, 140, 30);
diZhiFuxuanKaung1.setBounds(160, 380, 80, 30);
diZhiFuxuanKaung2.setBounds(240, 380, 70, 30);
diZhiFuxuanKaung3.setBounds(320, 380, 70, 30);
jieshaoWenBenYu.setBounds(160, 420, 140, 40);
wenTiKaung.setBounds(160, 460, 140, 30);
daAnKuang.setBounds(160, 500, 140, 30);
this.setLocationRelativeTo(null);
this.add(unameKuang);
this.add(pwdKuang1);
this.add(pwdKuang2);
this.add(nameKuang);
this.add(phoneKuang);
this.add(wenTiKaung);
this.add(daAnKuang);
this.add(diZhiFuxuanKaung1);
this.add(diZhiFuxuanKaung2);
this.add(diZhiFuxuanKaung3);
zhuCeAnNiu = new JButton("確認(rèn)注冊");
zhuCeAnNiu.addActionListener
(new zhuCeShiJian(this));
zhuCeAnNiu.setBounds(160, 580, 120, 30);
this.add(zhuCeAnNiu);
this.setVisible(true);
}
}