?? borrowermanage.java
字號:
//密碼添加的選擇
int askPwd = JOptionPane.showConfirmDialog(null, "輸入新密碼(Y)/參照原始密碼新建記錄(N)","添加密碼?", JOptionPane.YES_NO_OPTION);
if(askPwd == JOptionPane.YES_OPTION) {
//輸入新密碼
//問題:非保密.....
String newPwd = JOptionPane.showInputDialog("新密碼");
value.setPwd(newPwd);
}else {
//參照原始密碼新建記錄
//不用修改原來value數據
}
if (BorrowerOper.add(value)) {
JOptionPane.showMessageDialog(null, "添加成功");
search();
} else {
JOptionPane.showMessageDialog(null, "添加失敗!");
}
}
}
});
}
return jButton_add;
}
private Borrower b;
private Borrower getIputText() {
String card = getJTextField_card().getText().trim();
String id = getJTextField_id().getText().trim();
String borrower = getJTextField_borrower().getText().trim();
String login = getJTextField_login().getText().trim();
String email = getJTextField_email().getText().trim();
String phone = getJTextField_phone().getText().trim();
String pwd = getJPasswordField().getText().trim();
String isStudent = "1";
if (jRadioButton_tea.isSelected()) {
isStudent = "0";
}
b = new Borrower(id, borrower,login, pwd, email, phone, isStudent);
return b;
}
/**
* This method initializes jButton_del
*
* @return javax.swing.JButton
*/
private JButton getJButton_del() {
if (jButton_del == null) {
jButton_del = new JButton();
//jButton_del.setText("刪除");
jButton_add.setToolTipText("刪除選擇的借閱者記錄");
jButton_del.setIcon(new ImageIcon("E:/img/standard_127_20.png"));
jButton_del.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (checkEmpty()) {
BorrowerOper db = new BorrowerOper();
String[] names = getJTableValue();
int ch = JOptionPane.showConfirmDialog(null,
"你真的要刪除該記錄?(借閱卡信息將一并刪除)", "刪除數據",
JOptionPane.YES_NO_OPTION);
if (ch == JOptionPane.YES_OPTION) {
if (db.delete(names[1])) {
JOptionPane.showMessageDialog(null, "數據刪除成功");
// row = getJTable().getSelectedRow();
// TableModel td = getJTable().getModel();
// DefaultTableModel model = (DefaultTableModel)
// td;
// model.removeRow(row);
search();
} else {
JOptionPane.showMessageDialog(null, "數據刪除失敗");
}
}
}
}
});
}
return jButton_del;
}
/**
* This method initializes jTextField_borrower
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_borrower() {
if (jTextField_borrower == null) {
jTextField_borrower = new JTextField();
}
return jTextField_borrower;
}
/**
* This method initializes jTextField_email
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_email() {
if (jTextField_email == null) {
jTextField_email = new JTextField();
}
return jTextField_email;
}
/**
* This method initializes jTextField_phone
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_phone() {
if (jTextField_phone == null) {
jTextField_phone = new JTextField();
}
return jTextField_phone;
}
/**
* This method initializes jToolBar_space
*
* @return javax.swing.JToolBar
*/
private JToolBar getJToolBar_space() {
if (jToolBar_space == null) {
jToolBar_space = new JToolBar();
jToolBar_space.setFloatable(false);
jToolBar_space.add(getJTextArea_space());
}
return jToolBar_space;
}
/**
* This method initializes jTextArea_space
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea_space() {
if (jTextArea_space == null) {
jTextArea_space = new JTextArea();
jTextArea_space.setRows(9);
jTextArea_space.setEditable(false);
String help = "";
jTextArea_space.setText(help);
}
return jTextArea_space;
}
/**
* This method initializes jRadioButton_stu
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getJRadioButton_stu() {
if (jRadioButton_stu == null) {
jRadioButton_stu = new JRadioButton();
jRadioButton_stu.setText("學生");
jRadioButton_stu.setSelected(true);
}
return jRadioButton_stu;
}
/**
* This method initializes jRadioButton_tea
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getJRadioButton_tea() {
if (jRadioButton_tea == null) {
jRadioButton_tea = new JRadioButton();
jRadioButton_tea.setText("老師");
}
return jRadioButton_tea;
}
/**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
}
return jPasswordField;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.add(getJScrollPane(), null);
}
return jPanel;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJTable());
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
Object[][] data = {};
String[] column = { "借閱人編號", "借閱者編號", "姓名","登錄ID", "是否學生", "Email", "電話",
"已借圖書數" };
DefaultTableModel model = new DefaultTableModel(data, column);
jTable = new JTable(model);
jTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent e) {
String[] value = getJTableValue();
jTextField_card.setText(value[0]);
jTextField_id.setText(value[1]);
jTextField_borrower.setText(value[2]);
jPasswordField.setText(value[3]);
jTextField_login.setText(value[7]);
//把原始密碼 安全地保存到 私有變量中
originalPwd = value[3];
jTextField_email.setText(value[4]);
jTextField_phone.setText(value[5]);
if (value[6].toString().equals("1")) {
jRadioButton_stu.setSelected(true);
} else if (value[6].toString().equals("0")) {
jRadioButton_tea.setSelected(true);
} else {
jRadioButton_stu.setSelected(false);
jRadioButton_tea.setSelected(false);
}
}
});
}
return jTable;
}
int row = 0;
private JButton jButton_updateCard = null;
private JToolBar jToolBar_pwd1 = null;
private JLabel jLabel_pwd1 = null;
private JPasswordField jPasswordField1 = null;
private JLabel jLabel_stutea = null;
private JLabel jLabel_stutea1 = null;
private JButton jButton_updatePwd = null;
public String[] getJTableValue() {
row = getJTable().getSelectedRow();
//System.out.println("row " + row);
int columns = getJTable().getColumnCount();
String[] data = new String[8];
data[1] = getJTable().getValueAt(row, 1).toString();
Iterator iter = BorrowerOper.query(data[1]).iterator();
while (iter.hasNext()) {
Borr value = (Borr) iter.next();
data[0] = value.getCard_id();
// card_id,borrower_id,borrower,pwd,email,phone,isStudent,borrow_num
data[2] = value.getBorrower();
data[3] = value.getPwd();
data[4] = value.getEmail();
data[5] = value.getPhone();
data[6] = value.getIsStudent();
data[7] = value.getLogin();
}
return data;
}
/**
* This method initializes jButton_updateCard
*
* @return javax.swing.JButton
*/
private JButton getJButton_updateCard() {
if (jButton_updateCard == null) {
jButton_updateCard = new JButton();
jButton_updateCard.setIcon(new ImageIcon(
"E:/img/standard_141_16.png"));
jButton_updateCard.setToolTipText("重新辦理借閱卡");
jButton_updateCard
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (checkEmpty()) {
String id = getJTextField_id().getText().trim();
int ch = JOptionPane.showConfirmDialog(null,"重新申請借閱卡,原來的借閱卡將作廢,是否辦理?", "修改數據",JOptionPane.YES_NO_OPTION);
if (ch == JOptionPane.YES_OPTION) {
String updatedCard = BorrowerOper
.updateCard(id);
if (!updatedCard.equals("ERROR")) {
JOptionPane.showMessageDialog(null,
"新借閱卡辦理成功,請記住你的卡號是:" +updatedCard);
getJTextField_card().setText(
updatedCard);
search();
} else {
JOptionPane.showMessageDialog(null,
"新借閱卡辦理失敗");
}
}
}
}
});
}
return jButton_updateCard;
}
/**
* This method initializes jToolBar1
*
* @return javax.swing.JToolBar
*/
private JToolBar getJToolBar_pwd1() {
if (jToolBar_pwd1 == null) {
jLabel_pwd1 = new JLabel();
jLabel_pwd1.setText("密碼確認");
jToolBar_pwd1 = new JToolBar();
jToolBar_pwd1.setFloatable(false);
jToolBar_pwd1.setVisible(false);
jToolBar_pwd1.add(jLabel_pwd1);
jToolBar_pwd1.add(getJPasswordField1());
}
return jToolBar_pwd1;
}
private String originalPwd = null;
private JToolBar jToolBar_login = null;
private JLabel jLabel_login = null;
private JTextField jTextField_login = null;
/**
* This method initializes jPasswordField1
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField1() {
if (jPasswordField1 == null) {
jPasswordField1 = new JPasswordField();
jPasswordField1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent e) {
//輸入密碼,回車確認
if(e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
//進行密碼確認時,原密碼...值 從何而得?,故在選擇記錄時,要保存原密碼
if(jPasswordField1.getText().equals(originalPwd)) {
//匹配
//輸入新密碼
//問題:非保密.....
//不可取消??
String newPwd = JOptionPane.showInputDialog("原始密碼正確,請輸入新密碼:");
String id = getJTextField_id().getText();
if (BorrowerOper.updatePwd(id,newPwd)) {
JOptionPane.showMessageDialog(null, "密碼修改成功");
search();
} else {
JOptionPane.showMessageDialog(null, "密碼修改失敗!");
}
}else{
//不匹配
}
}
}
});
}
return jPasswordField1;
}
/**
* This method initializes jButton_updatePwd
*
* @return javax.swing.JButton
*/
private JButton getJButton_updatePwd() {
if (jButton_updatePwd == null) {
jButton_updatePwd = new JButton();
jButton_updatePwd.setIcon(new ImageIcon("E:/img/standard_050_16.png"));
jButton_updatePwd.setToolTipText("修改密碼");
jButton_updatePwd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if(jToolBar_pwd1.isVisible()) {
jButton_updatePwd.setIcon(new ImageIcon("E:/img/standard_050_16.png"));
jToolBar_pwd1.setVisible(false);
jTextArea_space.setRows(9);
}else{
jButton_updatePwd.setIcon(new ImageIcon("E:/img/standard_049_16.png"));
jToolBar_pwd1.setVisible(true);
jTextArea_space.setRows(7);
//密碼確認框獲得焦點
//###
}
}
});
}
return jButton_updatePwd;
}
/**
* This method initializes jToolBar1
*
* @return javax.swing.JToolBar
*/
private JToolBar getJToolBar_login() {
if (jToolBar_login == null) {
jLabel_login = new JLabel();
jLabel_login.setText("登錄ID");
jToolBar_login = new JToolBar();
jToolBar_login.setFloatable(false);
jToolBar_login.add(jLabel_login);
jToolBar_login.add(getJTextField_login());
}
return jToolBar_login;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_login() {
if (jTextField_login == null) {
jTextField_login = new JTextField();
}
return jTextField_login;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -