JAVA 点菜系统数据库课程设计

点菜系统数据库课程设计

效果图

在这里插入图片描述
在这里插入图片描述

数据库建表
CREATE TABLE OrderDish
(orderid int not null,money int,primary key(orderid)
);CREATE TABLE Dish
(id varchar(20) not null,name nchar(10),price int,type nchar(10),primary key(id)
);
insert into Dish values('zhushi0','水煮肉片',20,'主食');
insert into Dish values('zhushi1','农家小炒肉',19,'主食');
insert into Dish values('zhushi2','回锅牛肉',28,'主食');
insert into Dish values('zhushi3','红烧鱼块',24,'主食');
insert into Dish values('zhushi4','干烧刁子鱼',24,'主食');
insert into Dish values('zhushi5','干锅手撕鸡',22,'主食');
insert into Dish values('zhushi6','香菇焖鸡',26,'主食');
insert into Dish values('zhushi7','四季豆牛肚丝',26,'主食');
insert into Dish values('zhushi8','鱼香肉丝',19,'主食');  insert into Dish values('sushi0','酸辣土豆丝',12,'素食');
insert into Dish values('sushi1','番茄炒蛋',13,'素食');
insert into Dish values('sushi2','豆角炒茄子',13,'素食');
insert into Dish values('sushi3','麻婆豆腐',12,'素食');
insert into Dish values('sushi4','手撕包菜',10,'素食');
insert into Dish values('sushi5','小炒香干',13,'素食');
insert into Dish values('sushi6','小炒千叶豆腐',16,'素食');
insert into Dish values('sushi7','口味黑木耳',16,'素食');insert into Dish values('xiaochi0','鸡米花',10,'小吃');
insert into Dish values('xiaochi1','无骨鸡柳',10,'小吃');
insert into Dish values('xiaochi2','骨肉相连',10,'小吃');
insert into Dish values('xiaochi3','薯条',8,'小吃');
insert into Dish values('xiaochi4','川香鸡柳',10,'小吃');
insert into Dish values('xiaochi5','香酥鸡块',15,'小吃');insert into Dish values('yinpin0','红豆奶茶',10,'饮品');
insert into Dish values('yinpin1','芒果奶昔',10,'饮品');
insert into Dish values('yinpin2','蜜桃奶昔',10,'饮品');
insert into Dish values('yinpin3','姜母茶',15,'饮品');
insert into Dish values('yinpin4','原味奶茶',10,'饮品');
insert into Dish values('yinpin5','咖啡奶茶',10,'饮品');CREATE TABLE OrderItem
(orderid int not null,id varchar(20) not null,num int,primary key(orderid,id),foreign key(orderid) references OrderDish(orderid),foreign key(id) references Dish(id)
);drop table OrderItem;
drop table Dish;
drop table OrderDish;try
{}
catch(Exception exp)
{exp.printStackTrace();
}String url = "jdbc:mysql://localhost:3306/test" ;  //下面几行都是模板    
String user = "root" ;   
String password = "" ;
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection(url, user, password);PreparedStatement ps=null; 
ps=conn.prepareStatement("select count(*) from OrderDish"); 
ResultSet re=ps.executeQuery();

需要添加n多图片,加载连接mysql的驱动器

import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;
import java.sql.*;
import javax.swing.border.EmptyBorder;
public class test1 extends JFrame implements ActionListener {//private static final String  = null;public static void main(String[] args) {EventQueue.invokeLater(new Runnable() {public void run() {try {test1 frame = new test1();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}int orderid=0;public test1() {setTitle("点菜系统");setSize(600,600); //设置窗口大小setLocation(100,100); //设置窗口的位置ImageIcon image = new ImageIcon("Image/huanyingguanglin.PNG"); image.setImage(image.getImage().getScaledInstance(600,530,Image.SCALE_DEFAULT)); // 把背景图片显示在一个标签里面  JLabel label = new JLabel(image);  // 把标签的大小位置设置为图片刚好填充整个面板  label.setBounds(0, 0, this.getWidth(), this.getHeight());  // 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明  JPanel imagePanel = (JPanel) this.getContentPane();  imagePanel.setOpaque(false);  // 把背景图片添加到分层窗格的最底层作为背景  this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE)); JButton jb=new JButton();jb.addActionListener(this);  //增加监听jb.setActionCommand("Welcome"); //监听信号jb.setPreferredSize(new Dimension(250,50));jb.setFont(new Font("宋体",Font.BOLD,20));jb.setText("欢迎顾客点击进入菜单");JPanel jp=new JPanel();jp.setOpaque(false);jp.setLayout(new GridBagLayout());GridBagConstraints c=new GridBagConstraints();c.fill=GridBagConstraints.NONE;c.gridx=0; c.gridy=0;c.insets=new Insets(300,0,50,50);jp.add(jb,c);jb=new JButton();jb.addActionListener(this);jb.setActionCommand("Close");jb.setPreferredSize(new Dimension(250,50));jb.setFont(new Font("宋体",Font.BOLD,20));jb.setText("取消订单退出系统");c=new GridBagConstraints();c.fill=GridBagConstraints.NONE;c.gridx=1; c.gridy=0;c.insets=new Insets(300,0,50,50);jp.add(jb,c);this.add(jp);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true);  //是否显示    }public void actionPerformed(ActionEvent e){try{String url = "jdbc:mysql://localhost:3306/test" ;  //下面几行都是模板    String user = "root" ;   String password = "" ;Class.forName("com.mysql.jdbc.Driver");Connection conn=DriverManager.getConnection(url, user, password);PreparedStatement ps=null;if(e.getActionCommand()=="Welcome"){    ps=conn.prepareStatement("select count(*) from OrderDish"); ResultSet re=ps.executeQuery();while(re.next()) orderid=re.getInt(1);orderid++;ps=conn.prepareStatement("insert into OrderDish values(?,0)");ps.setInt(1, orderid); ps.executeUpdate();OrderDish order=new OrderDish(this,"菜单",true,orderid); //新的对话界面}else if(e.getActionCommand()=="Close"){ ps=conn.prepareStatement("delete from OrderItem where orderid=?");ps.setInt(1, orderid);ps.executeUpdate();ps=conn.prepareStatement("delete from OrderDish where orderid=?"); ps.setInt(1, orderid);ps.executeUpdate();this.dispose();}    }catch(Exception exp){ exp.printStackTrace(); }}
}class OrderDish extends JDialog implements ActionListener
{JPanel[] jp={null,null,null,null};JTabbedPane jtp=null;JButton but=null;JPanel topPane=null,bottomPane=null,pane=null;JPanel[] zhushi={null,null,null,null,null,null,null,null,null,null};JLabel lab=null;JCheckBox[] zhushicheck={null,null,null,null,null,null,null,null,null};JCheckBox[] sushicheck={null,null,null,null,null,null,null,null};JCheckBox[] xiaochicheck={null,null,null,null,null,null};JCheckBox[] yinpincheck={null,null,null,null,null,null};JComboBox[] zhushicombo={null,null,null,null,null,null,null,null,null};JComboBox[] sushicombo={null,null,null,null,null,null,null,null};JComboBox[] xiaochicombo={null,null,null,null,null,null};JComboBox[] yinpincombo={null,null,null,null,null,null};ImageIcon image=null;JScrollPane[] jsp={null,null,null,null};String[] zhushiAL={ "zhushi0","zhushi1","zhushi2","zhushi3","zhushi4","zhushi5","zhushi6","zhushi7","zhushi8" };String[] sushiAL={ "sushi0","sushi1","sushi2","sushi3","sushi4","sushi5","sushi6","sushi7" };String[] xiaochiAL={ "xiaochi0","xiaochi1","xiaochi2","xiaochi3","xiaochi4","xiaochi5" };String[] yinpinAL={ "yinpin0","yinpin1","yinpin2","yinpin3","yinpin4","yinpin5" };String[] zhushinumAL={ "zhushinum0","zhushinum1","zhushinum2","zhushinum3","zhushinum4","zhushinum5","zhushinum6","zhushinum7","zhushinum8" };String[] sushinumAL={ "sushinum0","sushinum1","sushinum2","sushinum3","sushinum4","sushinum5","sushinum6","sushinum7" };String[] xiaochinumAL={ "xiaochinum0","xiaochinum1","xiaochinum2","xiaochinum3","xiaochinum4","xiaochinum5" };String[] yinpinnumAL={ "yinpinnum0","yinpinnum1","yinpinnum2","yinpinnum3","yinpinnum4","yinpinnum5" };int orderid=0,zhushinum=9,sushinum=8,xiaochinum=6,yinpinnum=6;OrderDish(Frame a,String b,boolean c,int oid){super(a,b,c);orderid=oid;this.setTitle("菜单");this.setSize(600,600);this.setLocation(200,100);//右上角碗碟图片image = new ImageIcon("Image/碗碟.PNG"); image.setImage(image.getImage().getScaledInstance(300,100,Image.SCALE_DEFAULT)); lab=new JLabel(image);//左上角查看当前订单按钮but=new JButton();but.setForeground(Color.RED);but.setFont(new Font("宋体",Font.BOLD,25));but.setText("点击查看当前订单");but.setBackground(Color.WHITE);but.setPreferredSize(new Dimension(280,90));but.addActionListener(this);but.setActionCommand("ViewOrder"); //点击查看当前订单监听器pane=new JPanel();pane.setBackground(Color.WHITE);pane.add(but);//上部分面板topPane=new JPanel();topPane.setLayout(new GridLayout(1,2));topPane.add(pane);topPane.add(lab);this.add(topPane,BorderLayout.NORTH);//四个选项卡面板jp[0]=new JPanel();jp[1]=new JPanel();jp[2]=new JPanel();jp[3]=new JPanel();//给第0个面板添加内容jp[0].setLayout(new GridLayout(3,3,10,10));for(int i=0;i<zhushinum;i++) zhushi[i]=new JPanel(); //多个面板存放不同的菜String[] num={"1","2","3","4","5"};String[] zhushiname={"水煮肉片  20元/份 ", "农家小炒肉  19元/份", "回锅牛肉 28元/份","红烧鱼块 24元/份", "干烧刁子鱼 24元/份", "干锅手撕鸡 22元/份","香菇焖鸡 26元/份", "四季豆牛肚丝 26元/份", "鱼香肉丝 19元/份"};String[] zhushitp={"Image/shuizhuroupian.PNG","Image/nongjiaxiaochaorou.PNG","Image/huiguoniurou.PNG","Image/hongshaoyukuai.PNG","Image/ganshaodiaoziyu.PNG","Image/ganguoshousiji.PNG","Image/xianggumenji.PNG","Image/sijidouniudusi.PNG","Image/yuxiangrousi.PNG"};//给每个菜的面板添加内容for(int i=0;i<zhushinum;i++){bottomPane=new JPanel();bottomPane.setLayout(new GridLayout(2,1));zhushicheck[i]=new JCheckBox("选中");zhushicheck[i].addActionListener(this);zhushicheck[i].setActionCommand(zhushiAL[i]); //增加监听器lab=new JLabel(zhushiname[i]);bottomPane.add(lab); zhushicombo[i]=new JComboBox(num); //下拉列表框zhushicombo[i].setSelectedIndex(0); //设置默认为1(第0个数)zhushicombo[i].addActionListener(this);zhushicombo[i].setActionCommand(zhushinumAL[i]);lab=new JLabel("份");pane=new JPanel();pane.add(zhushicheck[i]); pane.add(zhushicombo[i]); pane.add(lab);bottomPane.add(pane); image= new ImageIcon(zhushitp[i]); image.setImage(image.getImage().getScaledInstance(180,120,Image.SCALE_DEFAULT));lab=new JLabel(image);zhushi[i].add(lab,BorderLayout.CENTER);zhushi[i].add(bottomPane,BorderLayout.SOUTH);}//把所有菜的面板加入到大面板中去for(int i=0;i<zhushinum;i++) jp[0].add(zhushi[i]);jp[0].setPreferredSize(new Dimension(560,600));jsp[0]=new JScrollPane(jp[0]);//给第1个面板添加内容String[] sushiname={"酸辣土豆丝 12元/份","番茄炒蛋 13元/份","豆角炒茄子 13元/份","麻婆豆腐 12元/份","手撕包菜 10元/份","小炒香干 13元/份","小炒千叶豆腐 16元/份","口味黑木耳 16元/份"};String[] sushitp={"sushi/suanlatudousi.PNG","sushi/fanqiechaodan.PNG","sushi/doujiaochaoqiezi.PNG","sushi/mapodoufu.PNG","sushi/shousibaocai.PNG","sushi/xiaochaoxianggan.PNG","sushi/xiaochaoqianyedoufu.PNG","sushi/kouweiheimuer.PNG"};jp[1].setLayout(new GridLayout(3,3,10,10));for(int i=0;i<sushinum;i++) zhushi[i]=new JPanel(); //多个面板存放不同的菜//给每个菜的面板添加内容for(int i=0;i<sushinum;i++){bottomPane=new JPanel();bottomPane.setLayout(new GridLayout(2,1));sushicheck[i]=new JCheckBox("选中");sushicheck[i].addActionListener(this);sushicheck[i].setActionCommand(sushiAL[i]); //增加监听器lab=new JLabel(sushiname[i]);bottomPane.add(lab); sushicombo[i]=new JComboBox(num); //下拉列表框sushicombo[i].setSelectedIndex(0); //设置默认为1(第0个数)sushicombo[i].addActionListener(this);sushicombo[i].setActionCommand(sushinumAL[i]);lab=new JLabel("份");pane=new JPanel();pane.add(sushicheck[i]); pane.add(sushicombo[i]); pane.add(lab);bottomPane.add(pane); image= new ImageIcon(sushitp[i]); image.setImage(image.getImage().getScaledInstance(180,120,Image.SCALE_DEFAULT));lab=new JLabel(image);zhushi[i].add(lab,BorderLayout.CENTER);zhushi[i].add(bottomPane,BorderLayout.SOUTH);}for(int i=0;i<sushinum;i++) jp[1].add(zhushi[i]);jp[1].setPreferredSize(new Dimension(560,600));jsp[1]=new JScrollPane(jp[1]);//给第2个面板添加内容String[] xiaochiname={"鸡米花  10元/份","无骨鸡柳 10元/份","骨肉相连 10元/份","薯条 8元/份","川香鸡柳 10元/份","香酥鸡块 15元/份"};String[] xiaochitp={"xiaochi/jimihua.PNG","xiaochi/wugujiliu.PNG","xiaochi/gurouxianglian.PNG","xiaochi/shutiao.PNG","xiaochi/chuanxiangjiliu.PNG","xiaochi/xiangsujikuai.PNG"};jp[2].setLayout(new GridLayout(2,3,10,10));for(int i=0;i<xiaochinum;i++) zhushi[i]=new JPanel(); //多个面板存放不同的菜//给每个菜的面板添加内容for(int i=0;i<xiaochinum;i++){bottomPane=new JPanel();bottomPane.setLayout(new GridLayout(2,1));xiaochicheck[i]=new JCheckBox("选中");xiaochicheck[i].addActionListener(this);xiaochicheck[i].setActionCommand(xiaochiAL[i]); //增加监听器lab=new JLabel(xiaochiname[i]);bottomPane.add(lab); xiaochicombo[i]=new JComboBox(num); //下拉列表框xiaochicombo[i].setSelectedIndex(0); //设置默认为1(第0个数)xiaochicombo[i].addActionListener(this);xiaochicombo[i].setActionCommand(xiaochinumAL[i]);lab=new JLabel("份");pane=new JPanel();pane.add(xiaochicheck[i]); pane.add(xiaochicombo[i]); pane.add(lab);bottomPane.add(pane); image= new ImageIcon(xiaochitp[i]); image.setImage(image.getImage().getScaledInstance(180,120,Image.SCALE_DEFAULT));lab=new JLabel(image);zhushi[i].add(lab,BorderLayout.CENTER);zhushi[i].add(bottomPane,BorderLayout.SOUTH);}for(int i=0;i<xiaochinum;i++) jp[2].add(zhushi[i]);jp[2].setPreferredSize(new Dimension(560,400));jsp[2]=new JScrollPane(jp[2]);//给第3个面板添加内容String[] yinpinname={"红豆奶茶  10元/份","芒果奶昔 10元/份","蜜桃奶昔 10元/份","姜母茶 15元/份","原味奶茶 10元/份","咖啡奶茶 10元/份"};String[] yinpintp={"yinpin/hongdounaicha.PNG","yinpin/mangguonaixi.PNG","yinpin/mitaonaixi.PNG","yinpin/jiangmucha.PNG","yinpin/yuanweinaicha.PNG","yinpin/kafeinaicha.PNG"};jp[3].setLayout(new GridLayout(2,3,10,10));for(int i=0;i<yinpinnum;i++) zhushi[i]=new JPanel(); //多个面板存放不同的菜//给每个菜的面板添加内容for(int i=0;i<yinpinnum;i++){bottomPane=new JPanel();bottomPane.setLayout(new GridLayout(2,1));yinpincheck[i]=new JCheckBox("选中");yinpincheck[i].addActionListener(this);yinpincheck[i].setActionCommand(yinpinAL[i]); //增加监听器lab=new JLabel(yinpinname[i]);bottomPane.add(lab); yinpincombo[i]=new JComboBox(num); //下拉列表框yinpincombo[i].setSelectedIndex(0); //设置默认为1(第0个数)yinpincombo[i].addActionListener(this);yinpincombo[i].setActionCommand(yinpinnumAL[i]);lab=new JLabel("份");pane=new JPanel();pane.add(yinpincheck[i]); pane.add(yinpincombo[i]); pane.add(lab);bottomPane.add(pane); image= new ImageIcon(yinpintp[i]); image.setImage(image.getImage().getScaledInstance(180,120,Image.SCALE_DEFAULT));lab=new JLabel(image);zhushi[i].add(lab,BorderLayout.CENTER);zhushi[i].add(bottomPane,BorderLayout.SOUTH);}//把所有菜的面板加入到大面板中去for(int i=0;i<yinpinnum;i++) jp[3].add(zhushi[i]);jp[3].setPreferredSize(new Dimension(560,400));jsp[3]=new JScrollPane(jp[3]);jtp=new JTabbedPane();jtp.add("主食",jsp[0]);jtp.add("素食",jsp[1]);jtp.add("小吃",jsp[2]);jtp.add("饮品",jsp[3]);this.add(jtp,BorderLayout.CENTER);JPanel bottomPane=new JPanel();but=new JButton();but.setFont(new Font("宋体",Font.BOLD,20));but.setText(" 前往结账   ");but.addActionListener(this);but.setActionCommand("jiezhang");bottomPane.add(but);but=new JButton();but.setFont(new Font("宋体",Font.BOLD,20));but.setText(" 重新选菜   ");but.addActionListener(this);but.setActionCommand("chongxuan");bottomPane.add(but);but=new JButton();but.setFont(new Font("宋体",Font.BOLD,20));but.setText("   返回     ");but.addActionListener(this);but.setActionCommand("Close");bottomPane.add(but);this.add(bottomPane,BorderLayout.SOUTH);setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);setVisible(true);  //是否显示    }public int Getzhushi(String s){for(int i=0;i<zhushinum;i++) if(s==zhushiAL[i]) return i;return -1;}public int Getzhushinum(String s){for(int i=0;i<zhushinum;i++) if(s==zhushinumAL[i]) return i;return -1;}public int Getsushi(String s){for(int i=0;i<sushinum;i++) if(s==sushiAL[i]) return i;return -1;}public int Getsushinum(String s){for(int i=0;i<sushinum;i++) if(s==sushinumAL[i]) return i;return -1;}public int Getxiaochi(String s){for(int i=0;i<xiaochinum;i++) if(s==xiaochiAL[i]) return i;return -1;}public int Getxiaochinum(String s){for(int i=0;i<xiaochinum;i++) if(s==xiaochinumAL[i]) return i;return -1;}public int Getyinpin(String s){for(int i=0;i<yinpinnum;i++) if(s==yinpinAL[i]) return i;return -1;}public int Getyinpinnum(String s){for(int i=0;i<yinpinnum;i++) if(s==yinpinnumAL[i]) return i;return -1;}public void actionPerformed(ActionEvent e){if(e.getActionCommand()=="Close") this.dispose(); //关闭窗口else if(e.getActionCommand()=="jiezhang") { Check ck=new Check(this,"结账",true,orderid); }//产生结账窗口else if(e.getActionCommand()=="chongxuan"){//把所有的选择取消,并删除数据库中所有选菜内容for(int i=0;i<zhushinum;i++) { if(zhushicheck[i].isSelected())    zhushicheck[i].setSelected(false);zhushicombo[i].setSelectedIndex(0);}for(int i=0;i<sushinum;i++) {if(sushicheck[i].isSelected()) sushicheck[i].setSelected(false);zhushicombo[i].setSelectedIndex(0);}for(int i=0;i<xiaochinum;i++) {if(xiaochicheck[i].isSelected()) xiaochicheck[i].setSelected(false);xiaochicombo[i].setSelectedIndex(0);}for(int i=0;i<yinpinnum;i++){if(yinpincheck[i].isSelected()) yinpincheck[i].setSelected(false);yinpincombo[i].setSelectedIndex(0);}try{String url = "jdbc:mysql://localhost:3306/test" ;  //下面几行都是模板    String user = "root" ;   String password = "" ;Class.forName("com.mysql.jdbc.Driver");Connection conn=DriverManager.getConnection(url, user, password);PreparedStatement ps=null; ps=conn.prepareStatement("delete from OrderItem where orderid=?"); ps.setInt(1, orderid);ps.executeUpdate();        }catch(Exception exp){exp.printStackTrace();}return;}else if(e.getActionCommand()=="ViewOrder"){ View view=new View(this,"当前订单",true,orderid); }else{try{String url = "jdbc:mysql://localhost:3306/test" ;  //下面几行都是模板    String user = "root" ;   String password = "" ;Class.forName("com.mysql.jdbc.Driver");Connection conn=DriverManager.getConnection(url, user, password);PreparedStatement ps=null; int a=Getzhushi(e.getActionCommand());if(a!=-1){if(zhushicheck[a].isSelected()) {ps=conn.prepareStatement("insert into OrderItem values(?,?,?)");ps.setInt(1,orderid); ps.setString(2, zhushiAL[a]);int num=zhushicombo[a].getSelectedIndex()+1;ps.setInt(3, num);ps.executeUpdate();}else{ps=conn.prepareStatement("delete from OrderItem where orderid=? and id=?");ps.setInt(1, orderid); ps.setString(2, zhushiAL[a]);ps.executeUpdate();}return;}a=Getsushi(e.getActionCommand());if(a!=-1){if(sushicheck[a].isSelected()) {ps=conn.prepareStatement("insert into OrderItem values(?,?,?)");ps.setInt(1,orderid); ps.setString(2, sushiAL[a]);int num=sushicombo[a].getSelectedIndex()+1;ps.setInt(3, num);ps.executeUpdate();}else{ps=conn.prepareStatement("delete from OrderItem where orderid=? and id=?");ps.setInt(1, orderid); ps.setString(2, sushiAL[a]);ps.executeUpdate();}return;}a=Getxiaochi(e.getActionCommand());if(a!=-1){if(xiaochicheck[a].isSelected()) {ps=conn.prepareStatement("insert into OrderItem values(?,?,?)");ps.setInt(1,orderid); ps.setString(2, xiaochiAL[a]);int num=xiaochicombo[a].getSelectedIndex()+1;ps.setInt(3, num);ps.executeUpdate();}else{ps=conn.prepareStatement("delete from OrderItem where orderid=? and id=?");ps.setInt(1, orderid); ps.setString(2, xiaochiAL[a]);ps.executeUpdate();}return;}a=Getyinpin(e.getActionCommand());if(a!=-1){if(yinpincheck[a].isSelected()) {ps=conn.prepareStatement("insert into OrderItem values(?,?,?)");ps.setInt(1,orderid); ps.setString(2, yinpinAL[a]);int num=yinpincombo[a].getSelectedIndex()+1;ps.setInt(3, num);ps.executeUpdate();}else{ps=conn.prepareStatement("delete from OrderItem where orderid=? and id=?");ps.setInt(1, orderid); ps.setString(2, yinpinAL[a]);ps.executeUpdate();}return;}a=Getzhushinum(e.getActionCommand());if(a!=-1){if(zhushicheck[a].isSelected()){ps=conn.prepareStatement("update OrderItem set num=? where orderid=? and id=?");int num=zhushicombo[a].getSelectedIndex()+1;ps.setInt(1, num);    ps.setInt(2, orderid); ps.setString(3, zhushiAL[a]);    ps.executeUpdate();}}a=Getsushinum(e.getActionCommand());if(a!=-1){if(sushicheck[a].isSelected()){ps=conn.prepareStatement("update OrderItem set num=? where orderid=? and id=?");int num=sushicombo[a].getSelectedIndex()+1;ps.setInt(1, num);    ps.setInt(2, orderid); ps.setString(3, sushiAL[a]);    ps.executeUpdate();}}a=Getxiaochinum(e.getActionCommand());if(a!=-1){if(xiaochicheck[a].isSelected()){ps=conn.prepareStatement("update OrderItem set num=? where orderid=? and id=?");int num=xiaochicombo[a].getSelectedIndex()+1;ps.setInt(1, num);    ps.setInt(2, orderid); ps.setString(3, xiaochiAL[a]);    ps.executeUpdate();}}a=Getyinpinnum(e.getActionCommand());if(a!=-1){if(yinpincheck[a].isSelected()){ps=conn.prepareStatement("update OrderItem set num=? where orderid=? and id=?");int num=yinpincombo[a].getSelectedIndex()+1;ps.setInt(1, num);    ps.setInt(2, orderid); ps.setString(3, yinpinAL[a]);    ps.executeUpdate();}} }catch(Exception exp){exp.printStackTrace();}}}
}class View extends JDialog implements ActionListener
{JScrollPane[] jsp={null,null,null,null,null};int orderid=0;View(JDialog a,String b,boolean c,int oid){super(a,b,c);orderid=oid;this.setSize(600,600);this.setLocation(300,100);//连接数据库把选菜信息显示出来JTabbedPane jtp=new JTabbedPane();String[] sql={"select name,price,num from Dish,OrderItem where orderid=? and OrderItem.id=Dish.id","select name,price,num from Dish,OrderItem where orderid=? and OrderItem.id=Dish.id and Dish.id like 'zhushi%'","select name,price,num from Dish,OrderItem where orderid=? and OrderItem.id=Dish.id and Dish.id like 'sushi%'","select name,price,num from Dish,OrderItem where orderid=? and OrderItem.id=Dish.id and Dish.id like 'xiaochi%'","select name,price,num from Dish,OrderItem where orderid=? and OrderItem.id=Dish.id and Dish.id like 'yinpin%'"};try{String url = "jdbc:mysql://localhost:3306/test" ;  //下面几行都是模板    String user = "root" ;   String password = "" ;Class.forName("com.mysql.jdbc.Driver");Connection conn=DriverManager.getConnection(url, user, password);PreparedStatement ps=null; for(int i=0;i<5;i++){Vector ziduan=new Vector();ziduan.add("菜名"); ziduan.add("单价"); ziduan.add("数量");Vector jilu=new Vector(); //集合类      //这里就要连接数据库把信息显示出来ps=conn.prepareStatement(sql[i]); ps.setInt(1, orderid);ResultSet re=ps.executeQuery();while(re.next()){String name=re.getString(1);String price =String.format("%d", re.getInt(2));String num=String.format("%d", re.getInt(3));Vector v=new Vector();v.add(name); v.add(price); v.add(num);jilu.add(v);}JTable tab=new JTable(jilu,ziduan);//JTable是表格,里面的参数是先记录后字段tab.setFont(new Font("楷体",Font.BOLD,20));tab.setBackground(Color.CYAN);tab.setRowHeight(30);jsp[i]=new JScrollPane(tab); //滚动条}}catch(Exception exp){exp.printStackTrace();}jtp.add("所有",jsp[0]);jtp.add("主食",jsp[1]);jtp.add("素食",jsp[2]);jtp.add("小吃",jsp[3]);jtp.add("饮品",jsp[4]);this.add(jtp,BorderLayout.CENTER);JButton but=new JButton();but.setFont(new Font("宋体",Font.BOLD,20));but.setText(" 返回  ");but.addActionListener(this);but.setActionCommand("exit");JPanel pane=new JPanel();pane.add(but,BorderLayout.CENTER);this.add(pane,BorderLayout.SOUTH);setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);setVisible(true);  //是否显示}public void actionPerformed(ActionEvent e){if(e.getActionCommand()=="exit"){this.dispose();}}
}
class Check extends JDialog implements ActionListener
{JButton[] jb={null,null};int orderid=0,sum=0;Check(JDialog a,String b,boolean c,int oid){super(a,b,c);orderid=oid;this.setTitle("结账");this.setSize(600,600);this.setLocation(300,100);//连接数据库把所有选菜信息显示出来Vector ziduan=new Vector();ziduan.add("菜名"); ziduan.add("单价"); ziduan.add("数量");Vector jilu=new Vector();//连接数据库得到信息try{String url = "jdbc:mysql://localhost:3306/test" ;  //下面几行都是模板    String user = "root" ;   String password = "" ;Class.forName("com.mysql.jdbc.Driver");Connection conn=DriverManager.getConnection(url, user, password);PreparedStatement ps=null; ps=conn.prepareStatement("select name,price,num from Dish,OrderItem where orderid=? and OrderItem.id=Dish.id"); ps.setInt(1, orderid);ResultSet re=ps.executeQuery();while(re.next()){String name=re.getString(1);int p=re.getInt(2);int t=re.getInt(3);sum+=p*t;String price =String.format("%d", p);String num=String.format("%d", t);Vector v=new Vector();v.add(name); v.add(price); v.add(num);jilu.add(v);}}catch(Exception exp){exp.printStackTrace();}//加总价标签JLabel lab=new JLabel();lab.setFont(new Font("宋体",Font.BOLD,20));lab.setText("总计 "+sum+"元");lab.setHorizontalAlignment(JLabel.CENTER);this.add(lab,BorderLayout.NORTH);//加表格记录JTable tab=new JTable(jilu,ziduan);//JTable是表格,里面的参数是先记录后字段tab.setFont(new Font("楷体",Font.BOLD,20));tab.setBackground(Color.CYAN);tab.setRowHeight(30);JScrollPane jsp=new JScrollPane(tab); //滚动条    this.add(jsp,BorderLayout.CENTER);//加按钮jb[0]=new JButton();jb[0].setFont(new Font("宋体",Font.BOLD,20));jb[0].setText("  确认支付   ");jb[0].addActionListener(this);jb[0].setActionCommand("Pay");jb[1]=new JButton();jb[1].setFont(new Font("宋体",Font.BOLD,20));jb[1].setText("  返回    ");jb[1].addActionListener(this);jb[1].setActionCommand("Close");JPanel bottomPane=new JPanel();bottomPane.add(jb[0]); bottomPane.add(jb[1]);this.add(bottomPane,BorderLayout.SOUTH);setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);setVisible(true);  //是否显示}public void actionPerformed(ActionEvent e){//if(e.getActionCommand()=="Close"){this.dispose();}else if(e.getActionCommand()=="Pay"){try{String url = "jdbc:mysql://localhost:3306/test" ;  //下面几行都是模板    String user = "root" ;   String password = "" ;Class.forName("com.mysql.jdbc.Driver");Connection conn=DriverManager.getConnection(url, user, password);PreparedStatement ps=null; ps=conn.prepareStatement("update OrderDish set money=? where orderid=?");ps.setInt(1, sum); ps.setInt(2, orderid);ps.executeUpdate();                }catch(Exception exp){exp.printStackTrace();}Pay pay=new Pay(this,"支付",true);}}
}class Pay extends JDialog implements ActionListener
{JTabbedPane jtp=null;JButton jb=null;JPanel bottomPane=null;JLabel[] jl={null,null,null,null};ImageIcon image=null;Pay(JDialog a,String b,boolean c){super(a,b,c);this.setSize(600,600);this.setLocation(400,100);image= new ImageIcon("Image/zhifubao.PNG"); image.setImage(image.getImage().getScaledInstance(600,500,Image.SCALE_DEFAULT));jl[0]=new JLabel(image);image= new ImageIcon("Image/weixin.PNG"); image.setImage(image.getImage().getScaledInstance(600,500,Image.SCALE_DEFAULT));jl[1]=new JLabel(image);image= new ImageIcon("Image/wangyin.PNG"); image.setImage(image.getImage().getScaledInstance(600,500,Image.SCALE_DEFAULT));jl[2]=new JLabel(image);image= new ImageIcon("Image/xianjing.PNG"); image.setImage(image.getImage().getScaledInstance(600,500,Image.SCALE_DEFAULT));jl[3]=new JLabel(image);jtp=new JTabbedPane();jtp.add("支付宝支付",jl[0]);jtp.add(" 微信支付  ",jl[1]);jtp.add(" 网银支付  ",jl[2]);jtp.add(" 现金支付  ",jl[3]);this.add(jtp,BorderLayout.CENTER);jb=new JButton();jb.setFont(new Font("宋体",Font.BOLD,20));jb.setText("   完成退出      ");jb.addActionListener(this);jb.setActionCommand("exit");bottomPane=new JPanel();bottomPane.add(jb);this.add(bottomPane,BorderLayout.SOUTH);setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);setVisible(true);  }public void actionPerformed(ActionEvent e){if(e.getActionCommand()=="exit"){this.dispose();}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/309850.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[C++11]委托构造函数

委托构造函数允许使用同一个类中的一个构造函数调用其他的构造函数&#xff0c;从而简化相关变量的初始化。 注意点: 1.这种链式的构造函数调用不能形成一个闭环(死循环)&#xff0c;否则会在运行期抛异常。 2.如果要进行多层构造函数的链式调用&#xff0c;建议将构造函数的…

基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目

首先&#xff0c;默认咱们已经有了.net core 3.1的开发环境&#xff0c;如果你没有&#xff0c;快去下载... https://dotnet.microsoft.com/download由于项目是基于abp vNext开发的&#xff0c;所以开发之前建议去撸一遍abp官方文档&#xff0c;https://docs.abp.io/en/abp/lat…

[C++11]统一的数据初始化方式 - 初始化列表

关于C中的变量&#xff0c;数组&#xff0c;对象等都有不同的初始化方法&#xff0c;在这些繁琐的初始化方法中没有任何一种方式适用于所有的情况。为了统一初始化方式&#xff0c;并且让初始化行为具有确定的效果&#xff0c;在C11中提出了列表初始化的概念。 代码如下: #in…

Sql Server之旅——第三站 解惑那些背了多年聚集索引的人

说到聚集索引&#xff0c;我想每个码农都明白&#xff0c;但是也有很多像我这样的伪程序员&#xff0c;只能用死记硬背来解决这个问题&#xff0c;什么表中只能建一个聚集索引&#xff0c;然后又扯到了目录查找来帮助读者记忆。。。。问题就在这里&#xff0c;我们不是学文科&a…

懂「互联网语」的程序员,是个狠人。

借用一下时下很火的「互联网语」做程序员的乐趣是只有进场的人才能获得的红利与程序员相处绝对是令人WOW的用户体验但是别真信那些个程序员说的话哪怕有无数江湖传言为他背书不然你良久建立的心智模型会在瞬间就崩塌毕竟头部程序员和腰腿部程序员之间的壁垒打通不了也许你暂时还…

c语言oj合法标识符,YTUOJ-C语言合法标识符

Description输入一个字符串&#xff0c;判断其是否是C的合法标识符。Input输入数据包含多个测试实例&#xff0c;数据的第一行是一个整数n,表示测试实例的个数&#xff0c;然后是n行输入数据&#xff0c;每行是一个长度不超过50的字符串。Output对于每组输入数据&#xff0c;输…

[C++11]initializer_lisr模板类的使用

代码如下: #include <iostream> using namespace std;void func(initializer_list<int> ls) {auto it ls.begin();for (; it ! ls.end(); it){cout << *it << " ";}cout << endl; }int main() {func({ 1,2,5,12,23 });return 0; }测…

linux tcp 创建,Linux下tcp服务器创建的步骤

创建一个socket&#xff0c;使用函数socket()socket(套接字)实质上提供了进程通信的端点&#xff0c;进程通信之前&#xff0c;双方首先必须建立各自的一个端点&#xff0c;否则没有办法通信。通过socket将IP地址和端口绑定之后&#xff0c;客户端就可以和服务器通信了#include…

基于 abp vNext 和 .NET Core 开发博客项目 - 数据访问和代码优先

上一篇文章完善了项目中的代码&#xff0c;接入了Swagger。本篇主要使用Entity Framework Core完成对数据库的访问&#xff0c;以及使用Code-First的方式进行数据迁移&#xff0c;自动创建表结构。数据访问在.EntityFrameworkCore项目中添加我们的数据访问上下文对象MeowvBlogD…

[C++11]使用using和typedef给模板定义别名

using语法和typedef一样&#xff0c;并不会创建出新的类型&#xff0c;它们只是给某些类型定义了新的别名。using相较于typedef的优势在于定义函数指针别名时看起来更加直观&#xff0c;并且可以给模板定义别名。 使用typedef给模板定义别名: 无法直接使用typedef给模板定义别…

Azure Show|第一期 开播啦!嘉宾梁迪李卓恒李佳芮

欢迎来到Azure Show!Azure ShowAzure Show 是由微软最有价值专家、微软技术社区区域总监卢建晖和微软开发者关系PM朱兴亮共同发起的一个关于微软Azure、开源技术、还有技术社区相关的线上节目。每期节目由MVP面对面、开源故事、从零开始以及Azure101组成&#xff0c;邀请微软技…

基于 abp vNext 和 .NET Core 开发博客项目 - 完善与美化,Swagger登场

上一篇文章(https://www.cnblogs.com/meowv/p/12896898.html)已经成功将博客项目跑起来了&#xff0c;那么本篇主要是将之前遗留的问题解决&#xff0c;现在的代码看起来可能还是比较混乱&#xff0c;有大量与之无关的代码存在里面&#xff0c;对于强迫症患者来说真的是零容忍。…

[C++11]基于范围的for循环

C11提供了一种新型的for循环形式 - 基于范围的for循环 语法: for (declaration : expression) {//循环体 }在上面的语法格式中&#xff0c;declaration表示遍历声明&#xff0c;在遍历过程中&#xff0c;当前被遍历到的元素会被存储到声明的变量中&#xff0c;expression是要…

c语言画笔的使用方法,新手必看:Photoshop笔刷画笔工具基本使用教程

本文为Photoshop初学者提供基本的Photoshop笔刷画笔工具的基本使用方法,这可以说是Photoshop最重要的功能。希望初学PS朋友认真学习&#xff0c;有所帮助&#xff01;工具/原料Photoshop CC 2014或者其他较新版本的psPhotoshop笔刷画笔工具介绍&#xff1a;1、画笔工具在哪里呢…

基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来

上一篇文章(https://www.cnblogs.com/meowv/p/12896177.html)已经成功创建了博客项目&#xff0c;但是abp默认给我们引用了许多项目中用不到的组件。本篇文章将给项目进行瘦身&#xff0c;删掉对我们来说暂时用不到的组件。讲解各个模块之间的关系&#xff0c;写一个Hello Worl…

计算机网络原理第一章习题3-24 3-25

计算机网络原理第一章习题 3-24假定站点A和B在同一个10Mb/s以太网网段上。这两个站点之间的传播时延为225比特时间。现假定A开始发送一帧&#xff0c;并且在A发送结束之前B也发送一帧。如果A发送的是以太网所容许的最短的帧&#xff0c;那么A在检测到和B发生碰撞之前能否把自己…

[C++11]可调用对象

在C中存在"可调用对象"这么一个概念&#xff0c;准确来说&#xff0c;可调用对象有如下几种定义: 1.是一个函数指针 代码如下: int print(int a, double b) {cout << a << b << endl;return 0; }int(*func)(int, double) &print;2.是一个具…

c语言加花指令,花指令的应用

原标题&#xff1a;花指令的应用对免杀的影响是非常大的&#xff0c;有效地利用花指令可以使免杀工作事半功倍&#xff0c;甚至单凭花指令就可以达到免杀的效果。一、花指令在免杀领域的应用1、花指令的应用技巧在使用之前&#xff0c;首先我们应该明白什么时候比较适合使用&am…

走向统一的 .NET 旅程

这是微软第一次完全线上举办的Build大会&#xff0c;也是第一次完全属于开发者的大会。几乎所有的新产品都是属于开发者&#xff0c;开发者成为了唯一的主角。现在的微软比以往任何时候都贴近开发者&#xff0c;重视开发者的作用&#xff0c;为他们打造平台和工具。因为没有开发…

[PAT乙级]1039 到底买不买

小红想买些珠子做一串自己喜欢的珠串。卖珠子的摊主有很多串五颜六色的珠串&#xff0c;但是不肯把任何一串拆散了卖。于是小红要你帮忙判断一下&#xff0c;某串珠子里是否包含了全部自己想要的珠子&#xff1f;如果是&#xff0c;那么告诉她有多少多余的珠子&#xff1b;如果…