?? registerwindow.java
字號:
package org.itstar.netbar.swing;
import org.itstar.netbar.bean.CustomerBean;
import org.itstar.netbar.domain.ICustomerDomain;
import org.itstar.netbar.domain.impl.CustomerDomainImpl;
import org.itstar.netbar.utils.CurrentTime;
import javax.swing.SwingUtilities;
import java.awt.Point;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class RegisterWindow //extends JFrame
{
private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="10,10"
private JPanel jPanel = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JLabel jLabel3 = null;
private JLabel jLabel4 = null;
private JButton btnReg = null;
private JButton btnReset = null;
private JButton btnCancel = null;
private JTextField txtCardNum = null;
private JPasswordField txtCardPswd = null;
private JPasswordField txtPswdAgain = null;
private JLabel jLabel6 = null;
private JTextField txtBalance = null;
private JTextField txtName = null;
private JTextField txtPersonID = null;
private JLabel lblInfo = null;
/**
* This method initializes jFrame
*
* @return javax.swing.JFrame
*/
public JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame();
jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
jFrame.setAlwaysOnTop(true);
jFrame.setSize(343, 366);
jFrame.setLocation(new Point(260, 200));
jFrame.setContentPane(getJPanel());
jFrame.setTitle("會員注冊");
}
return jFrame;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
lblInfo = new JLabel();
lblInfo.setBounds(new Rectangle(86, 88, 154, 16));
lblInfo.setEnabled(true);
lblInfo.setFont(new Font("Dialog", Font.BOLD, 12));
lblInfo.setForeground(new Color(255, 102, 102));
lblInfo.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
lblInfo.setText("");
jLabel6 = new JLabel();
jLabel6.setText("再次輸入密碼");
jLabel6.setSize(new Dimension(87, 25));
jLabel6.setFont(new Font("Dialog", Font.BOLD, 13));
jLabel6.setLocation(new Point(63, 106));
jLabel4 = new JLabel();
jLabel4.setText("身份證號");
jLabel4.setSize(new Dimension(80, 25));
jLabel4.setFont(new Font("Dialog", Font.BOLD, 13));
jLabel4.setLocation(new Point(63, 238));
jLabel3 = new JLabel();
jLabel3.setText("會員名稱");
jLabel3.setSize(new Dimension(80, 25));
jLabel3.setFont(new Font("Dialog", Font.BOLD, 13));
jLabel3.setLocation(new Point(62, 196));
jLabel2 = new JLabel();
jLabel2.setText("卡號金額");
jLabel2.setSize(new Dimension(80, 25));
jLabel2.setFont(new Font("Dialog", Font.BOLD, 13));
jLabel2.setLocation(new Point(62, 149));
jLabel1 = new JLabel();
jLabel1.setText("卡號密碼");
jLabel1.setSize(new Dimension(80, 25));
jLabel1.setFont(new Font("Dialog", Font.BOLD, 13));
jLabel1.setLocation(new Point(62, 62));
jLabel = new JLabel();
jLabel.setText("會員卡號");
jLabel.setSize(new Dimension(80, 25));
jLabel.setFont(new Font("Dialog", Font.BOLD, 13));
jLabel.setLocation(new Point(62, 22));
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.add(jLabel, null);
jPanel.add(jLabel1, null);
jPanel.add(jLabel2, null);
jPanel.add(jLabel3, null);
jPanel.add(jLabel4, null);
jPanel.add(getBtnReg(), null);
jPanel.add(getBtnReset(), null);
jPanel.add(getBtnCancel(), null);
jPanel.add(getTxtCardNum(), null);
jPanel.add(getTxtCardPswd(), null);
jPanel.add(getTxtPswdAgain(), null);
jPanel.add(jLabel6, null);
jPanel.add(getTxtBalance(), null);
jPanel.add(getTxtName(), null);
jPanel.add(getTxtPersonID(), null);
jPanel.add(lblInfo, null);
}
return jPanel;
}
/**
* This method initializes btnReg
*
* @return javax.swing.JButton
*/
private JButton getBtnReg() {
if (btnReg == null) {
btnReg = new JButton();
btnReg.setText("注 冊");
btnReg.setSize(new Dimension(70, 30));
btnReg.setFont(new Font("Dialog", Font.BOLD, 13));
btnReg.setLocation(new Point(46, 291));
btnReg.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
boolean isSamePswd=(txtCardPswd.getText().equals(txtPswdAgain.getText()));
if(txtCardNum.getText().equals("")||txtName.getText().equals("")||txtCardPswd.getText().equals("")
||txtBalance.getText().equals("")||txtPersonID.getText().equals(""))
{
JOptionPane.showMessageDialog(jFrame, "請先確保各字段不為空!!");
}
else if(!isSamePswd&&!txtCardPswd.getText().equals(""))
{
lblInfo.setText("[兩次密碼不相同!]");
}
else if(!txtCardNum.getText().equals("")&&!txtName.getText().equals("")
&&!txtBalance.getText().equals("")&&!txtPersonID.getText().equals(""))
{//各字段不允許為空
ICustomerDomain cDomain=new CustomerDomainImpl();
CustomerBean cBean=new CustomerBean();
cBean.setCusCardNum(txtCardNum.getText());
cBean.setCusCardPassword(txtCardPswd.getText());
cBean.setCusBalance(txtBalance.getText());
cBean.setCusName(txtName.getText());
cBean.setCusPersonID(txtPersonID.getText());
cBean.setCusRegDate(CurrentTime.getCurTime());
cBean.setCusLastLoginTime("");
Map map=new HashMap();
map.put("cusCardNum", txtCardNum.getText());
List list=new ArrayList();
list=cDomain.query(map);
if(list.size()>0)
{//已經存在此會員
JOptionPane.showMessageDialog(jFrame, "已經存在此會員卡號!");
}
else
{//添加成功
cDomain.insert(cBean);
JOptionPane.showMessageDialog(jFrame, "會員帳號添加成功!");
}
}
}
});
}
return btnReg;
}
/**
* This method initializes btnReset
*
* @return javax.swing.JButton
*/
private JButton getBtnReset() {
if (btnReset == null) {
btnReset = new JButton();
btnReset.setText("重 置");
btnReset.setSize(new Dimension(70, 30));
btnReset.setFont(new Font("Dialog", Font.BOLD, 13));
btnReset.setLocation(new Point(135, 291));
btnReset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
txtCardNum.setText("");
txtCardPswd.setText("");
lblInfo.setText("");
txtPswdAgain.setText("");
txtBalance.setText("");
txtName.setText("");
txtPersonID.setText("");
txtCardNum.grabFocus(); //搶奪焦點
}
});
}
return btnReset;
}
/**
* This method initializes btnCancel
*
* @return javax.swing.JButton
*/
private JButton getBtnCancel() {
if (btnCancel == null) {
btnCancel = new JButton();
btnCancel.setText("取 消");
btnCancel.setSize(new Dimension(70, 30));
btnCancel.setFont(new Font("Dialog", Font.BOLD, 13));
btnCancel.setLocation(new Point(226, 291));
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jFrame.dispose();
}
});
}
return btnCancel;
}
/**
* This method initializes txtCardNum
*
* @return javax.swing.JTextField
*/
private JTextField getTxtCardNum() {
if (txtCardNum == null) {
txtCardNum = new JTextField();
txtCardNum.setLocation(new Point(155, 23));
txtCardNum.setText("");
txtCardNum.setFont(new Font("Dialog", Font.PLAIN, 14));
txtCardNum.setSize(new Dimension(100, 25));
}
return txtCardNum;
}
/**
* This method initializes txtCardPswd
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getTxtCardPswd() {
if (txtCardPswd == null) {
txtCardPswd = new JPasswordField();
txtCardPswd.setText("");
txtCardPswd.setLocation(new Point(155, 61));
txtCardPswd.setFont(new Font("Dialog", Font.PLAIN, 14));
txtCardPswd.setSize(new Dimension(100, 25));
}
return txtCardPswd;
}
/**
* This method initializes txtPswdAgain
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getTxtPswdAgain() {
if (txtPswdAgain == null) {
txtPswdAgain = new JPasswordField();
txtPswdAgain.setText("");
txtPswdAgain.setLocation(new Point(155, 107));
txtPswdAgain.setFont(new Font("Dialog", Font.PLAIN, 14));
txtPswdAgain.setSize(new Dimension(100, 25));
}
return txtPswdAgain;
}
/**
* This method initializes txtBalance
*
* @return javax.swing.JTextField
*/
private JTextField getTxtBalance() {
if (txtBalance == null) {
txtBalance = new JTextField();
txtBalance.setText("");
txtBalance.setLocation(new Point(155, 151));
txtBalance.setFont(new Font("Dialog", Font.PLAIN, 14));
txtBalance.setSize(new Dimension(100, 25));
txtBalance.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent e) {
if(!txtBalance.getText().equals(""))
{
try
{
double balance=Double.parseDouble(txtBalance.getText());
if(balance<0)
{
JOptionPane.showMessageDialog(jFrame,"注冊時的金額不能為負數!");
txtBalance.setText("");
txtBalance.grabFocus();
}
}catch(NumberFormatException ne){
JOptionPane.showMessageDialog(jFrame,"輸入的不是純數字,請重新輸入!");
txtBalance.setText("");
txtBalance.grabFocus();
}
}
}
});
}
return txtBalance;
}
/**
* This method initializes txtName
*
* @return javax.swing.JTextField
*/
private JTextField getTxtName() {
if (txtName == null) {
txtName = new JTextField();
txtName.setText("");
txtName.setLocation(new Point(155, 196));
txtName.setFont(new Font("Dialog", Font.PLAIN, 14));
txtName.setSize(new Dimension(100, 25));
}
return txtName;
}
/**
* This method initializes txtPersonID
*
* @return javax.swing.JTextField
*/
private JTextField getTxtPersonID() {
if (txtPersonID == null) {
txtPersonID = new JTextField();
txtPersonID.setText("");
txtPersonID.setLocation(new Point(155, 237));
txtPersonID.setFont(new Font("Dialog", Font.PLAIN, 14));
txtPersonID.setSize(new Dimension(100, 25));
txtPersonID.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent e) {
if(!txtPersonID.getText().equals(""))
{
try
{
double balance=Double.parseDouble(txtPersonID.getText());
if(balance<0||txtPersonID.getText().length()!=6)
{
JOptionPane.showMessageDialog(jFrame,"身份證輸入有錯誤,請重新輸入![6位純數字]");
txtPersonID.setText("");
txtPersonID.grabFocus();
}
}catch(NumberFormatException ne){
JOptionPane.showMessageDialog(jFrame,"身份證輸入有錯誤,請重新輸入![6位純數字]");
txtPersonID.setText("");
txtPersonID.grabFocus();
}
}
}
});
}
return txtPersonID;
}
/**
* Launches this application
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
RegisterWindow application = new RegisterWindow();
application.getJFrame().setVisible(true);
}
});
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -