📄 pointspanel.java~2~
字号:
package memberpane;
import javax.swing.*;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
public class PointsPanel extends JPanel {
public PointsPanel(JTable table) {
this.table = table;
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(null);
abovePanel.setBorder(BorderFactory.createEtchedBorder());
abovePanel.setBounds(new Rectangle(9, 8, 380, 129));
abovePanel.setLayout(null);
downPanel.setBorder(BorderFactory.createEtchedBorder());
downPanel.setBounds(new Rectangle(9, 147, 380, 76));
downPanel.setLayout(null);
jLabel1.setText("会员编号");
jLabel1.setBounds(new Rectangle(20, 21, 62, 24));
jLabel2.setText("会员姓名");
jLabel2.setBounds(new Rectangle(209, 21, 62, 24));
jLabel3.setText("会员类别");
jLabel3.setBounds(new Rectangle(20, 54, 62, 24));
jLabel4.setText("登记日期");
jLabel4.setBounds(new Rectangle(209, 54, 62, 24));
jLabel5.setText("储值余额");
jLabel5.setBounds(new Rectangle(20, 86, 62, 24));
jLabel6.setText("当前积分");
jLabel6.setBounds(new Rectangle(209, 86, 62, 24));
pointsField.setBounds(new Rectangle(245, 25, 80, 24));
vipidField.setEditable(false);
vipidField.setBounds(new Rectangle(81, 21, 80, 24));
nameField.setEditable(false);
nameField.setBounds(new Rectangle(270, 21, 80, 24));
vipKindField.setEditable(false);
vipKindField.setBounds(new Rectangle(81, 54, 80, 24));
enterDateField.setEditable(false);
enterDateField.setBounds(new Rectangle(270, 54, 80, 24));
curMoneyField.setEditable(false);
curMoneyField.setBounds(new Rectangle(81, 86, 80, 24));
curPointsField.setEditable(false);
curPointsField.setBounds(new Rectangle(270, 86, 80, 24));
jLabel7.setText("操作分值");
jLabel7.setBounds(new Rectangle(184, 25, 62, 24));
increaseRadioButton.setText("增加积分操作");
increaseRadioButton.setBounds(new Rectangle(55, 12, 108, 24));
reduceRadioButton.setText("减少积分操作");
reduceRadioButton.setBounds(new Rectangle(55, 40, 108, 24));
okButton.setBounds(new Rectangle(81, 238, 87, 31));
okButton.setText("确定");
cancelButton.setBounds(new Rectangle(205, 237, 87, 31));
cancelButton.setText("取消");
cancelButton.addActionListener(new
PointsPanel_cancelButton_actionAdapter(this));
this.add(abovePanel);
abovePanel.add(vipKindField);
abovePanel.add(curMoneyField);
abovePanel.add(curPointsField);
abovePanel.add(jLabel6);
abovePanel.add(jLabel4);
abovePanel.add(jLabel5);
abovePanel.add(jLabel1);
abovePanel.add(jLabel3);
abovePanel.add(jLabel2);
abovePanel.add(vipidField);
abovePanel.add(enterDateField);
abovePanel.add(nameField);
this.add(downPanel);
downPanel.add(reduceRadioButton);
downPanel.add(increaseRadioButton);
downPanel.add(jLabel7);
downPanel.add(pointsField);
this.add(okButton);
this.add(cancelButton);
buttonGroup.add(increaseRadioButton);
buttonGroup.add(reduceRadioButton);
int selectedRow = table.getSelectedRow();
if(selectedRow != -1){//当确实有一行被选中的时候,可以对该行进行修改
Connection conn = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
}
String dburl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=db.mdb";
try {
conn = DriverManager.getConnection(dburl);
} catch (SQLException ex1) {
}
Statement stmtQuery = null;
ResultSet rs = null;
try {
stmtQuery = conn.createStatement();
ID = (String)table.getValueAt(selectedRow,0);//ID赋值为当前行的第0位上的值,即会员的ID
rs = stmtQuery.executeQuery("select * from VIP where ID =" + ID + "");
rs.next();
//获得所有字段值
String Mname = rs.getString("Name");
String Mvipid = rs.getString("VIPID");
String Mvipkind = rs.getString("VIPKind");
String Msex = rs.getString("Sex");
String Mgrade = rs.getString("Grade");
String Mphone = rs.getString("Phone");
String Mmovephone = rs.getString("MovePhone");
String Mbirthday = rs.getString("Birthday");
String Mvalid = rs.getString("Valid");
String Mpass = rs.getString("Pass");
String Menterdate = rs.getString("EnterDate");
String Menddate = rs.getString("EndDate");
String Mbeginmoney = rs.getString("BeginMoney");
String Mcurmoney = rs.getString("CurMoney");
String Msumcost = rs.getString("SumCost");
String Mbeginpoints = rs.getString("BeginPoints");
String Mcurpoints = rs.getString("CurPoints");
String Msumpoints = rs.getString("SumPoints");
String Mminzu = rs.getString("MinZu");
String Munit = rs.getString("Unit");
String Maddress = rs.getString("Address");
String Mpostcode = rs.getString("postcode");
String Moccu = rs.getString("Occu");
String Mcertid = rs.getString("CertID");
String Memail = rs.getString("Email");
String Mremark = rs.getString("Mem");
//设置面板上所有会员信息值
nameField.setText(Mname);
sexComboBox.setSelectedItem(Msex);
nationField.setText(Mminzu);
memKindComboBox.setSelectedItem(Mvipkind);
//暂时去掉ActionListener,避免在初始化的时候由于日期改变事件触发生成DateChooser询问对话框
//日期修改结束后重新添加ActionListener
birthdayComboBox.removeActionListener(birthdayComboBox.getActionListeners()[0]);
birthdayComboBox.removeItemAt(0);
birthdayComboBox.addItem(Mbirthday.substring(0,Mbirthday.indexOf(" ")));
birthdayComboBox.addActionListener(new
UpdatePanel_birthdayComboBox_actionAdapter(this));
//暂时去掉ActionListener,避免在初始化的时候由于日期改变事件触发生成DateChooser询问对话框
//日期修改结束后重新添加ActionListener
enterDateComboBox.removeActionListener(enterDateComboBox.getActionListeners()[0]);
enterDateComboBox.removeItemAt(0);
enterDateComboBox.addItem(Menterdate.substring(0,Menterdate.indexOf(" ")));
enterDateComboBox.addActionListener(new
UpdatePanel_enterDateComboBox_actionAdapter(this));
//暂时去掉ActionListener,避免在初始化的时候由于日期改变事件触发生成DateChooser询问对话框
//日期修改结束后重新添加ActionListener
endDateComboBox.removeActionListener(endDateComboBox.getActionListeners()[0]);
endDateComboBox.removeItemAt(0);
endDateComboBox.addItem(Menddate.substring(0,Menddate.indexOf(" ")));
endDateComboBox.addActionListener(new
UpdatePanel_endDateComboBox_actionAdapter(this));
unitField.setText(Munit);
addressField.setText(Maddress);
postcodeField.setText(Mpostcode);
phoneField.setText(Mphone);
careerField.setText(Moccu);
mobiliField.setText(Mmovephone);
certcodeField.setText(Mcertid);
emailField.setText(Memail);
memNumField.setText(Mvipid);
if(Mvalid.equals("1")) validCheckBox.setSelected(true); else validCheckBox.setSelected(false);
passwordField.setText(Mpass);
gradeComboBox.setSelectedItem(Mgrade);
beginMoneyField.setText(Mbeginmoney);
curMoneyField.setText(Mcurmoney);
consumField.setText(Msumcost);
beginPointsField.setText(Mbeginpoints);
curPointsField.setText(Mcurpoints);
sumPointsField.setText(Msumpoints);
remarkArea.setText(Mremark);
conn.close();
}catch (SQLException ex) {
System.out.println(ex.getStackTrace());
}} else {
}
}
JPanel abovePanel = new JPanel();
JPanel downPanel = new JPanel();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JTextField pointsField = new JTextField();
JTextField vipidField = new JTextField();
JTextField nameField = new JTextField();
JTextField vipKindField = new JTextField();
JTextField enterDateField = new JTextField();
JTextField curMoneyField = new JTextField();
JTextField curPointsField = new JTextField();
JLabel jLabel7 = new JLabel();
JRadioButton increaseRadioButton = new JRadioButton();
JRadioButton reduceRadioButton = new JRadioButton();
JButton okButton = new JButton();
JButton cancelButton = new JButton();
ButtonGroup buttonGroup = new ButtonGroup();
JTable table = null;
public void cancelButton_actionPerformed(ActionEvent e) {
//通过当前panel得到其所依附的JFrame,需要四次getParent()
//从底层向上分别为:PointsPanel->JPanel->JLayeredPane->JRootPane->JFrame
JFrame frame = (JFrame)this.getParent().getParent().getParent().getParent();
frame.setVisible(false);
frame.dispose();
}
}
class PointsPanel_cancelButton_actionAdapter
implements ActionListener {
private PointsPanel adaptee;
PointsPanel_cancelButton_actionAdapter(PointsPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.cancelButton_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -