package com.itany.menuorder.ui;
import java.awt.Font;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import com.itany.manuorder.beanConstans.BeanContants;
import com.itany.menuorder.factory.Factory;
import com.itany.menuorder.service.impl.DeskServiceImpl;
public class MenuFrame {
static DeskServiceImpl dsi = (DeskServiceImpl) Factory
.getBean(BeanContants.BEAN_DESKSERVICE_IMPL);
private JFrame menuFrame;
private JLabel imageLab;
private JButton checkBut;
// 初始化
public void init() {
//System.out.println("init");
menuFrame = new JFrame("WelcomePage");
imageLab = new JLabel();
checkBut = new JButton("...MenuOrderSystem...");
}
// 设置大侠
public void setStyle() {
//System.out.println("style");
menuFrame.setSize(600, 600);
menuFrame.setLocationRelativeTo(null);
menuFrame.setLayout(null);
checkBut.setBounds(90, 400, 400, 50);
checkBut.setFont(new Font("宋体", Font.BOLD, 25));
// checkBut.setBounds(null);
checkBut.setContentAreaFilled(false);
checkBut.setBorder(null);
menuFrame.add(checkBut);
imageLab.setIcon(new ImageIcon(MenuFrame.class.getClassLoader()
.getResource("image/bgima.jpg")));
imageLab.setSize(600, 600);
menuFrame.add(imageLab);
}
// 监视器
public void registHandler() {
//System.out.println("registHandler");
checkBut.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String str = JOptionPane.showInputDialog(null, "请输入桌号",
JOptionPane.YES_NO_OPTION);
int no;
// 抓取座号输入错误
try {
no = Integer.parseInt(str);
// System.out.println(no);
if (1 > no || 100 < no) {
JOptionPane.showConfirmDialog(null, "请输入0-100", "提示",
JOptionPane.ERROR_MESSAGE);
} else {
if (dsi.findDeskByNo(no) == true) {
JOptionPane.showMessageDialog(null, "本桌已有人就餐",
"提示", JOptionPane.CANCEL_OPTION);
} else {
dsi.orderDesk(no);
MenuOrderFrame mof = new MenuOrderFrame();
mof.show();
}
}
} catch (NumberFormatException e2) {
JOptionPane.showConfirmDialog(null, "请输入数字", "提示",
JOptionPane.CLOSED_OPTION,
JOptionPane.ERROR_MESSAGE);
}
}
});
checkBut.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
//TODO Auto-generated method stub
}
//按下
public void mousePressed(MouseEvent e) {
}
@Override
// 离开
public void mouseExited(MouseEvent e) {
checkBut.setText("...MenuOrderSystem...");
checkBut.setFont(new Font("宋体", Font.BOLD, 25));
}
// @Override
// // 进入
public void mouseEntered(MouseEvent e) {
checkBut.setText("开始点菜");
checkBut.setFont(new Font("宋体", Font.BOLD, 30));
}
@Override
// 点击
public void mouseClicked(MouseEvent e) {
}
});
}
public void show() {
//System.out.println("show");
init();
setStyle();
registHandler();
menuFrame.setVisible(true);
menuFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
评论0
最新资源