?? 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 + -