?? add.java
字號:
package client;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;
import com.swtdesigner.SwingResourceManager;
import sever.business.iface.ILibrarianInfoIface;
import sever.business.impl.IlibrarianInfoImpl;
import sever.entity.LibrarianInfo;
public class Add extends JFrame {
private ButtonGroup buttonGroup = new ButtonGroup();
private JTextField text1;
private JTextField text4;
private JTextField text3;
private JTextField text2;
private JTextField text;
private JPasswordField txtPwd;
private JPasswordField txtPwd1;
private JFrame frame;
ImageIcon image=new ImageIcon("E:\\image\\1.JPG");
ImageIcon image2=new ImageIcon("E:\\image\\2.JPG");
ImageIcon image3=new ImageIcon("E:\\image\\one.JPG");
ImageIcon icon =new ImageIcon("E:\\image\\m1.gif");
ImageIcon icon2 =new ImageIcon("E:\\image\\w4.gif");
/**
* Launch the application
* @param args
*/
// public static void main(String args[]) {
// try {
// Add window = new Add();
// window.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
/**
* Create the application
*/
public Add() {
new JFrame();
getContentPane().setLayout(null);
setBounds(190, 135, 446, 462);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setTitle("添加管理員");
text = new JTextField();
text.setBounds(130, 50, 191, 21);
getContentPane().add(text);
final JLabel label_1 = new JLabel();
label_1.setFont(new Font("@黑體", Font.PLAIN, 14));
label_1.setText("密 碼:");
label_1.setBounds(55, 93, 60, 15);
getContentPane().add(label_1);
final JLabel label_2 = new JLabel();
label_2.setFont(new Font("@黑體", Font.PLAIN, 14));
label_2.setText("確 認:");
label_2.setBounds(55, 133, 60, 15);
getContentPane().add(label_2);
final JRadioButton radioButton = new JRadioButton();
radioButton.setFont(new Font("@黑體", Font.PLAIN, 14));
radioButton.setBounds(130, 175, 21, 23);
getContentPane().add(radioButton);
final JRadioButton radioButton_1 = new JRadioButton();
radioButton_1.setFont(new Font("@黑體", Font.PLAIN, 14));
buttonGroup.add(radioButton);
buttonGroup.add(radioButton_1);
radioButton_1.setBounds(255, 175, 21, 23);
getContentPane().add(radioButton_1);
final JLabel label_3 = new JLabel();
label_3.setFont(new Font("@黑體", Font.PLAIN, 14));
label_3.setText("性 別:");
label_3.setBounds(55, 179, 60, 15);
getContentPane().add(label_3);
final JLabel label_4 = new JLabel();
label_4.setFont(new Font("@黑體", Font.PLAIN, 14));
label_4.setText("年 齡:");
label_4.setBounds(55, 218, 60, 15);
getContentPane().add(label_4);
text2 = new JTextField();
text2.setBounds(130, 250, 171, 21);
getContentPane().add(text2);
final JLabel label_5 = new JLabel();
label_5.setFont(new Font("@黑體", Font.PLAIN, 14));
label_5.setText("電 話:");
label_5.setBounds(55, 253, 60, 15);
getContentPane().add(label_5);
text3 = new JTextField();
text3.setBounds(130, 285, 171, 21);
getContentPane().add(text3);
final JLabel label_6 = new JLabel();
label_6.setFont(new Font("黑體", Font.PLAIN, 14));
label_6.setText("地 址:");
label_6.setBounds(55, 288, 60, 15);
getContentPane().add(label_6);
text4 = new JTextField();
text4.setBounds(130, 320, 171, 21);
getContentPane().add(text4);
final JLabel emailLabel = new JLabel();
emailLabel.setFont(new Font("@黑體", Font.PLAIN, 14));
emailLabel.setText("E-mail:");
emailLabel.setBounds(55, 323, 60, 15);
getContentPane().add(emailLabel);
final JButton button = new JButton();
button.setText("確認");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name=text.getText();
String add=text2.getText();
String tel=text3 .getText();
String email=text4.getText();
String age=text1.getText();
String pwd = txtPwd.getText();
String pwd1 = txtPwd.getText();
if(name.length()==0 ||add.length()==0 ||tel.length()==0 ||email.length()==0 ||age.length()==0 ||pwd1.length()==0 ||pwd.length()==0)
{
JOptionPane.showMessageDialog(null,"請填寫完整!","錯誤", JOptionPane.ERROR_MESSAGE);
}
else if(pwd.length()<6 ||pwd1.length()<6){
JOptionPane.showMessageDialog(null,"密碼不得少于6位數!","錯誤", JOptionPane.ERROR_MESSAGE);
}
else if(!pwd1.equals(pwd)){
JOptionPane.showMessageDialog(null,"前后輸入的密碼不相同!!","錯誤", JOptionPane.ERROR_MESSAGE);
}
else{
LibrarianInfo librarian=new LibrarianInfo();
librarian.setLibrarianName(text.getText().trim());
librarian.setLibrarianPass(txtPwd.getText().trim());
librarian.setLibrarianPosition(txtPwd1.getText().trim());
if(radioButton.isSelected()==true){
librarian.setLibrarianSex("男");
}
if(radioButton_1.isSelected()==true){
librarian.setLibrarianSex("女");
}
librarian.setLibrarianAge(Integer.parseInt(text1.getText().trim()));
librarian.setLibrarianTel(text2.getText().trim());
librarian.setLibrarianAddress(text3.getText().trim());
librarian.setLibrarianEmail(text4.getText().trim());
ILibrarianInfoIface libr=new IlibrarianInfoImpl();
boolean li=libr.addLibraian(librarian);
JOptionPane.showMessageDialog(null,"已成功添加!");
}
}
});
button.setFont(new Font("@黑體", Font.PLAIN, 14));
button.setBounds(96, 375, 69, 25);
getContentPane().add(button);
final JButton button_1 = new JButton();
button_1.setText("重置");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.setText("");
text2.setText("");
text3 .setText("");
text4.setText("");
text1.setText("");
txtPwd.setText("");
txtPwd1.setText("");
}
});
button_1.setFont(new Font("@黑體", Font.PLAIN, 14));
button_1.setBounds(261, 375, 69, 25);
getContentPane().add(button_1);
text1 = new JTextField();
text1.setBounds(130, 215, 101, 21);
getContentPane().add(text1);
final JLabel label_7 = new JLabel();
label_7.setFont(new Font("@黑體", Font.PLAIN, 14));
label_7.setText("用戶名:");
label_7.setBounds(55, 53, 60, 15);
getContentPane().add(label_7);
final JLabel label = new JLabel();
label.setIcon(SwingResourceManager.getIcon(Add.class, "m1.gif"));
label.setBounds(158, 158, 47, 45);
getContentPane().add(label);
final JLabel label_8 = new JLabel();
label_8.setIcon(SwingResourceManager.getIcon(Add.class, "w4.gif"));
label_8.setBounds(285, 158, 47, 46);
getContentPane().add(label_8);
txtPwd = new JPasswordField();
txtPwd.setToolTipText("請輸入6位以上的密碼");
txtPwd.setBounds(130, 88, 191, 25);
getContentPane().add(txtPwd);
txtPwd1 = new JPasswordField();
txtPwd1.setBounds(130, 128, 191, 25);
txtPwd1.setToolTipText("請輸入6位以上的密碼");
getContentPane().add(txtPwd1);
getContentPane().setBackground(new Color(224, 235, 237));
setIconImage(SwingResourceManager.getImage(Add.class, "/LOGO.jpg"));
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -