加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
超市积分1.txt 23.99 KB
一键复制 编辑 原始数据 按行查看 历史
姜鑫 提交于 2020-01-02 21:08 . 1
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
package rjgc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class BaseDao {
protected static String dbClassName = "com.mysql.cj.jdbc.Driver";
protected static String dbUrl = "jdbc:mysql://localhost:3306/supermarket?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=UTC";
protected static String dbUser = "root";
protected static String dbPwd = "123456";
public static Connection conn = null;
static {
try {
if (conn == null) {
Class.forName(dbClassName).newInstance();
conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
}
} catch (Exception ee) {
ee.printStackTrace();
}
}
private BaseDao() {
}
// 读取顾客
public static customer getCus(String card) {
customer cus = new customer();
ResultSet rs = findForResultSet("select * from customer where card='"
+ card + "'");
try {
if (rs.next()) {
cus.setCard(card);
cus.setPassword(rs.getString("password"));
cus.setName(rs.getString("name"));
cus.setDate(rs.getString("RegistDate"));
cus.setScore(rs.getInt("score"));
cus.setId(rs.getInt("id"));
}
} catch (SQLException e) {
e.printStackTrace();
}
return cus;
}
public static ResultSet findForResultSet(String sql) {
if (conn == null)
return null;
ResultSet rs = null;
Statement stmt = null;
try {
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
} catch (Exception e) {
e.printStackTrace();
}
return rs;
}
// 执行指定查询
public static ResultSet query(String QueryStr) {
ResultSet set = findForResultSet(QueryStr);
return set;
}
//添加商品
public static boolean addThing(thing th) {
if (th == null)
return false;
else
return insert("insert into thing values('" + th.getId() + "','"
+ th.getName() +"','"+ th.getScore()+ "')");
}
//添加顾客
public static boolean addCus(customer cus) {
if (cus == null)
return false;
else
return insert("insert into customer values('" + cus.getId() + "','"
+ cus.getName() + "','" + cus.getCard() + "','"
+ cus.getPassword() + "','" + cus.getScore() + "','"
+ cus.getDate() + "')");
}
//添加操作
public static boolean insert(String sql) {
boolean result = false;
try {
Statement stmt = conn.createStatement();
result = stmt.execute(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}
// 修改顾客积分信息的方法
public static int updateCus(int card,int score) {
return update("update customer set score = score+'" + score + "' where Card='" + card + "'");
}
//修改操作
public static int update(String sql) {
int result = 0;
try {
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}
//返回商品最大id
public static int getThingMaxId( String table,String idName) {
int id=0;
String sql = "select max(" + idName + ") from " + table;
try {
Statement stmt = conn.createStatement();
ResultSet set = stmt.executeQuery(sql);
if (set.next())
id = set.getInt(1);
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
return id;
}
//返回顾客最大id
public static int getCustomerMaxId( String table,String idName) {
int id=0;
String sql = "select max(" + idName + ") from " + table;
try {
Statement stmt = conn.createStatement();
ResultSet set = stmt.executeQuery(sql);
if (set.next())
id = set.getInt(1);
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
return id;
}
}
import java.util.Date;
public class customer {
private int id;
private String name;
private String card;
private int score;
private String password;
private String registDate;
public customer() {
}
public customer(int id) {
this.id = id;
}
public customer(int id,String name,String card,int score,String password,String registDate) {
this.id = id;
this.name = name;
this.card=card;
this.score=score;
this.password=password;
this.registDate=registDate;
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setCard(String card) {
this.card = card;
}
public String getCard() {
return card;
}
public void setScore(int score) {
this.score = score;
}
public int getScore() {
return score;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDate() {
return registDate;
}
public void setDate(String registDate) {
this.registDate = registDate;
}
}
package rjgc;
public class test {
public static void main(String[] args) {
// TODO 自动生成的方法存根
new mainWindow();
}
}
package rjgc;
public class thing {
private int id;
private String name;
private int score;
public thing() {
}
public thing(int id) {
this.id=id;
}
public thing(int id,String name,int score) {
this.id=id;
this.name=name;
this.score=score;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id=id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name=name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score=score;
}
}
package rjgc;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Window extends JDialog{
public Window(WindowS frame) {
super(frame,"用户卡号",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(220,220,500,300);//设置窗体坐标和大小
setTitle("收银员系统");
setLayout(null);
Container c = getContentPane();
JLabel l = new JLabel("-----欢迎进入收银员界面-----");//创建一个标签
l.setBounds(150, 10, 300, 30);
c.add(l);//窗体中添加标签
JLabel l1 = new JLabel("会员卡号");
l1.setBounds(10, 60, 60, 20);
c.add(l1);
JLabel l2 = new JLabel("消费金额");
l2.setBounds(10, 100, 60, 20);
c.add(l2);
JTextField jt1 = new JTextField();
jt1.setBounds(80, 60, 200, 20);
c.add(jt1);
JTextField jt2 = new JTextField();
jt2.setBounds(80, 100, 200, 20);
c.add(jt2);
JButton btn1= new JButton("确定");
btn1.setBounds(150, 150, 60, 20);
c.add(btn1);
JButton btn2= new JButton("取消");
btn2.setBounds(250, 150, 60, 20);
c.add(btn2);
btn1.addActionListener(new ActionListener() {//为按钮添加鼠标单击事件
public void actionPerformed(ActionEvent e) {
String str1=jt1.getText();
String str2=jt2.getText();
int card=Integer.parseInt(str1);
int score=Integer.parseInt(str2);
if(BaseDao.updateCus(card, score)==1)
new WindowW(Window.this,"成功!").setVisible(true);
else
new WindowW(Window.this,"失败!").setVisible(true);
}
});
}
class WindowW extends JDialog{
public WindowW(Window frame,String s) {
super(frame,s,true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(250,250,400,250);//设置对话框窗体大小
Container c = getContentPane();//创建一个容器
setLayout(null);
JLabel l1 = new JLabel(s);
l1.setBounds(80, 60, 200, 20);
c.add(l1);
}
}
}
package rjgc;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Window1 extends JDialog{
public Window1(WindowS2 frame) {
super(frame,"开卡系统",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setLayout(null);
Container c = getContentPane();
setBounds(230,230,500,300);//设置窗体坐标和大小
JLabel l = new JLabel("-----欢迎进入开卡界面-----");//创建一个标签
l.setBounds(150, 10, 300, 30);
c.add(l);//窗体中添加标签
JLabel l1 = new JLabel("姓名");
l1.setBounds(10, 60, 60, 20);
c.add(l1);
JLabel l2 = new JLabel("密码");
l2.setBounds(10, 100, 60, 20);
c.add(l2);
JLabel l3 = new JLabel("确认密码");
l3.setBounds(10, 140, 60, 20);
c.add(l3);
JTextField jt = new JTextField();
jt.setBounds(80, 60, 200, 20);
c.add(jt);
JPasswordField jp1=new JPasswordField();
jp1.setBounds(80, 100, 200, 20);
c.add(jp1);
JPasswordField jp2=new JPasswordField();
jp2.setBounds(80, 140, 200, 20);
c.add(jp2);
JButton btn1= new JButton("确定");
btn1.setBounds(150, 180, 60, 20);
c.add(btn1);
JButton btn2= new JButton("取消");
btn2.setBounds(250, 180, 60, 20);
c.add(btn2);
btn1.addActionListener(new ActionListener() {//为按钮添加鼠标单击事件
public void actionPerformed(ActionEvent e) {
char ch1[] = jp1.getPassword();//获取密码的字符数组
String str1=new String(ch1);
char ch2[] = jp2.getPassword();//获取密码的字符数组
String str2=new String(ch2);
if(jt.getText().equals(""))
{
new win1(Window1.this).setVisible(true);//使MYJDialog窗体可见
}
else if(str1.equals(""))
{
new win2(Window1.this).setVisible(true);//使MYJDialog窗体可见
}
else if(str1.equals(str2))
{
int id=BaseDao.getCustomerMaxId("customer", "ID")+1;
int score=0;
String name=jt.getText();
//注册日期
Date date = new Date();
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
String rdate = dateFormat.format(date);
String password=str1;
String card=id+"";
customer cus=new customer(id,name,card,score,password,rdate);
BaseDao.addCus(cus);
new MyJDialog(Window1.this,cus).setVisible(true);//使MYJDialog窗体可见
}
else
{
new win(Window1.this).setVisible(true);//使MYJDialog窗体可见
}
}
});
}
class MyJDialog extends JDialog{
public MyJDialog(Window1 frame,customer cus)
{
super(frame,"用户卡号",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(250,250,400,200);//设置对话框窗体大小
Container c = getContentPane();//创建一个容器
setLayout(null);
JLabel l1 = new JLabel("请记住卡号 : "+cus.getCard());
l1.setBounds(50, 60, 200, 20);
c.add(l1);
}
}
class win extends JDialog{
public win(Window1 frame) {
super(frame,"错误!!!",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(250,250,400,250);//设置对话框窗体大小
Container c = getContentPane();//创建一个容器
setLayout(null);
JLabel l1 = new JLabel("确认密码错误!");
l1.setBounds(80, 60, 200, 20);
c.add(l1);
}
}
class win1 extends JDialog{
public win1(Window1 frame) {
super(frame,"错误!!!",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(250,250,400,250);//设置对话框窗体大小
Container c = getContentPane();//创建一个容器
setLayout(null);
JLabel l1 = new JLabel("姓名不能为空!");
l1.setBounds(100, 60, 200, 20);
c.add(l1);
}
}
class win2 extends JDialog{
public win2(Window1 frame) {
super(frame,"错误!!!",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(250,250,400,250);//设置对话框窗体大小
Container c = getContentPane();//创建一个容器
setLayout(null);
JLabel l1 = new JLabel("密码不能为空!");
l1.setBounds(100, 60, 200, 20);
c.add(l1);
}
}
}
package rjgc;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
public class WindowS extends JDialog{
public WindowS(mainWindow frame) {
super(frame,"验证界面",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(210,210,500,280);//设置窗体坐标和大小
setLayout(null);
Container c = getContentPane();
JLabel l = new JLabel("-----请验证你的身份-----");//创建一个标签
l.setBounds(150, 10, 300, 30);
c.add(l);//窗体中添加标签
JLabel l1 = new JLabel("你的口令:");
l1.setBounds(10, 80, 80, 20);
c.add(l1);
JPasswordField jp=new JPasswordField();
jp.setBounds(120, 80, 200, 20);
c.add(jp);
JButton btn1= new JButton("确定");
btn1.setBounds(150, 150, 60, 20);
c.add(btn1);
JButton btn2= new JButton("取消");
btn2.setBounds(250, 150, 60, 20);
c.add(btn2);
btn1.addActionListener(new ActionListener() {//为按钮添加鼠标单击事件
public void actionPerformed(ActionEvent e) {
char ch[] = jp.getPassword();//获取密码的字符数组
String str=new String(ch);
if(str.equals("password"))
new Window(WindowS.this).setVisible(true);
else
new WindowS1(WindowS.this).setVisible(true);
}
});
}
}
package rjgc;
import java.awt.Container;
import javax.swing.JDialog;
import javax.swing.JLabel;
public class WindowS1 extends JDialog{
public WindowS1(WindowS frame) {
super(frame,"错误!!!",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(220,220,300,200);//设置窗体坐标和大小
setLayout(null);
Container c = getContentPane();
JLabel l = new JLabel("口令错误!!!请重新输入!");//创建一个标签
l.setBounds(30, 50, 300, 30);
c.add(l);//窗体中添加标签
}
}
package rjgc;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
public class WindowS2 extends JDialog{
public WindowS2(mainWindow frame) {
super(frame,"用户界面",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(220,220,500,300);//设置窗体坐标和大小
setLayout(null);
Container c = getContentPane();
JLabel l = new JLabel("-----欢迎进入用户界面-----");//创建一个标签
l.setBounds(150, 10, 300, 30);
c.add(l);//窗体中添加标签
JRadioButton jr1=new JRadioButton("开卡");
JRadioButton jr2=new JRadioButton("查询积分");
JRadioButton jr3=new JRadioButton("修改密码");
jr1.setBounds(20, 70, 80, 20);
jr2.setBounds(120, 70, 80, 20);
jr3.setBounds(220, 70, 80, 20);
jr1.setSelected(true);
ButtonGroup group=new ButtonGroup();
group.add(jr1);
group.add(jr2);
group.add(jr3);
c.add(jr1);
c.add(jr2);
c.add(jr3);
JButton btn1= new JButton("确定");
btn1.setBounds(150, 150, 60, 20);
c.add(btn1);
JButton btn2= new JButton("取消");
btn2.setBounds(250, 150, 60, 20);
c.add(btn2);
btn1.addActionListener(new ActionListener() {//为按钮添加鼠标单击事件
public void actionPerformed(ActionEvent e) {
if(jr1.isSelected())
new Window1(WindowS2.this).setVisible(true);
else if(jr2.isSelected())
new WindowS3(WindowS2.this).setVisible(true);
else
new WindowS4(WindowS2.this).setVisible(true);
}
});
}
}
package rjgc;
import java.awt.Container;
import javax.swing.JDialog;
import javax.swing.JLabel;
public class WindowS3 extends JDialog{
public WindowS3(WindowS2 frame) {
super(frame,"查询积分",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(250,250,300,200);//设置窗体坐标和大小
setLayout(null);
Container c = getContentPane();
JLabel l1 = new JLabel("积分:");
l1.setBounds(10, 50, 80, 20);
c.add(l1);
}
}
package rjgc;
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
public class WindowS4 extends JDialog{
public WindowS4(WindowS2 frame) {
super(frame,"修改密码",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(250,250,500,300);//设置窗体坐标和大小
setLayout(null);
Container c = getContentPane();
JLabel l1 = new JLabel("旧密码:");
l1.setBounds(30, 50, 80, 20);
c.add(l1);
JLabel l2 = new JLabel("新密码:");
l2.setBounds(30, 100, 80, 20);
c.add(l2);
JPasswordField jp1=new JPasswordField();
jp1.setBounds(120, 50, 200, 20);
c.add(jp1);
JPasswordField jp2=new JPasswordField();
jp2.setBounds(120, 100, 200, 20);
c.add(jp2);
JButton btn1= new JButton("确定");
btn1.setBounds(150, 160, 60, 20);
c.add(btn1);
JButton btn2= new JButton("取消");
btn2.setBounds(250, 160, 60, 20);
c.add(btn2);
}
}
package rjgc;
import java.awt.Container;
import javax.swing.JDialog;
import javax.swing.JLabel;
public class WindowS11 extends JDialog{
public WindowS11(WindowSS frame) {
super(frame,"错误!!!",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(220,220,300,200);//设置窗体坐标和大小
setLayout(null);
Container c = getContentPane();
JLabel l = new JLabel("口令错误!!!请重新输入!");//创建一个标签
l.setBounds(30, 50, 300, 30);
c.add(l);//窗体中添加标签
}
}
package rjgc;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
public class WindowS22 extends JDialog{
public WindowS22(WindowSS frame) {
super(frame,"管理员界面",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(220,220,500,300);//设置窗体坐标和大小
setLayout(null);
Container c = getContentPane();
JLabel l = new JLabel("-----欢迎进入管理员界面-----");//创建一个标签
l.setBounds(150, 10, 300, 30);
c.add(l);//窗体中添加标签
JRadioButton jr1=new JRadioButton("添加兑换商品");
JRadioButton jr2=new JRadioButton("修改兑换商品");
JRadioButton jr3=new JRadioButton("删除兑换商品");
jr1.setBounds(20, 90, 120, 20);
jr2.setBounds(150, 90, 120, 20);
jr3.setBounds(280, 90, 120, 20);
jr1.setSelected(true);
ButtonGroup group=new ButtonGroup();
group.add(jr1);
group.add(jr2);
group.add(jr3);
c.add(jr1);
c.add(jr2);
c.add(jr3);
JButton btn1= new JButton("确定");
btn1.setBounds(150, 160, 60, 20);
c.add(btn1);
JButton btn2= new JButton("取消");
btn2.setBounds(250, 160, 60, 20);
c.add(btn2);
btn1.addActionListener(new ActionListener() {//为按钮添加鼠标单击事件
public void actionPerformed(ActionEvent e) {
if(jr1.isSelected())
new WindowS221(WindowS22.this).setVisible(true);
// else if(jr2.isSelected())
// new WindowS222(WindowS22.this).setVisible(true);
// else
// new WindowS223(WindowS22.this).setVisible(true);
}
});
}
}
package rjgc;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;
import rjgc.Window1.MyJDialog;
public class WindowS221 extends JDialog{
public WindowS221(WindowS22 frame) {
super(frame,"添加兑换商品",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(250,250,500,300);//设置窗体坐标和大小
setLayout(null);
Container c = getContentPane();
JLabel l = new JLabel("-----欢迎进入添加兑换商品界面-----");//创建一个标签
l.setBounds(150, 10, 300, 30);
c.add(l);//窗体中添加标签
JLabel l1 = new JLabel("商品名");
l1.setBounds(10, 60, 60, 20);
c.add(l1);
JLabel l2 = new JLabel("兑换积分");
l2.setBounds(10, 100, 60, 20);
c.add(l2);
JTextField jt1 = new JTextField();
jt1.setBounds(80, 60, 200, 20);
c.add(jt1);
JTextField jt2 = new JTextField();
jt2.setBounds(80, 100, 200, 20);
c.add(jt2);
JButton btn1= new JButton("确定");
btn1.setBounds(150, 150, 60, 20);
c.add(btn1);
JButton btn2= new JButton("取消");
btn2.setBounds(250, 150, 60, 20);
c.add(btn2);
btn1.addActionListener(new ActionListener() {//为按钮添加鼠标单击事件
public void actionPerformed(ActionEvent e) {
String str1=jt1.getText();
String str2=jt2.getText();
if(str1.equals(""))
{
new win1(WindowS221.this).setVisible(true);
}
else if(str2.equals(""))
{
new win2(WindowS221.this).setVisible(true);
}
else
{
int id=BaseDao.getThingMaxId("thing", "ID")+1;
String name=str1;
int score=Integer.parseInt(str2);
thing th=new thing(id,name,score);
BaseDao.addThing(th);
ResultSet haveCus = BaseDao.query("select * from customer where id='" + id + "'");
try {
if(haveCus.next())
new MyJDialog(WindowS221.this,"添加成功!").setVisible(true);
else
new MyJDialog(WindowS221.this,"添加失败!").setVisible(true);
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}
}
});
}
class MyJDialog extends JDialog{
public MyJDialog(WindowS221 frame,String s)
{
super(frame,"提示",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(270,270,300,200);//设置对话框窗体大小
Container c = getContentPane();//创建一个容器
setLayout(null);
JLabel l1 = new JLabel(s);
l1.setBounds(80, 60, 200, 20);
c.add(l1);
}
}
class win1 extends JDialog{
public win1(WindowS221 frame) {
super(frame,"错误!!!",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(250,250,400,250);//设置对话框窗体大小
Container c = getContentPane();//创建一个容器
setLayout(null);
JLabel l1 = new JLabel("商品名不能为空!");
l1.setBounds(100, 60, 200, 20);
c.add(l1);
}
}
class win2 extends JDialog{
public win2(WindowS221 frame) {
super(frame,"错误!!!",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(250,250,400,250);//设置对话框窗体大小
Container c = getContentPane();//创建一个容器
setLayout(null);
JLabel l1 = new JLabel("兑换积分不能为空!");
l1.setBounds(100, 60, 200, 20);
c.add(l1);
}
}
}
package rjgc;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
public class WindowSS extends JDialog{
public WindowSS(mainWindow frame) {
super(frame,"验证界面",true);//实例化一个JDialog类对象,指定对话框的父窗体、窗体标题和类型
setBounds(210,210,500,280);//设置窗体坐标和大小
setLayout(null);
Container c = getContentPane();
JLabel l = new JLabel("-----请验证你的身份-----");//创建一个标签
l.setBounds(150, 10, 300, 30);
c.add(l);//窗体中添加标签
JLabel l1 = new JLabel("你的口令:");
l1.setBounds(10, 80, 80, 20);
c.add(l1);
JPasswordField jp=new JPasswordField();
jp.setBounds(120, 80, 200, 20);
c.add(jp);
JButton btn1= new JButton("确定");
btn1.setBounds(150, 150, 60, 20);
c.add(btn1);
JButton btn2= new JButton("取消");
btn2.setBounds(250, 150, 60, 20);
c.add(btn2);
btn1.addActionListener(new ActionListener() {//为按钮添加鼠标单击事件
public void actionPerformed(ActionEvent e) {
char ch[] = jp.getPassword();//获取密码的字符数组
String str=new String(ch);
if(str.equals("pass"))
new WindowS22(WindowSS.this).setVisible(true);
else
new WindowS11(WindowSS.this).setVisible(true);
}
});
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化