目录

时间安排... 1

代码清单... 2

CaidanS.java(厨师管理菜单的界面)... 2

caidan.java(顾客点菜的菜单界面)... 10

Denglu.java(登录)... 16

Zhuce.java(注册)... 20

dingdanS.java(厨师查看、编辑、删除订单界面)... 25

Home.java(初始主界面)... 29

时间安排

以下是我的时间安排:

10月27日

需求分析、功能设计、界面设计、数据库设计

10月28日

弄清JAVA的布局、容器、监听器等层次、关系和作用,主界面代码实现

10月29日

连接数据库,登录、注册界面和功能实现,顾客、厨师身份区别

10月30日

面条、小菜的图片绘制

10月31日

利用POI读写Excel文件,一键配置菜单功能实现,且保存菜单到数据库

11月1日

堂吃和订座的选座功能实现(桌号状态连接数据库记录)

11月2日

顾客的菜单界面实现,从数据库读取菜单

11月3日

实现顾客从菜单最后一列输入购买数量的功能,监听表格被修改的内容,保存到数据库(即生成订单)

11月4日

实现厨师查看、编辑、删除订单的功能

11月5日

测试与改进

代码清单

写了三十多个.java文件,实在懒得一个个打开复制粘贴代码了,而且全放进来的话估计至少有五千行,也看不过来,所以我只放几个核心的。

CaidanS.java(厨师管理菜单的界面)

import java.awt.EventQueue;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.File;

import java.io.FileInputStream;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.util.ArrayList;

import java.util.Vector;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JFileChooser;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTable;

importjavax.swing.filechooser.FileSystemView;

import javax.swing.table.DefaultTableModel;

importorg.apache.poi.hssf.usermodel.HSSFSheet;

importorg.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.Row;

import java.awt.Color;

import javax.swing.JButton;

import java.awt.Font;

public class caidanS {

privateJFrame frame;

privateJTable noodle;

privateJTable dish;

privateJButton setNoodle;

privateJButton setDish;

ArrayList<noodle>noodles = null;

ArrayList<dish>dishs = null;

/**

* Launch the application.

*/

publicstatic void main(String[] args) {

EventQueue.invokeLater(newRunnable() {

publicvoid run() {

try{

caidanSwindow = new caidanS();

window.frame.setVisible(true);

}catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the application.

*/

publiccaidanS() {

initialize();

}

/**

* Initialize the contents of the frame.

*/

privatevoid initialize() {

frame= new JFrame();

frame.setTitle("食面埋伏® 菜单 (您的身份是:厨师)");

frame.setBounds(100,100, 1280, 780);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

noodle= new JTable(new Object[][]{},new String[]{"类型", "价格","图片"});

noodle.setFont(newFont("微软雅黑", Font.PLAIN, 22));

noodle.setBackground(Color.ORANGE);

noodle.setModel(newDefaultTableModel(

newObject[][] {

},

newString[] {

"类型","价格", "图片"

}

){

Class[]columnTypes = new Class[] {

String.class,Double.class, ImageIcon.class

};

publicClass getColumnClass(int columnIndex) {

returncolumnTypes[columnIndex];

}

});

noodle.setBounds(340,50, 500, 300);

noodle.setRowHeight(60);

noodle.setPreferredSize(null);

frame.getContentPane().add(noodle);

noodle.getColumnModel().getColumn(0).setPreferredWidth(100);

noodle.getColumnModel().getColumn(1).setPreferredWidth(50);

noodle.getColumnModel().getColumn(2).setPreferredWidth(250);

dish= new JTable(new Object[][]{},new String[]{"类型", "量","价格","图片"});

dish.setFont(newFont("微软雅黑", Font.PLAIN, 22));

dish.setBackground(Color.CYAN);

dish.setModel(newDefaultTableModel(

newObject[][] {

},

newString[] {

"\u7C7B\u578B","\u91CF", "\u4EF7\u683C", "\u56FE\u7247"

}

){

Class[]columnTypes = new Class[] {

String.class,String.class, Double.class, ImageIcon.class

};

publicClass getColumnClass(int columnIndex) {

returncolumnTypes[columnIndex];

}

});

dish.setBounds(340,370, 500, 300);

dish.setRowHeight(33);

frame.getContentPane().add(dish);

dish.getColumnModel().getColumn(0).setPreferredWidth(100);

dish.getColumnModel().getColumn(1).setPreferredWidth(50);

dish.getColumnModel().getColumn(2).setPreferredWidth(50);

dish.getColumnModel().getColumn(3).setPreferredWidth(250);

Stringdriver = "com.mysql.jdbc.Driver";

String dbName = "NoodleRestaurant";

String passwrod = "19961225";

String userName = "root";

String url = "jdbc:mysql://localhost:3306/" + dbName;

String sql = "insert into noodle values(?,?,?) ";

setNoodle= new JButton("\u4E00\u952E\u914D\u7F6E\u9762\u6761");

setNoodle.setBounds(900,150, 140, 29);

setNoodle.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent e) {

try{

noodles= ReadNoodleFile();

DefaultTableModelnoom =  (DefaultTableModel)noodle.getModel();

Class.forName(driver);

Connection conn =DriverManager.getConnection(url, userName,

passwrod);

PreparedStatement ps =conn.prepareStatement(sql);

for(noodle n : noodles){

Vectorv = new Vector();

v.add(n.name);

v.add(n.price);

File f = new File(n.path);

if (f.exists()) {

v.add(new ImageIcon(n.path));

ps.setString(3, n.path);

}

ps.setString(1, n.name);

ps.setDouble(2, n.price);

ps.executeUpdate();

noom.addRow(v);

}

ps.close();

conn.close();

intoption=JOptionPane.showConfirmDialog(null, "面条配置成功!\n是否返回主页面?");

if(option==JOptionPane.YES_OPTION){

frame.dispose();

HomeS.main(null);

}

}catch(Exception e1) {

System.out.println(e1);

}

}

});

frame.getContentPane().add(setNoodle);

setDish= new JButton("\u4E00\u952E\u914D\u7F6E\u5C0F\u83DC");

setDish.setBounds(900,500, 140, 29);

setDish.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent e) {

try{

dishs= ReadDishFile();

DefaultTableModeldism =  (DefaultTableModel)dish.getModel();

Stringsql2 = "insert into dish values(?,?,?,?) ";

Class.forName(driver);

Connection conn = DriverManager.getConnection(url,userName,

passwrod);

PreparedStatement ps2 =conn.prepareStatement(sql2);

for(dish d : dishs){

Vectorv2 = new Vector();

v2.add(d.name);

v2.add(d.amount);

v2.add(d.price);

File f2 = new File(d.path);

if (f2.exists()) {

v2.add(new ImageIcon(d.path));

ps2.setString(4, d.path);

}

ps2.setString(1, d.name);

ps2.setString(2, d.amount);

ps2.setDouble(3, d.price);

ps2.executeUpdate();

dism.addRow(v2);

}

ps2.close();

conn.close();

int option2=JOptionPane.showConfirmDialog(null,"小菜配置成功!\n是否返回主页面?");

if(option2==JOptionPane.YES_OPTION){

frame.dispose();

HomeS.main(null);

}

}catch (Exception e1) {

//TODO Auto-generated catch block

e1.printStackTrace();

}

}

});

frame.getContentPane().add(setDish);

JPanelpanel = new JPanel();

panel.setBounds(0,0, 1280, 780);

frame.getContentPane().add(panel);

Iconi=new ImageIcon("D:\\PS\\material\\noodle\\bg.jpg"); /*用源图片“背景.jpg”构造一个ImageIcon对象i,需要注意如果图片的路径使用的是相对路径,则图片文件必须放在类文件所在文件夹或项目的根文件夹中,否则图片的路径必须用绝对路径。*/

JLabellb = new JLabel(i); //用指定的图片构造标签对象lb

frame.getLayeredPane().add(lb,new Integer(Integer.MIN_VALUE));

//把标签放在第二层JlayerPane上。

lb.setBounds(0,0,i.getIconWidth(),i.getIconHeight());

//设置标签的尺寸,即背景图象的大小。

panel.setOpaque(false);;

panel.add(lb);

}

publicstatic ArrayList<noodle> ReadNoodleFile() throws Exception {

//TODO Auto-generated method stub

JFileChooserfileChooser = new JFileChooser();

ArrayListtemp = new ArrayList();

if(fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {

java.io.Filefile = fileChooser.getSelectedFile();

FileInputStreamfileIn = new FileInputStream(file);

//根据指定的文件输入流导入Excel从而产生Workbook对象

HSSFWorkbookwb0 = new HSSFWorkbook(fileIn);

//获取Excel文档中的第一个表单

HSSFSheetsht0 = wb0.getSheetAt(0);

//对Sheet中的每一行进行迭代

intr;

introwNum = sht0.getPhysicalNumberOfRows();

for(r = 1; r <= rowNum; r++) {

Rowrow = sht0.getRow(r);

if(row == null) {

break;

}

//创建实体类

noodleinfo=new noodle();

//取出当前行第1个单元格数据,并封装在info实体stuName属性上

info.setName(row.getCell(0).getStringCellValue());

info.setPrice(row.getCell(1).getNumericCellValue());

info.setPath(row.getCell(2).getStringCellValue());

temp.add(info);

}

fileIn.close();

}

else{

System.out.println("Nofile selected");

}

returntemp;

}

publicstatic ArrayList<dish> ReadDishFile() throws Exception {

//TODO Auto-generated method stub

JFileChooserfileChooser = new JFileChooser();

ArrayListtemp = new ArrayList();

if(fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {

java.io.Filefile = fileChooser.getSelectedFile();

FileInputStream fileIn = newFileInputStream(file);

//根据指定的文件输入流导入Excel从而产生Workbook对象

HSSFWorkbookwb0 = new HSSFWorkbook(fileIn);

//获取Excel文档中的第一个表单

HSSFSheetsht0 = wb0.getSheetAt(0);

//对Sheet中的每一行进行迭代

intr;

introwNum = sht0.getPhysicalNumberOfRows();

for(r = 1; r <= rowNum; r++) {

Rowrow = sht0.getRow(r);

if(row == null) {

break;

}

//创建实体类

dishinfo=new dish();

//取出当前行第1个单元格数据,并封装在info实体stuName属性上

info.setName(row.getCell(0).getStringCellValue());

info.setAmount(row.getCell(1).getStringCellValue());

info.setPrice(row.getCell(2).getNumericCellValue());

info.setPath(row.getCell(3).getStringCellValue());

temp.add(info);

}

fileIn.close();

}

else{

System.out.println("Nofile selected");

}

returntemp;

}

}

caidan.java(顾客点菜的菜单界面)

import java.awt.EventQueue;

import java.awt.Font;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.Vector;

import javax.swing.CellEditor;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTable;

import javax.swing.table.DefaultTableModel;

import java.awt.Color;

import javax.swing.JButton;

import javax.swing.JTextPane;

/* 顾客看到的菜单界面 --ZYP */

public class caidan {

privateJFrame frame;

privateJTable noodle;

privateJTable dish;

privateJButton buy;

/**

* Launch the application.

*/

publicstatic void main(String[] args) {

EventQueue.invokeLater(newRunnable() {

publicvoid run() {

try{

caidanwindow = new caidan();

window.frame.setVisible(true);

}catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the application.

*/

publiccaidan() {

initialize();

}

/**

* Initialize the contents of the frame.

*/

privatevoid initialize() {

frame= new JFrame();

frame.setTitle("\u98DF\u9762\u57CB\u4F0F\u00AE\u83DC\u5355 \uFF08\u60A8\u7684\u8EAB\u4EFD\u662F\uFF1A\u987E\u5BA2\uFF09");

frame.setBounds(100,100, 1280, 780);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

dish= new JTable();

dish.setFont(newFont("微软雅黑", Font.PLAIN, 22));

dish.setBackground(Color.CYAN);

dish.setModel(newDefaultTableModel(new Object[][] {

},

newString[] {

"\u7C7B\u578B","\u91CF", "\u4EF7\u683C", "\u56FE\u7247","\u6570\u91CF"

}){

Class[]columnTypes = new Class[] {

String.class,String.class, Double.class, ImageIcon.class, Integer.class

};

publicClass getColumnClass(int columnIndex) {

returncolumnTypes[columnIndex];

}

});

dish.setBounds(340,370, 500, 300);

dish.setRowHeight(33);

frame.getContentPane().add(dish);

dish.getColumnModel().getColumn(0).setPreferredWidth(100);

dish.getColumnModel().getColumn(1).setPreferredWidth(50);

dish.getColumnModel().getColumn(2).setPreferredWidth(50);

dish.getColumnModel().getColumn(3).setPreferredWidth(250);

dish.getColumnModel().getColumn(3).setPreferredWidth(50);

noodle= new JTable();

noodle.setFont(newFont("微软雅黑", Font.PLAIN, 22));

noodle.setBackground(Color.ORANGE);

noodle.setModel(newDefaultTableModel(

newObject[][] {

},

newString[] {

"\u7C7B\u578B","\u4EF7\u683C", "\u56FE\u7247", "\u6570\u91CF"

}

){

Class[]columnTypes = new Class[] {

String.class,Double.class, ImageIcon.class, Integer.class

};

publicClass getColumnClass(int columnIndex) {

returncolumnTypes[columnIndex];

}

});

noodle.setBounds(340,50, 500, 300);

noodle.setRowHeight(60);

frame.getContentPane().add(noodle);

noodle.getColumnModel().getColumn(0).setPreferredWidth(100);

noodle.getColumnModel().getColumn(1).setPreferredWidth(50);

noodle.getColumnModel().getColumn(2).setPreferredWidth(250);

noodle.getColumnModel().getColumn(3).setPreferredWidth(50);

/*表格列宽根据窗口大小调整比例自适应  --ZYP */

JOptionPane.showMessageDialog(null,"请在菜单每行末尾\n修改您的购买数量^_^");

/*设置按钮,点击后保存表格修改内容到数据库  --ZYP*/

buy= new JButton("\u786E\u8BA4\u8D2D\u4E70");

buy.setBounds(900,350, 123, 29);

buy.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent e) {

testt = new test();

t.orderID++;

try{

intnrow = noodle.getSelectedRow();

intncol = noodle.getSelectedColumn();

intdrow = dish.getSelectedRow();

intdcol = dish.getSelectedColumn();

CellEditornce = noodle.getCellEditor(nrow, ncol);

nce.stopCellEditing();

CellEditordce = dish.getCellEditor(drow, dcol);

dce.stopCellEditing();

}catch(Exception e1) {

System.out.println(e1);

}

Stringdriver = "com.mysql.jdbc.Driver";

String dbName ="NoodleRestaurant";

String passwrod = "19961225";

String userName = "root";

String url ="jdbc:mysql://localhost:3306/" + dbName;

String sql = "insert intoorderDetail values(?,?,?,?,?,?)";

try {

DefaultTableModel noom =  (DefaultTableModel) noodle.getModel();

DefaultTableModel dism =  (DefaultTableModel) dish.getModel();

Class.forName(driver);

Connection conn =DriverManager.getConnection(url, userName,

passwrod);

PreparedStatement ps =conn.prepareStatement(sql);

PreparedStatement ps2 =conn.prepareStatement(sql);

inti , num;

intj = noom.getRowCount();

intk = dism.getRowCount();

for(i = 0; i < j; i++) {

num= (int) noom.getValueAt(i, 3);

if(num != 0)

{

ps.setInt(1,t.orderID);

ps.setString(2,(String) noom.getValueAt(i, 0));

ps.setString(3, null);

ps.setDouble(4,(double) noom.getValueAt(i, 1));

ps.setInt(5,(int) noom.getValueAt(i, 3));

ps.setDouble(6,((double) noom.getValueAt(i, 1) * (int)noom.getValueAt(i, 3)));

ps.executeUpdate();

}

}

ps.close();

for(i = 0; i < k; i++) {

num= (int) dism.getValueAt(i, 4);

if(num != 0)

{

ps2.setInt(1,t.orderID);

ps2.setString(2,(String) dism.getValueAt(i, 0));

ps2.setString(3,(String) dism.getValueAt(i, 1));

ps2.setDouble(4,(double) dism.getValueAt(i, 2));

ps2.setInt(5,(int) dism.getValueAt(i, 4));

ps2.setDouble(6,((double) dism.getValueAt(i, 2) * (int)dism.getValueAt(i, 4)));

ps2.executeUpdate();

}

}

ps2.close();

conn.close();

intoption=JOptionPane.showConfirmDialog(null, "购买成功!\n是否返回主页面?");

if(option==JOptionPane.YES_OPTION){

frame.dispose();

HomeB.main(null);

return;

}

}catch (Exception e1) {

System.out.println(e1);

}

}

});

frame.getContentPane().add(buy);

JPanelpanel = new JPanel();

panel.setBounds(0,0, 1280, 780);

frame.getContentPane().add(panel);

Iconi=new ImageIcon("D:\\PS\\material\\noodle\\bg.jpg"); /*用源图片“背景.jpg”构造一个ImageIcon对象i,需要注意如果图片的路径使用的是相对路径,则图片文件必须放在类文件所在文件夹或项目的根文件夹中,否则图片的路径必须用绝对路径。*/

JLabellb = new JLabel(i); //用指定的图片构造标签对象lb

frame.getLayeredPane().add(lb,new Integer(Integer.MIN_VALUE));

//把标签放在第二层JlayerPane上。

lb.setBounds(0,0,i.getIconWidth(),i.getIconHeight());

//设置标签的尺寸,即背景图象的大小。

panel.setOpaque(false);;

panel.add(lb);

Stringdriver = "com.mysql.jdbc.Driver";

String dbName = "NoodleRestaurant";

String passwrod = "19961225";

String userName = "root";

String url = "jdbc:mysql://localhost:3306/" + dbName;

String sql = "select * from noodle";

String sql2 = "select * from dish";

try {

DefaultTableModelnoom =  (DefaultTableModel)noodle.getModel();

DefaultTableModeldism =  (DefaultTableModel)dish.getModel();

Class.forName(driver);

Connection conn = DriverManager.getConnection(url, userName,

passwrod);

PreparedStatement ps = conn.prepareStatement(sql);

PreparedStatement ps2 = conn.prepareStatement(sql2);

ResultSet rs = ps.executeQuery(sql);

while (rs.next()) {

Vector v = new Vector();

v.add(rs.getString(1));

v.add(rs.getDouble(2));

v.add(new ImageIcon(rs.getString(3)));

v.add(0);

noom.addRow(v);

}

rs.close();

ps.close();

ResultSet rs2 = ps2.executeQuery(sql2);

while (rs2.next()) {

Vector v = new Vector();

v.add(rs2.getString(1));

v.add(rs2.getString(2));

v.add(rs2.getDouble(3));

v.add(new ImageIcon(rs2.getString(4)));

v.add(0);

dism.addRow(v);

}

rs2.close();

ps2.close();

conn.close();

}catch (SQLException e) {

System.out.println("MySQL操作错误");

e.printStackTrace();

}catch (Exception e) {

e.printStackTrace();

}finally {

}

}

}

Denglu.java(登录)

import java.awt.EventQueue;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.JPasswordField;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import java.awt.Color;

public class denglu {

privateJFrame frame;

privateJTextField yhm;

privateJPasswordField mm;

/**

* Launch the application.

*/

publicstatic void main(String[] args) {

EventQueue.invokeLater(newRunnable() {

publicvoid run() {

try{

dengluwindow = new denglu();

window.frame.setVisible(true);

}catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the application.

*/

publicdenglu() {

initialize();

}

/**

* Initialize the contents of the frame.

*/

privatevoid initialize() {

frame= new JFrame();

frame.setTitle("\u98DF\u9762\u57CB\u4F0F\u00AE\u767B\u5F55");

frame.setBounds(100,100, 1280, 780);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

yhm= new JTextField();

yhm.setText("");

yhm.setBounds(600,148, 200, 27);

frame.getContentPane().add(yhm);

yhm.setColumns(10);

mm= new JPasswordField();

mm.setText("");

mm.setBounds(600,255, 200, 27);

frame.getContentPane().add(mm);

JButtonloginButton = new JButton("\u767B\u5F55");

loginButton.setBackground(Color.CYAN);

loginButton.setBounds(575, 500, 123,29);

frame.getContentPane().add(loginButton);

loginButton.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent a) {

//TODO Auto-generated method stub

Stringyh = yhm.getText(),

psw= mm.getText();

Stringdriver = "com.mysql.jdbc.Driver";

String dbName ="NoodleRestaurant";

String passwrod = "19961225";

String userName = "root";

String url ="jdbc:mysql://localhost:3306/" + dbName;

String sql = "select * from userwhere ID =?";

int status;

try {

Class.forName(driver);

Connection conn =DriverManager.getConnection(url, userName,

passwrod);

PreparedStatement ps =conn.prepareStatement(sql);

ps.setString(1, yh);

ResultSet rs = ps.executeQuery();

if (!rs.next()) {

JOptionPane.showMessageDialog(null,"用户名不存在!");

return;

}

else if(!(psw.equals(rs.getString(3)))) {

JOptionPane.showMessageDialog(null,"密码错误!");

return;

}

else {

status= rs.getInt(4);

if(status == 1){

test.flag  = 1;

JOptionPane.showMessageDialog(null,"来掌管你的世界吧,伟大的厨师!");

}

if(status == 0) {

test.flag= 0;

JOptionPane.showMessageDialog(null,"欢迎您回来,祝您用餐愉快!");

}

frame.dispose();

test.testHome();

}

// 关闭记录集

if (rs != null) {

try {

rs.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

// 关闭声明

if (ps != null) {

try {

ps.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

// 关闭链接对象

if (conn != null) {

try {

conn.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

});

JPanelpanel = new JPanel();

panel.setBounds(0,0, 1280, 780);

frame.getContentPane().add(panel);

Iconi=new ImageIcon("D:\\PS\\material\\noodle\\denglu.jpg"); /*用源图片“背景.jpg”构造一个ImageIcon对象i,需要注意如果图片的路径使用的是相对路径,则图片文件必须放在类文件所在文件夹或项目的根文件夹中,否则图片的路径必须用绝对路径。*/

JLabellb = new JLabel(i); //用指定的图片构造标签对象lb

frame.getLayeredPane().add(lb,new Integer(Integer.MIN_VALUE));

//把标签放在第二层JlayerPane上。

lb.setBounds(0,0,i.getIconWidth(),i.getIconHeight());

//设置标签的尺寸,即背景图象的大小。

panel.setOpaque(false);;

panel.add(lb);

}

}

Zhuce.java(注册)

import java.awt.EventQueue;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.JPasswordField;

import javax.swing.JRadioButton;

import javax.swing.ButtonGroup;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import java.awt.Color;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

public class zhuce {

privateJFrame frame;

privateJTextField nicheng;

privateJTextField yhm;

privateJPasswordField mm;

privateJPasswordField qrmm;

/**

* Launch the application.

*/

publicstatic void main(String[] args) {

EventQueue.invokeLater(newRunnable() {

publicvoid run() {

try{

zhucewindow = new zhuce();

window.frame.setVisible(true);

}catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the application.

*/

publiczhuce() {

initialize();

}

/**

* Initialize the contents of the frame.

*/

privatevoid initialize() {

frame= new JFrame();

frame.setTitle("\u98DF\u9762\u57CB\u4F0F\u00AE\u6CE8\u518C");

frame.setBounds(100,100, 1280, 780);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

nicheng= new JTextField();

nicheng.setBounds(600,385, 200, 27);

frame.getContentPane().add(nicheng);

yhm= new JTextField();

yhm.setBounds(600,128, 200, 27);

frame.getContentPane().add(yhm);

mm= new JPasswordField();

mm.setBounds(600,215, 200, 27);

frame.getContentPane().add(mm);

qrmm= new JPasswordField();

qrmm.setBounds(600,299, 200, 27);

frame.getContentPane().add(qrmm);

JRadioButtongukeButton = new JRadioButton("\u987E\u5BA2");

gukeButton.setBounds(600,487, 72, 29);

frame.getContentPane().add(gukeButton);

JRadioButtonchushiButton = new JRadioButton("\u53A8\u5E08");

chushiButton.setBounds(720,487, 72, 29);

frame.getContentPane().add(chushiButton);

JButtonzhuceButton = new JButton("\u6CE8\u518C");

zhuceButton.setBackground(Color.ORANGE);

zhuceButton.setBounds(575,580, 123, 29);

frame.getContentPane().add(zhuceButton);

zhuceButton.addActionListener(newActionListener(){

publicvoid actionPerformed(ActionEvent a){

//TODO Auto-generated method stub

Stringyh = yhm.getText(),

psw= mm.getText(),

again= qrmm.getText(),

nc= nicheng.getText();

if("".equals(yh)){

JOptionPane.showMessageDialog(null,"用户名空了");

return;}

if(yh.length()<4||yh.length()>20){

JOptionPane.showMessageDialog(null,"用户名不合格,长度应在4~20位之间");

return;}

if("".equals(psw)){

JOptionPane.showMessageDialog(null,"密码空了");

return;}

if(psw.length()<6||psw.length()>20){

JOptionPane.showMessageDialog(null,"密码不合格,长度应在6~20位之间");

return;}

if("".equals(again)){

JOptionPane.showMessageDialog(null,"确认密码为空");

return;}

if(!psw.equals(again)){

JOptionPane.showMessageDialog(null,"两次密码不一致,请从新输入");

return;}

if(nc.length()<1||nc.length()>20){

JOptionPane.showMessageDialog(null,"昵称不合格,长度应在1~20位之间");

return;}

Stringdriver = "com.mysql.jdbc.Driver";

String dbName ="NoodleRestaurant";

String passwrod = "19961225";

String userName = "root";

String url ="jdbc:mysql://localhost:3306/" + dbName;

String sql = "insert into uservalues(?,?,?,?) ";

int status = 0;

if(gukeButton.isSelected()) {

status = 0;

}

if(chushiButton.isSelected()) {

status= 1;

}

try{

Class.forName(driver);

Connection conn =DriverManager.getConnection(url, userName,

passwrod);

PreparedStatement ps =conn.prepareStatement(sql);

ps.setString(1, yh);

ps.setString(2, nc);

ps.setString(3, psw);

ps.setInt(4, status);

ps.executeUpdate();

ps.close();

conn.close();

} catch (Exception e) {

System.out.println(e);

}

JOptionPane.showMessageDialog(null,"注册成功!");

frame.dispose();

}

});

ButtonGroupbtg=new ButtonGroup();

btg.add(gukeButton);

btg.add(chushiButton);

JPanelpanel = new JPanel();

panel.setBounds(0,0, 1280, 780);

frame.getContentPane().add(panel);

Iconi=new ImageIcon("D:\\PS\\material\\noodle\\zhuce0.jpg"); /*用源图片“背景.jpg”构造一个ImageIcon对象i,需要注意如果图片的路径使用的是相对路径,则图片文件必须放在类文件所在文件夹或项目的根文件夹中,否则图片的路径必须用绝对路径。*/

JLabellb = new JLabel(i); //用指定的图片构造标签对象lb

frame.getLayeredPane().add(lb,new Integer(Integer.MIN_VALUE));

//把标签放在第二层JlayerPane上。

lb.setBounds(0,0,i.getIconWidth(),i.getIconHeight());

//设置标签的尺寸,即背景图象的大小。

panel.setOpaque(false);;

panel.add(lb);

}

}

dingdanS.java(厨师查看、编辑、删除订单界面)

import java.awt.EventQueue;

import javax.swing.Icon;

import javax.swing.ImageIcon;

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 java.awt.Color;

import java.awt.Font;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.Vector;

import javax.swing.table.DefaultTableModel;

import javax.swing.JButton;

public class dingdanS {

privateJFrame frame;

privateJTable table;

/**

* Launch the application.

*/

publicstatic void main(String[] args) {

EventQueue.invokeLater(newRunnable() {

publicvoid run() {

try{

dingdanS window = new dingdanS();

window.frame.setVisible(true);

}catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the application.

*/

publicdingdanS() {

initialize();

}

/**

* Initialize the contents of the frame.

*/

privatevoid initialize() {

frame= new JFrame();

frame.setTitle("\u98DF\u9762\u57CB\u4F0F\u00AE\u8BA2\u5355\uFF08\u60A8\u7684\u8EAB\u4EFD\u662F\uFF1A\u53A8\u5E08\uFF09");

frame.setBounds(100,100, 1280, 780);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

table= new JTable();

table.setModel(newDefaultTableModel(

newObject[][] {

},

newString[] {

"\u8BA2\u5355\u53F7","\u987E\u5BA2", "\u603B\u4EF7","\u4E0B\u5355\u65F6\u95F4"

}

){

Class[]columnTypes = new Class[] {

Integer.class,String.class, Double.class, String.class

};

publicClass getColumnClass(int columnIndex) {

returncolumnTypes[columnIndex];

}

});

table.setFont(newFont("微软雅黑", Font.PLAIN, 22));

table.setBackground(Color.ORANGE);

table.setBounds(300,150, 600, 400);

table.getColumnModel().getColumn(0).setPreferredWidth(50);

table.getColumnModel().getColumn(1).setPreferredWidth(100);

table.getColumnModel().getColumn(2).setPreferredWidth(50);

table.getColumnModel().getColumn(3).setPreferredWidth(250);

table.setVisible(true);

frame.getContentPane().add(table);

DefaultTableModelordert =  (DefaultTableModel) table.getModel();

JButtonxq = new JButton("\u67E5\u770B\u8BE6\u60C5");

xq.setBackground(Color.ORANGE);

xq.setBounds(960,150, 110, 29);

xq.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent e) {

xiangqing.main(null);

}

});

frame.getContentPane().add(xq);

JButtonwancheng = new JButton("\u8BA2\u5355\u5B8C\u6210");

wancheng.setBackground(Color.CYAN);

wancheng.setBounds(1100,150, 123, 29);

wancheng.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent e) {

JOptionPane.showMessageDialog(null,"真棒,订单完成^_^");

frame.dispose();

ddf.main(null);

}

});

frame.getContentPane().add(wancheng);

JPanelpanel = new JPanel();

panel.setBounds(0,0, 1280, 780);

frame.getContentPane().add(panel);

Iconi=new ImageIcon("D:\\PS\\material\\noodle\\dd.jpg"); /*用源图片“背景.jpg”构造一个ImageIcon对象i,需要注意如果图片的路径使用的是相对路径,则图片文件必须放在类文件所在文件夹或项目的根文件夹中,否则图片的路径必须用绝对路径。*/

JLabellb = new JLabel(i); //用指定的图片构造标签对象lb

frame.getLayeredPane().add(lb,new Integer(Integer.MIN_VALUE));

//把标签放在第二层JlayerPane上。

lb.setBounds(0,0,i.getIconWidth(),i.getIconHeight());

//设置标签的尺寸,即背景图象的大小。

panel.setOpaque(false);;

panel.add(lb);

Stringdriver = "com.mysql.jdbc.Driver";

String dbName = "NoodleRestaurant";

String passwrod = "19961225";

String userName = "root";

String url = "jdbc:mysql://localhost:3306/" + dbName;

String sql = "select * from orderall";

try {

Class.forName(driver);

Connection conn = DriverManager.getConnection(url, userName,

passwrod);

PreparedStatement ps = conn.prepareStatement(sql);

ResultSet rs = ps.executeQuery(sql);

while (rs.next()) {

Vector v = new Vector();

v.add(rs.getInt(1));

v.add(rs.getString(2));

v.add(rs.getDouble(3));

v.add(rs.getString(4));

ordert.addRow(v);

}

rs.close();

ps.close();

conn.close();

}catch (SQLException e) {

System.out.println("MySQL操作错误");

e.printStackTrace();

}catch (Exception e) {

e.printStackTrace();

}finally {

}

}

}

Home.java(初始主界面)

import java.awt.EventQueue;

import javax.swing.*;

import java.awt.GridBagLayout;

import java.awt.GridBagConstraints;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import java.awt.Insets;

import java.awt.Color;

public class Home {

privateJFrame frame;

privatedenglu dl = new denglu();

privatezhuce zc = new zhuce();

/**

* Launch the application.

*/

publicstatic void main(String[] args) {

EventQueue.invokeLater(newRunnable() {

publicvoid run() {

try{

Homewindow = new Home();

window.frame.setVisible(true);

}catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the application.

*/

publicHome() {

initialize();

}

/**

* Initialize the contents of the frame.

*/

privatevoid initialize() {

frame= new JFrame();

frame.setTitle("\u98DF\u9762\u57CB\u4F0F\u00AE\u9910\u996E\u7BA1\u7406\u7CFB\u7EDF");

frame.setBounds(100,100, 1280, 780);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JButtonwaimai = new JButton("\u5916\u5356");

waimai.setBackground(Color.ORANGE);

waimai.setBounds(666,380, 80, 60);

waimai.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent e) {

JOptionPane.showMessageDialog(null,"请先登录!");

}

});

JButtontangchi = new JButton("\u5802\u5403");

tangchi.setBackground(Color.ORANGE);

tangchi.setBounds(400,380, 80, 60);

tangchi.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent e) {

JOptionPane.showMessageDialog(null,"请先登录!");

}

});

frame.getContentPane().setLayout(null);

frame.getContentPane().add(tangchi);

JButtondingzuo = new JButton("\u8BA2\u5EA7");

dingzuo.setBackground(Color.ORANGE);

dingzuo.setBounds(533,380, 80, 60);

dingzuo.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent e) {

JOptionPane.showMessageDialog(null,"请先登录!");

}

});

frame.getContentPane().add(dingzuo);

frame.getContentPane().add(waimai);

JButtondingdan = new JButton("\u8BA2\u5355");

dingdan.setBackground(Color.ORANGE);

dingdan.setBounds(800,380, 80, 60);

dingdan.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent e) {

JOptionPane.showMessageDialog(null,"请先登录!");

}

});

frame.getContentPane().add(dingdan);

JButtondenglu = new JButton("\u767B\u5F55");

denglu.setBackground(Color.CYAN);

denglu.setBounds(510,480, 70, 50);

denglu.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent e) {

dl.main(null);

frame.dispose();

}

});

frame.getContentPane().add(denglu);

JButtonzhuce = new JButton("\u6CE8\u518C");

zhuce.setBounds(700,480, 70, 50);

frame.getContentPane().add(zhuce);

zhuce.addActionListener(newActionListener() {

publicvoid actionPerformed(ActionEvent e) {

zc.main(null);

}

});

zhuce.setBackground(Color.CYAN);

JPanelpanel = new JPanel();

panel.setBounds(0,0, 1280, 780);

frame.getContentPane().add(panel);

Iconi=new ImageIcon("D:\\PS\\material\\home20.jpg"); /*用源图片“背景.jpg”构造一个ImageIcon对象i,需要注意如果图片的路径使用的是相对路径,则图片文件必须放在类文件所在文件夹或项目的根文件夹中,否则图片的路径必须用绝对路径。*/

JLabellb = new JLabel(i); //用指定的图片构造标签对象lb

frame.getLayeredPane().add(lb,new Integer(Integer.MIN_VALUE));

//把标签放在第二层JlayerPane上。

lb.setBounds(0,0,i.getIconWidth(),i.getIconHeight());

//设置标签的尺寸,即背景图象的大小。

panel.setOpaque(false);;

panel.add(lb);

}

}

“食面埋伏”餐饮管理系统设计与实现--JAVA开发涉及UI界面、POI、连接数据库相关推荐

  1. Java开发关于UI界面_Android开发1:基本UI界面设计——布局和组件

    前言 啦啦啦~本学期要开始学习Android开发啦~ 博主在开始学习前是完完全全的小白,只有在平时完成老师要求的实验的过程中一步一步学习~从此篇博文起,博主将开始发布Android开发有关的博文,希望 ...

  2. JAVA毕业设计vue健康餐饮管理系统设计与实现计算机源码+lw文档+系统+调试部署+数据库

    JAVA毕业设计vue健康餐饮管理系统设计与实现计算机源码+lw文档+系统+调试部署+数据库 JAVA毕业设计vue健康餐饮管理系统设计与实现计算机源码+lw文档+系统+调试部署+数据库 本源码技术栈 ...

  3. java计算机毕业设计vue健康餐饮管理系统设计与实现MyBatis+系统+LW文档+源码+调试部署

    java计算机毕业设计vue健康餐饮管理系统设计与实现MyBatis+系统+LW文档+源码+调试部署 java计算机毕业设计vue健康餐饮管理系统设计与实现MyBatis+系统+LW文档+源码+调试部 ...

  4. java计算机毕业设计vue健康餐饮管理系统设计与实现源码+mysql数据库+系统+lw文档+部署

    java计算机毕业设计vue健康餐饮管理系统设计与实现源码+mysql数据库+系统+lw文档+部署 java计算机毕业设计vue健康餐饮管理系统设计与实现源码+mysql数据库+系统+lw文档+部署 ...

  5. java计算机毕业设计vue健康餐饮管理系统设计与实现(附源码、数据库)

    java计算机毕业设计vue健康餐饮管理系统设计与实现(附源码.数据库) 项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ ...

  6. JAVA毕设项目vue健康餐饮管理系统设计与实现(Vue+Mybatis+Maven+Mysql+sprnig+SpringMVC)

    JAVA毕设项目vue健康餐饮管理系统设计与实现(Vue+Mybatis+Maven+Mysql+sprnig+SpringMVC) 项目运行 环境配置: Jdk1.8 + Tomcat8.5 + M ...

  7. 基于javaweb的宠物医院预约管理系统设计和实现(java+springboot+mysql+ssm)

    基于javaweb的宠物医院预约管理系统设计和实现(java+springboot+mysql+ssm) 运行环境 Java≥8.MySQL≥5.7 开发工具 eclipse/idea/myeclip ...

  8. 基于javaweb+mysql的就业管理系统设计和实现(java+springboot+ssm)

    基于javaweb+mysql的就业管理系统设计和实现(java+springboot+ssm) 运行环境 Java≥8.MySQL≥5.7 开发工具 eclipse/idea/myeclipse/s ...

  9. springboot毕设项目汽车美容管理系统设计213wf(java+VUE+Mybatis+Maven+Mysql)

    springboot毕设项目汽车美容管理系统设计213wf(java+VUE+Mybatis+Maven+Mysql) 项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + ...

最新文章

  1. python绘图课设_python课程设计笔记(三)turtle绘图库(海龟库)
  2. lwip接收文件 stm32_接收数据
  3. 【Linux】Linux crontab 命令详解
  4. 【Oracle经典】132个oracle热门精品资料——下载目录收藏 (转载)
  5. 比较jquery中的after(),append(),appendTo()方法
  6. Apache JMeter (二)性能测试 入门实例
  7. 算法一看就懂之「 数组与链表 」
  8. 使用rkhunter检测Linux的rootkit
  9. Linux内核【链表】整理笔记(1)
  10. 威联通Nas进阶配置
  11. vue 前端打印pdf
  12. UML时序图(Sequence Diagram)
  13. 用 200 行 Python 代码掌握基本音乐理论
  14. android x86 v2ex,v2ex签到脚本改进 - 就爱阅读网
  15. MATLAB把型线图画静水力曲线,静水力表及静水力曲线图设绘通则
  16. PHP实例——留言板
  17. 如何使用熵值法分组计算核心指标权重,并为项目打分
  18. 怎样把任意exe程序注册成windows系统服务
  19. jdk7(jdk7u80是什么版本)
  20. 使用OpenSSL1.1.1中的libcrypto库进行RSA加密与解密数据

热门文章

  1. 统计学习(二)朴素贝叶斯分类
  2. 剑指offer:二叉树序列化与反序列化 - Python
  3. 天天写业务代码_如何成为技术大牛?
  4. 轻量级和企业级的区别
  5. Facebook的俄勒冈机房
  6. ajax poi jsp,Springboot+poi无法使用ajax方法
  7. 银行数字化转型导师坚鹏:商业银行大数据风控建模方法与案例
  8. jable.tv是什么
  9. java怎么让图片铺满_如何让添加的背景图片铺满整个JFrame?
  10. 量化交易平台有什么限制吗?