bjzhong25 bjzhong25
关注数: 22 粉丝数: 40 发帖数: 165 关注贴吧数: 4
不会做java用户登陆和注册啊,求大神帮忙 把自己写的两个界面奉上,求补全 登陆: import java.awt.Color; public class Login implements java.io.Serializable{ public String userName; public String passWord; public JFrame frmLogin; public JTextField textField; public JPasswordField passwordField; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Login window = new Login(); window.frmLogin.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Login() { initialize(); } /** * Initialize the contents of the frame. */ public void initialize() { frmLogin = new JFrame(); frmLogin.setTitle("Login"); frmLogin.getContentPane().setBackground(Color.DARK_GRAY); frmLogin.setBounds(100, 100, 419, 302); frmLogin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frmLogin.getContentPane().setLayout(null); frmLogin.setLocationRelativeTo(null); frmLogin.setAlwaysOnTop(true); frmLogin.setResizable(false); JLabel lblNewLabel = new JLabel("Login"); lblNewLabel.setFont(new Font("Algerian", Font.BOLD, 49)); lblNewLabel.setForeground(Color.GREEN); lblNewLabel.setBounds(24, 25, 184, 41); frmLogin.getContentPane().add(lblNewLabel); JLabel lblNewLabel_1 = new JLabel("Username"); lblNewLabel_1.setFont(new Font("Andalus", Font.PLAIN, 23)); lblNewLabel_1.setForeground(Color.GREEN); lblNewLabel_1.setBounds(72, 92, 95, 41); frmLogin.getContentPane().add(lblNewLabel_1); JLabel lblPassword = new JLabel("Password"); lblPassword.setFont(new Font("Andalus", Font.PLAIN, 23)); lblPassword.setForeground(Color.GREEN); lblPassword.setBounds(82, 143, 87, 36); frmLogin.getContentPane().add(lblPassword); textField = new JTextField(); textField.setBackground(Color.LIGHT_GRAY); textField.setBounds(190, 105, 119, 21); frmLogin.getContentPane().add(textField); textField.setColumns(10); passwordField = new JPasswordField(); passwordField.setEchoChar('*'); passwordField.setBackground(Color.LIGHT_GRAY); passwordField.setBounds(190, 154, 119, 21); frmLogin.getContentPane().add(passwordField); JButton btnLogin = new JButton("Login"); btnLogin.setForeground(Color.WHITE); btnLogin.setFont(new Font("Bernard MT Condensed", Font.PLAIN, 12)); btnLogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { } }); btnLogin.setBackground(Color.DARK_GRAY); btnLogin.setBounds(104, 208, 75, 21); frmLogin.getContentPane().add(btnLogin); JButton btnRegister = new JButton("Register"); btnRegister.setForeground(Color.WHITE); btnRegister.setFont(new Font("Bernard MT Condensed", Font.PLAIN, 12)); btnRegister.setBackground(Color.DARK_GRAY); btnRegister.setBounds(212, 207, 81, 21); frmLogin.getContentPane().add(btnRegister); } 注册: import java.awt.Color; import java.awt.EventQueue; import java.awt.Font; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class Register { ArrayList<Login> list = new ArrayList<Login>(); private JFrame frmRegister; private JTextField textField; private JTextField textField_1; private JTextField textField_2; private JTextField textField_3; private JTextField textField_4; private JTextField textField_5; private JTextField textField_6; private JPasswordField passwordField; private JPasswordField passwordField_1; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Register window = new Register(); window.frmRegister.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Register() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frmRegister = new JFrame(); frmRegister.setTitle("Register"); frmRegister.setResizable(false); frmRegister.getContentPane().setBackground(Color.DARK_GRAY); frmRegister.setLocationRelativeTo(null); frmRegister.setBounds(100, 100, 540, 598); frmRegister.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frmRegister.getContentPane().setLayout(null); JLabel lblRegister = new JLabel("Register"); lblRegister.setForeground(Color.GREEN); lblRegister.setFont(new Font("Algerian", Font.BOLD, 49)); lblRegister.setBounds(63, 30, 257, 41); frmRegister.getContentPane().add(lblRegister); JLabel lblUsername = new JLabel("username"); lblUsername.setForeground(Color.GREEN); lblUsername.setFont(new Font("Andalus", Font.PLAIN, 23)); lblUsername.setBounds(154, 98, 95, 23); frmRegister.getContentPane().add(lblUsername); JLabel lblPassword = new JLabel("password"); lblPassword.setForeground(Color.GREEN); lblPassword.setFont(new Font("Andalus", Font.PLAIN, 23)); lblPassword.setBounds(161, 132, 88, 23); frmRegister.getContentPane().add(lblPassword); JLabel lblPasswordComfirmation = new JLabel("password comfirmation"); lblPasswordComfirmation.setForeground(Color.GREEN); lblPasswordComfirmation.setFont(new Font("Andalus", Font.PLAIN, 23)); lblPasswordComfirmation.setBounds(28, 165, 221, 23); frmRegister.getContentPane().add(lblPasswordComfirmation); JLabel lblEmail = new JLabel("e-mail"); lblEmail.setForeground(Color.GREEN); lblEmail.setFont(new Font("Andalus", Font.PLAIN, 23)); lblEmail.setBounds(187, 229, 62, 23); frmRegister.getContentPane().add(lblEmail); JLabel lblQq = new JLabel("QQ"); lblQq.setForeground(Color.GREEN); lblQq.setFont(new Font("Andalus", Font.PLAIN, 23)); lblQq.setBounds(215, 262, 34, 23); frmRegister.getContentPane().add(lblQq); JLabel lblGrade = new JLabel("grade"); lblGrade.setForeground(Color.GREEN); lblGrade.setFont(new Font("Andalus", Font.PLAIN, 23)); lblGrade.setBounds(195, 361, 54, 23); frmRegister.getContentPane().add(lblGrade); JLabel lblClass = new JLabel("class"); lblClass.setForeground(Color.GREEN); lblClass.setFont(new Font("Andalus", Font.PLAIN, 23)); lblClass.setBounds(206, 328, 43, 23); frmRegister.getContentPane().add(lblClass); JLabel lblStudentId = new JLabel("student ID"); lblStudentId.setForeground(Color.GREEN); lblStudentId.setFont(new Font("Andalus", Font.PLAIN, 23)); lblStudentId.setBounds(150, 394, 99, 23); frmRegister.getContentPane().add(lblStudentId); JLabel lblTel = new JLabel("telephone"); lblTel.setForeground(Color.GREEN); lblTel.setFont(new Font("Andalus", Font.PLAIN, 23)); lblTel.setBounds(167, 295, 82, 23); frmRegister.getContentPane().add(lblTel); textField = new JTextField(); textField.setBounds(295, 103, 147, 19); frmRegister.getContentPane().add(textField); textField.setColumns(10); textField_1 = new JTextField(); textField_1.setColumns(10); textField_1.setBounds(295, 234, 147, 19); frmRegister.getContentPane().add(textField_1); textField_2 = new JTextField(); textField_2.setColumns(10); textField_2.setBounds(295, 266, 147, 19); frmRegister.getContentPane().add(textField_2); textField_3 = new JTextField(); textField_3.setColumns(10); textField_3.setBounds(295, 300, 147, 19); frmRegister.getContentPane().add(textField_3); textField_4 = new JTextField(); textField_4.setColumns(10); textField_4.setBounds(295, 333, 147, 19); frmRegister.getContentPane().add(textField_4); textField_5 = new JTextField(); textField_5.setColumns(10); textField_5.setBounds(295, 366, 147, 19); frmRegister.getContentPane().add(textField_5); textField_6 = new JTextField(); textField_6.setColumns(10); textField_6.setBounds(295, 399, 147, 19); frmRegister.getContentPane().add(textField_6); passwordField = new JPasswordField(); passwordField.setEchoChar('*'); passwordField.setBounds(295, 136, 147, 19); frmRegister.getContentPane().add(passwordField); passwordField_1 = new JPasswordField(); passwordField_1.setEchoChar('*'); passwordField_1.setBounds(295, 170, 147, 19); frmRegister.getContentPane().add(passwordField_1); JButton btnCreat = new JButton("Creat"); btnCreat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { /*serialization(textField.getText() ,passwordField.getText() ); */ /* String str = e.getActionCommand(); if ("Creat".equals(str)) { Login user = new Login(); user.setUserName(textField.getText()); user.setPassWord(textField_1.getText()); //user.setEmail(textField_3.getText()); String rePassWord = textField_2.getText(); if (!(user.getPassWord().equalsIgnoreCase(rePassWord))) { textField_1.setText("密码输入错误"); textField_2.setText("密码输入错误"); } else { frmRegister.setTitle("Successful registration" + "Welcome" + user.getUserName()); jtf2.setText("******"); jtf3.setText("******"); list.add(user); } } else if ("登录".equals(str)) { try { readFromFile(); } catch (Exception e1) { e1.printStackTrace(); } } */} }); btnCreat.setForeground(Color.WHITE); btnCreat.setBackground(Color.DARK_GRAY); btnCreat.setFont(new Font("Bernard MT Condensed", Font.PLAIN, 12)); btnCreat.setBounds(237, 480, 62, 23); frmRegister.getContentPane().add(btnCreat); JCheckBox chckbxAgreeToThe = new JCheckBox("agree to the Teddy Services Agreement and privacy and cookies statement."); chckbxAgreeToThe.setForeground(Color.WHITE); chckbxAgreeToThe.setFont(new Font("Bernard MT Condensed", Font.PLAIN, 12)); chckbxAgreeToThe.setBackground(Color.DARK_GRAY); chckbxAgreeToThe.setBounds(93, 442, 397, 23); frmRegister.getContentPane().add(chckbxAgreeToThe); JLabel label = new JLabel("------------------------------------------------------------------------------------------------------"); label.setForeground(Color.WHITE); label.setBounds(-28, 198, 636, 15); frmRegister.getContentPane().add(label); } public void serialization(String username ,String Password ){ ObjectOutputStream oos=null; try { oos=new ObjectOutputStream(new FileOutputStream("D:\\Register.txt")); User use=new User(username ,Password); oos.writeObject(use); oos.flush(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { if(oos!=null) oos.close(); } catch (IOException e) { e.printStackTrace(); } } } }
不会做java用户登陆和注册啊,求大神帮忙 把自己写的两个界面奉上,求补全 登陆: import java.awt.Color; public class Login implements java.io.Serializable{ public String userName; public String passWord; public JFrame frmLogin; public JTextField textField; public JPasswordField passwordField; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Login window = new Login(); window.frmLogin.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Login() { initialize(); } /** * Initialize the contents of the frame. */ public void initialize() { frmLogin = new JFrame(); frmLogin.setTitle("Login"); frmLogin.getContentPane().setBackground(Color.DARK_GRAY); frmLogin.setBounds(100, 100, 419, 302); frmLogin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frmLogin.getContentPane().setLayout(null); frmLogin.setLocationRelativeTo(null); frmLogin.setAlwaysOnTop(true); frmLogin.setResizable(false); JLabel lblNewLabel = new JLabel("Login"); lblNewLabel.setFont(new Font("Algerian", Font.BOLD, 49)); lblNewLabel.setForeground(Color.GREEN); lblNewLabel.setBounds(24, 25, 184, 41); frmLogin.getContentPane().add(lblNewLabel); JLabel lblNewLabel_1 = new JLabel("Username"); lblNewLabel_1.setFont(new Font("Andalus", Font.PLAIN, 23)); lblNewLabel_1.setForeground(Color.GREEN); lblNewLabel_1.setBounds(72, 92, 95, 41); frmLogin.getContentPane().add(lblNewLabel_1); JLabel lblPassword = new JLabel("Password"); lblPassword.setFont(new Font("Andalus", Font.PLAIN, 23)); lblPassword.setForeground(Color.GREEN); lblPassword.setBounds(82, 143, 87, 36); frmLogin.getContentPane().add(lblPassword); textField = new JTextField(); textField.setBackground(Color.LIGHT_GRAY); textField.setBounds(190, 105, 119, 21); frmLogin.getContentPane().add(textField); textField.setColumns(10); passwordField = new JPasswordField(); passwordField.setEchoChar('*'); passwordField.setBackground(Color.LIGHT_GRAY); passwordField.setBounds(190, 154, 119, 21); frmLogin.getContentPane().add(passwordField); JButton btnLogin = new JButton("Login"); btnLogin.setForeground(Color.WHITE); btnLogin.setFont(new Font("Bernard MT Condensed", Font.PLAIN, 12)); btnLogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { } }); btnLogin.setBackground(Color.DARK_GRAY); btnLogin.setBounds(104, 208, 75, 21); frmLogin.getContentPane().add(btnLogin); JButton btnRegister = new JButton("Register"); btnRegister.setForeground(Color.WHITE); btnRegister.setFont(new Font("Bernard MT Condensed", Font.PLAIN, 12)); btnRegister.setBackground(Color.DARK_GRAY); btnRegister.setBounds(212, 207, 81, 21); frmLogin.getContentPane().add(btnRegister); } 注册: import java.awt.Color; import java.awt.EventQueue; import java.awt.Font; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class Register { ArrayList<Login> list = new ArrayList<Login>(); private JFrame frmRegister; private JTextField textField; private JTextField textField_1; private JTextField textField_2; private JTextField textField_3; private JTextField textField_4; private JTextField textField_5; private JTextField textField_6; private JPasswordField passwordField; private JPasswordField passwordField_1; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Register window = new Register(); window.frmRegister.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Register() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frmRegister = new JFrame(); frmRegister.setTitle("Register"); frmRegister.setResizable(false); frmRegister.getContentPane().setBackground(Color.DARK_GRAY); frmRegister.setLocationRelativeTo(null); frmRegister.setBounds(100, 100, 540, 598); frmRegister.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frmRegister.getContentPane().setLayout(null); JLabel lblRegister = new JLabel("Register"); lblRegister.setForeground(Color.GREEN); lblRegister.setFont(new Font("Algerian", Font.BOLD, 49)); lblRegister.setBounds(63, 30, 257, 41); frmRegister.getContentPane().add(lblRegister); JLabel lblUsername = new JLabel("username"); lblUsername.setForeground(Color.GREEN); lblUsername.setFont(new Font("Andalus", Font.PLAIN, 23)); lblUsername.setBounds(154, 98, 95, 23); frmRegister.getContentPane().add(lblUsername); JLabel lblPassword = new JLabel("password"); lblPassword.setForeground(Color.GREEN); lblPassword.setFont(new Font("Andalus", Font.PLAIN, 23)); lblPassword.setBounds(161, 132, 88, 23); frmRegister.getContentPane().add(lblPassword); JLabel lblPasswordComfirmation = new JLabel("password comfirmation"); lblPasswordComfirmation.setForeground(Color.GREEN); lblPasswordComfirmation.setFont(new Font("Andalus", Font.PLAIN, 23)); lblPasswordComfirmation.setBounds(28, 165, 221, 23); frmRegister.getContentPane().add(lblPasswordComfirmation); JLabel lblEmail = new JLabel("e-mail"); lblEmail.setForeground(Color.GREEN); lblEmail.setFont(new Font("Andalus", Font.PLAIN, 23)); lblEmail.setBounds(187, 229, 62, 23); frmRegister.getContentPane().add(lblEmail); JLabel lblQq = new JLabel("QQ"); lblQq.setForeground(Color.GREEN); lblQq.setFont(new Font("Andalus", Font.PLAIN, 23)); lblQq.setBounds(215, 262, 34, 23); frmRegister.getContentPane().add(lblQq); JLabel lblGrade = new JLabel("grade"); lblGrade.setForeground(Color.GREEN); lblGrade.setFont(new Font("Andalus", Font.PLAIN, 23)); lblGrade.setBounds(195, 361, 54, 23); frmRegister.getContentPane().add(lblGrade); JLabel lblClass = new JLabel("class"); lblClass.setForeground(Color.GREEN); lblClass.setFont(new Font("Andalus", Font.PLAIN, 23)); lblClass.setBounds(206, 328, 43, 23); frmRegister.getContentPane().add(lblClass); JLabel lblStudentId = new JLabel("student ID"); lblStudentId.setForeground(Color.GREEN); lblStudentId.setFont(new Font("Andalus", Font.PLAIN, 23)); lblStudentId.setBounds(150, 394, 99, 23); frmRegister.getContentPane().add(lblStudentId); JLabel lblTel = new JLabel("telephone"); lblTel.setForeground(Color.GREEN); lblTel.setFont(new Font("Andalus", Font.PLAIN, 23)); lblTel.setBounds(167, 295, 82, 23); frmRegister.getContentPane().add(lblTel); textField = new JTextField(); textField.setBounds(295, 103, 147, 19); frmRegister.getContentPane().add(textField); textField.setColumns(10); textField_1 = new JTextField(); textField_1.setColumns(10); textField_1.setBounds(295, 234, 147, 19); frmRegister.getContentPane().add(textField_1); textField_2 = new JTextField(); textField_2.setColumns(10); textField_2.setBounds(295, 266, 147, 19); frmRegister.getContentPane().add(textField_2); textField_3 = new JTextField(); textField_3.setColumns(10); textField_3.setBounds(295, 300, 147, 19); frmRegister.getContentPane().add(textField_3); textField_4 = new JTextField(); textField_4.setColumns(10); textField_4.setBounds(295, 333, 147, 19); frmRegister.getContentPane().add(textField_4); textField_5 = new JTextField(); textField_5.setColumns(10); textField_5.setBounds(295, 366, 147, 19); frmRegister.getContentPane().add(textField_5); textField_6 = new JTextField(); textField_6.setColumns(10); textField_6.setBounds(295, 399, 147, 19); frmRegister.getContentPane().add(textField_6); passwordField = new JPasswordField(); passwordField.setEchoChar('*'); passwordField.setBounds(295, 136, 147, 19); frmRegister.getContentPane().add(passwordField); passwordField_1 = new JPasswordField(); passwordField_1.setEchoChar('*'); passwordField_1.setBounds(295, 170, 147, 19); frmRegister.getContentPane().add(passwordField_1); JButton btnCreat = new JButton("Creat"); btnCreat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { /*serialization(textField.getText() ,passwordField.getText() ); */ /* String str = e.getActionCommand(); if ("Creat".equals(str)) { Login user = new Login(); user.setUserName(textField.getText()); user.setPassWord(textField_1.getText()); //user.setEmail(textField_3.getText()); String rePassWord = textField_2.getText(); if (!(user.getPassWord().equalsIgnoreCase(rePassWord))) { textField_1.setText("密码输入错误"); textField_2.setText("密码输入错误"); } else { frmRegister.setTitle("Successful registration" + "Welcome" + user.getUserName()); jtf2.setText("******"); jtf3.setText("******"); list.add(user); } } else if ("登录".equals(str)) { try { readFromFile(); } catch (Exception e1) { e1.printStackTrace(); } } */} }); btnCreat.setForeground(Color.WHITE); btnCreat.setBackground(Color.DARK_GRAY); btnCreat.setFont(new Font("Bernard MT Condensed", Font.PLAIN, 12)); btnCreat.setBounds(237, 480, 62, 23); frmRegister.getContentPane().add(btnCreat); JCheckBox chckbxAgreeToThe = new JCheckBox("agree to the Teddy Services Agreement and privacy and cookies statement."); chckbxAgreeToThe.setForeground(Color.WHITE); chckbxAgreeToThe.setFont(new Font("Bernard MT Condensed", Font.PLAIN, 12)); chckbxAgreeToThe.setBackground(Color.DARK_GRAY); chckbxAgreeToThe.setBounds(93, 442, 397, 23); frmRegister.getContentPane().add(chckbxAgreeToThe); JLabel label = new JLabel("------------------------------------------------------------------------------------------------------"); label.setForeground(Color.WHITE); label.setBounds(-28, 198, 636, 15); frmRegister.getContentPane().add(label); } public void serialization(String username ,String Password ){ ObjectOutputStream oos=null; try { oos=new ObjectOutputStream(new FileOutputStream("D:\\Register.txt")); User use=new User(username ,Password); oos.writeObject(use); oos.flush(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { if(oos!=null) oos.close(); } catch (IOException e) { e.printStackTrace(); } } } }
1 下一页