📄 tipwizardframe.java
字号:
unitTextField.setText(vector.get(5).toString());// 设置“单位”文本框为符合条件的菜品单位
}
}
}
});
codeTextField.setColumns(10);
final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints();
gridBagConstraints_5.gridy = 0;
gridBagConstraints_5.gridx = 5;
panel.add(codeTextField, gridBagConstraints_5);
final JLabel nameLabel = new JLabel();
nameLabel.setFont(new Font("", Font.BOLD, 12));
nameLabel.setText(" 商品名称:");
orderDishesPanel.add(nameLabel);
nameTextField = new JTextField();
nameTextField.setHorizontalAlignment(SwingConstants.CENTER);
nameTextField.setEditable(false);
nameTextField.setFocusable(false);
nameTextField.setColumns(20);
orderDishesPanel.add(nameTextField);
final JLabel unitLabel = new JLabel();
unitLabel.setFont(new Font("", Font.BOLD, 12));
unitLabel.setText(" 单位:");
orderDishesPanel.add(unitLabel);
unitTextField = new JTextField();
unitTextField.setHorizontalAlignment(SwingConstants.CENTER);
unitTextField.setEditable(false);
unitTextField.setFocusable(false);
unitTextField.setColumns(5);
orderDishesPanel.add(unitTextField);
final JLabel amountLabel = new JLabel();
amountLabel.setFont(new Font("", Font.BOLD, 12));
amountLabel.setText(" 数量:");
orderDishesPanel.add(amountLabel);
amountTextField = new JTextField();// 创建“数量”文本框
amountTextField.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {// 当文本框获得焦点时执行
amountTextField.setText(null);// 设置“数量”文本框为空
}
public void focusLost(FocusEvent e) {// 当文本框失去焦点时执行
String amount = amountTextField.getText();// 获得输入的数量
if (amount.length() == 0)// 未输入数量
amountTextField.setText("1"); // 恢复为默认数量1
}
});
amountTextField.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
int length = amountTextField.getText().length();// 获取当前数量的位数
if (length < 2) {// 位数小于两位
String num = (length == 0 ? "123456789" : "0123456789"); // 将允许输入的字符定义成字符串
if (num.indexOf(e.getKeyChar()) < 0)// 查看按键字符是否包含在允许输入的字符中
e.consume(); // 如果不包含在允许输入的字符中则销毁此次按键事件
} else {
e.consume(); // 如果不小于数量允许的最大位数则销毁此次按键事件
}
}
});
amountTextField.setText("1");// 默认数量为1
amountTextField.setHorizontalAlignment(SwingConstants.CENTER);
amountTextField.setColumns(3);
orderDishesPanel.add(amountTextField);
final JLabel emptyLabel = new JLabel();
emptyLabel.setText(null);
emptyLabel.setPreferredSize(new Dimension(10, 20));
orderDishesPanel.add(emptyLabel);
final JButton addButton = new JButton();
addButton.setFont(new Font("", Font.BOLD, 12));
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
makeOutAnInvoice();
codeTextField.requestFocus();
}
});
addButton.setText("开 单");
orderDishesPanel.add(addButton);
final JButton subButton = new JButton();
subButton.setFont(new Font("", Font.BOLD, 12));
subButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int selectedRow = rightTable.getSelectedRow();
if (selectedRow == -1) {
JOptionPane.showMessageDialog(null, "请选择要签单的台号!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
} else {
int row = leftTable.getRowCount() - 1;
String NEW = leftTable.getValueAt(row, 0).toString();
if (NEW.equals("NEW")) {
leftTableValueV.removeAllElements();
leftTableValueV.addAll(menuOfDeskV.get(selectedRow));
for (; row >= 0; row--) {
leftTableValueV.get(row).set(0, "");
}
leftTableModel.setDataVector(leftTableValueV,
leftTableColumnV);
leftTable.setRowSelectionInterval(0, 0);
}
}
}
});
subButton.setText("签 单");
orderDishesPanel.add(subButton);
final JButton delButton = new JButton();
delButton.setFont(new Font("", Font.BOLD, 12));
delButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int lSelectedRow = leftTable.getSelectedRow();// 获得“签单列表”中的选中行,即要取消的菜品
if (lSelectedRow == -1) {// 未选中任何行
JOptionPane.showMessageDialog(null, "请选择要取消的商品!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
} else {
String NEW = leftTable.getValueAt(lSelectedRow, 0)
.toString();// 获得选中菜品的新点菜标记
if (NEW.equals("")) {// 没有新点菜标记,不允许取消
JOptionPane.showMessageDialog(null, "很抱歉,该商品已经不能取消!",
"友情提示", JOptionPane.INFORMATION_MESSAGE);
return;
} else {
int rSelectedRow = rightTable.getSelectedRow();// 获得“开台列表”中的选中行,即取消菜品的台号
int i = JOptionPane.showConfirmDialog(null, "确定要取消“"
+ rightTable.getValueAt(rSelectedRow, 1)
+ "”中的商品“"
+ leftTable.getValueAt(lSelectedRow, 3) + "”?",
"友情提示", JOptionPane.YES_NO_OPTION);// 弹出提示信息确认是否取消
if (i == 0) {// 确认取消
leftTableModel.removeRow(lSelectedRow);// 从“签单列表”中取消菜品
int rowCount = leftTable.getRowCount();// 获得取消后的点菜数量
if (rowCount == 0) {// 未点任何菜品
rightTableModel.removeRow(rSelectedRow);// 取消开台
menuOfDeskV.remove(rSelectedRow);// 移除签单列表
} else {
if (lSelectedRow == rowCount) {// 取消菜品为最后一个
lSelectedRow -= 1;// 设置最后一个菜品为选中的
} else {// 取消菜品不是最后一个
Vector<Vector<Object>> menus = menuOfDeskV
.get(rSelectedRow);
for (int row = lSelectedRow; row < rowCount; row++) {// 修改点菜序号
leftTable.setValueAt(row + 1, row, 1);
menus.get(row).set(1, row + 1);
}
}
leftTable.setRowSelectionInterval(lSelectedRow);// 设置选中行
}
}
}
}
}
});
delButton.setText("取 消");
orderDishesPanel.add(delButton);
final JPanel clueOnPanel = new JPanel();
clueOnPanel.setPreferredSize(new Dimension(220, 0));
clueOnPanel.setBorder(new TitledBorder(null, "",
TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.DEFAULT_POSITION, null, null));
clueOnPanel.setLayout(new GridLayout(0, 1));
bottomPanel.add(clueOnPanel, BorderLayout.WEST);
final JLabel aClueOnLabel = new JLabel();
clueOnPanel.add(aClueOnLabel);
aClueOnLabel.setFont(new Font("", Font.BOLD, 12));
aClueOnLabel.setText(" 今天是:");
final JLabel bClueOnLabel = new JLabel();
bClueOnLabel.setFont(new Font("", Font.BOLD, 12));
clueOnPanel.add(bClueOnLabel);
bClueOnLabel.setHorizontalAlignment(SwingConstants.CENTER);
bClueOnLabel.setText(Today.getDateOfShow());
final JLabel cClueOnLabel = new JLabel();
cClueOnLabel.setFont(new Font("", Font.BOLD, 12));
clueOnPanel.add(cClueOnLabel);
cClueOnLabel.setHorizontalAlignment(SwingConstants.CENTER);
cClueOnLabel.setText(Today.getDayOfWeek());
timeLabel = new JLabel();// 创建用于显示时间的标签对象
timeLabel.setFont(new Font("宋体", Font.BOLD, 14));// 设置标签中的文字为宋体、粗体、14号
timeLabel.setForeground(new Color(255, 0, 0));// 设置标签中的文字为红色
timeLabel.setHorizontalAlignment(SwingConstants.CENTER);// 设置标签中的文字居中显示
clueOnPanel.add(timeLabel);// 将标签添加到上级容器中
new Time().start();// 开启线程
final JLabel eClueOnLabel = new JLabel();
clueOnPanel.add(eClueOnLabel);
eClueOnLabel.setFont(new Font("", Font.BOLD, 12));
eClueOnLabel.setText(" 当前操作员:");
final JLabel fClueOnLabel = new JLabel();
fClueOnLabel.setFont(new Font("", Font.BOLD, 12));
clueOnPanel.add(fClueOnLabel);
fClueOnLabel.setHorizontalAlignment(SwingConstants.CENTER);
if (user == null)
fClueOnLabel.setText("系统默认用户");
else
fClueOnLabel.setText(user.get(1).toString());
final JPanel checkOutPanel = new JPanel();
checkOutPanel.setPreferredSize(new Dimension(500, 0));
bottomPanel.add(checkOutPanel);
checkOutPanel.setBorder(new TitledBorder(null, "",
TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.DEFAULT_POSITION, null, null));
checkOutPanel.setLayout(new GridBagLayout());
final JLabel label = new JLabel();
label.setPreferredSize(new Dimension(72, 70));
URL rmbUrl = this.getClass().getResource("/img/rmb.jpg");
ImageIcon rmbIcon = new ImageIcon(rmbUrl);
label.setIcon(rmbIcon);
final GridBagConstraints gridBagConstraints_9 = new GridBagConstraints();
gridBagConstraints_9.insets = new Insets(0, 0, 0, 15);
gridBagConstraints_9.gridheight = 4;
gridBagConstraints_9.gridy = 0;
gridBagConstraints_9.gridx = 0;
checkOutPanel.add(label, gridBagConstraints_9);
final JLabel expenditureLabel = new JLabel();
expenditureLabel.setFont(new Font("", Font.BOLD, 16));
expenditureLabel.setText("消费金额:");
final GridBagConstraints gridBagConstraints_13 = new GridBagConstraints();
gridBagConstraints_13.gridx = 1;
gridBagConstraints_13.gridy = 0;
gridBagConstraints_13.insets = new Insets(0, 10, 0, 0);
checkOutPanel.add(expenditureLabel, gridBagConstraints_13);
expenditureTextField = new JTextField();
expenditureTextField.setHorizontalAlignment(SwingConstants.RIGHT);
expenditureTextField.setText("0.00");
expenditureTextField.setForeground(new Color(255, 0, 0));
expenditureTextField.setFont(new Font("", Font.BOLD, 15));
expenditureTextField.setColumns(7);
expenditureTextField.setEditable(false);
final GridBagConstraints gridBagConstraints_6 = new GridBagConstraints();
gridBagConstraints_6.gridy = 0;
gridBagConstraints_6.gridx = 2;
checkOutPanel.add(expenditureTextField, gridBagConstraints_6);
final JLabel expenditureUnitLabel = new JLabel();
expenditureUnitLabel.setForeground(new Color(255, 0, 0));
expenditureUnitLabel.setFont(new Font("", Font.BOLD, 15));
expenditureUnitLabel.setText(" 元");
final GridBagConstraints gridBagConstraints_14 = new GridBagConstraints();
gridBagConstraints_14.gridy = 0;
gridBagConstraints_14.gridx = 3;
checkOutPanel.add(expenditureUnitLabel, gridBagConstraints_14);
final JLabel realWagesLabel = new JLabel();
realWagesLabel.setFont(new Font("", Font.BOLD, 16));
realWagesLabel.setText("实收金额:");
final GridBagConstraints gridBagConstraints_7 = new GridBagConstraints();
gridBagConstraints_7.insets = new Insets(10, 10, 0, 0);
gridBagConstraints_7.gridy = 1;
gridBagConstraints_7.gridx = 1;
checkOutPanel.add(realWagesLabel, gridBagConstraints_7);
realWagesTextField = new JTextField();
realWagesTextField.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
// TODO 自动生成方法存根
}
public void keyReleased(KeyEvent e) {
// TODO 自动生成方法存根
}
public void keyTyped(KeyEvent e) {
int length = realWagesTextField.getText().length();// 获取当前数量的位数
if (length < 8) {// 位数小于两位
String num = (length == 4 ? "123456789" : "0123456789"); // 将允许输入的字符定义成字符串
if (num.indexOf(e.getKeyChar()) < 0)// 查看按键字符是否包含在允许输入的字符中
e.consume(); // 如果不包含在允许输入的字符中则销毁此次按键事件
} else {
e.consume(); // 如果不小于数量允许的最大位数则销毁此次按键事件
}
}
});
realWagesTextField.setHorizontalAlignment(SwingConstants.RIGHT);
realWagesTextField.setText("0.00");
realWagesTextField.setForeground(new Color(0, 128, 0));
realWagesTextField.setFont(new Font("", Font.BOLD, 15));
realWagesTextField.setColumns(7);
final GridBagConstraints gridBagConstraints_8 = new GridBagConstraints();
gridBagConstraints_8.insets = new Insets(10, 0, 0, 0);
gridBagConstraints_8.gridy = 1;
gridBagConstraints_8.gridx = 2;
checkOutPanel.add(realWagesTextField, gridBagConstraints_8);
final JLabel realWagesUnitLabel = new JLabel();
realWagesUnitLabel.setForeground(new Color(0, 128, 0));
realWagesUnitLabel.setFont(new Font("", Font.BOLD, 15));
realWagesUnitLabel.setText(" 元");
final GridBagConstraints gridBagConstraints_15 = new GridBagConstraints();
gridBagConstraints_15.insets = new Insets(10, 0, 0, 0);
gridBagConstraints_15.gridy = 1;
gridBagConstraints_15.gridx = 3;
checkOutPanel.add(realWagesUnitLabel, gridBagConstraints_15);
final JButton checkOutButton = new JButton();
checkOutButton.setFont(new Font("", Font.BOLD, 12));
checkOutButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int selectedRow = rightTable.getSelectedRow();
if (selectedRow == -1) {
JOptionPane.showMessageDialog(null, "请选择要结账的台号!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
} else {
int rowCount = leftTable.getRowCount();// 获得结账餐台的点菜数量
String NEW = leftTable.getValueAt(rowCount - 1, 0)
.toString();// 获得最后点菜的标记
if (NEW.equals("NEW")) {// 如果最后点菜被标记为“NEW”,则弹出提示
JOptionPane.showMessageDialog(null, "请先确定未签单商品的处理方式!",
"友情提示", JOptionPane.INFORMATION_MESSAGE);
} else {
float expenditure = Float.valueOf(expenditureTextField
.getText());// 获得消费金额
float realWages = Float.valueOf(realWagesTextField
.getText());// 获得实收金额
if (realWages < expenditure) {// 如果实收金额小于消费金额,则弹出提示
if (realWages == 0.0f)
JOptionPane
.showMessageDialog(null, "请输入实收金额!",
"友情提示",
JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null,
"实收金额不能小于消费金额!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
realWagesTextField.requestFocus();// 并令“实收金额”文本框获得焦点
} else {
changeTextField.setText(realWages - expenditure
+ "0");// 计算并设置“找零金额”
String[] values = {
getNum(),
rightTable.getValueAt(selectedRow, 1)
.toString(),
Today.getDate()
+ " "
+ rightTable.getValueAt(
selectedRow, 2),
expenditureTextField.getText(),
user.get(0).toString() };// 组织消费单信息
dao.iOrderForm(values);// 持久化到数据库
values[0] = dao.sOrderFormOfMaxId();// 获得消费单编号
for (int i = 0; i < rowCount; i++) {// 通过循环获得各个消费项目的信息
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -