📄 addprice.java
字号:
package netbar;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AddPrice extends JFrame {
AddPriceDate addpricedate=new AddPriceDate();
public AddPrice() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(36, 31, 62, 32));
jLabel2.setFont(new java.awt.Font("Dialog", Font.BOLD, 15));
jLabel2.setText("金额:");
txtCardId.setFont(new java.awt.Font("Dialog", Font.BOLD, 15));
txtCardId.setBounds(new Rectangle(106, 31, 120, 32));
txtMoney.setFont(new java.awt.Font("Dialog", Font.BOLD, 15));
txtMoney.setEditable(true);
txtMoney.setBounds(new Rectangle(110, 83, 120, 32));
btnOK.setBounds(new Rectangle(43, 130, 72, 37));
btnOK.setFont(new java.awt.Font("Dialog", Font.BOLD, 15));
btnOK.setText("确定");
btnOK.addActionListener(new AddPrice_btnOK_actionAdapter(this));
btnReset.setBounds(new Rectangle(153, 130, 72, 37));
btnReset.setFont(new java.awt.Font("Dialog", Font.BOLD, 15));
btnReset.setText("重置");
btnReset.addActionListener(new AddPrice_btnReset_actionAdapter(this));
jLabel1.setFont(new java.awt.Font("Dialog", Font.BOLD, 15));
jLabel1.setText("卡号:");
this.getContentPane().add(txtMoney);
this.getContentPane().add(jPanel1);
jPanel1.add(jLabel1);
this.getContentPane().add(jPanel2);
jPanel2.add(jLabel2);
this.getContentPane().add(txtCardId);
this.getContentPane().add(btnOK);
this.getContentPane().add(btnReset);
jPanel2.setBorder(BorderFactory.createEtchedBorder());
jPanel2.setBounds(new Rectangle(36, 83, 62, 32));
txtMoney.addItem("10");
txtMoney.addItem("20");
txtMoney.addItem("30");
txtMoney.addItem("40");
txtMoney.addItem("50");
txtMoney.addItem("100");
this.setResizable(false);
}
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField txtCardId = new JTextField();
JComboBox txtMoney = new JComboBox();
JButton btnOK = new JButton();
JButton btnReset = new JButton();
public void btnOK_actionPerformed(ActionEvent e) {
String cardId=txtCardId.getText();
String money=txtMoney.getSelectedItem().toString();
if(addpricedate.ishave(cardId)==true){
addpricedate.addprice(cardId,money);
btnOK.setEnabled(false);
JOptionPane.showMessageDialog(this,"添加金额为:"+money+"元");
}
else
JOptionPane.showMessageDialog(this,"没有这个卡号!请重新输入!");
}
public void btnReset_actionPerformed(ActionEvent e) {
txtCardId.setText("");
txtMoney.setSelectedIndex(0);
btnOK.setEnabled(true);
}
}
class AddPrice_btnReset_actionAdapter implements ActionListener {
private AddPrice adaptee;
AddPrice_btnReset_actionAdapter(AddPrice adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnReset_actionPerformed(e);
}
}
class AddPrice_btnOK_actionAdapter implements ActionListener {
private AddPrice adaptee;
AddPrice_btnOK_actionAdapter(AddPrice adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnOK_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -