哪些虞书欣用J**a编写用户注册界面,包含:用户名、密码、密码确认、邮箱,以及注册和清空两个按钮。求高手,感谢!第1个回答:RUIRIVEN2018-05-26界面建议用可

第1个回答:

RUIRIVEN2018-05-26界面建议用可视化来做,美观且便捷。下面这个是完全用代码写的,仅供参考。importj**ax.swing.*;importj**a.awt.event.*;importj**a.awt.*;importj**a.sql.*;publicclassRegisterextendsJFrame{JLabeljl1=newJLabel("用户名");JTextFieldjt1=newJTextField();JLabeljl2=newJLabel("邮箱");JTextFieldjt2=newJTextField();JLabeljl3=newJLabel("密码");JPasswordFieldjpw1=newJPasswordField();JLabeljl4=newJLabel("密码确认");JPasswordFieldjpw2=newJPasswordField();JButtonregister=newJButton("注册");JButtonclean=newJButton("清空");publicRegister(){setLayout(newGridLayout(5,2));add(jl1);add(jt1);add(jl2);add(jt2);add(jl3);add(jpw1);add(jl4);add(jpw2);add(register);add(clean);Stringname=jt1.getText();Stringemail=jt2.getText();Stringpw=jpw1.getText();register.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){try{Class.forName("com.mysql.jdbc.Driver");Connectioncon=DriverManager.getConnection("jdbc:mysql://localhost/db","root","");Statementsta=con.createStatement();sta.executeUpdate("IN**RTINTOregisterVALUES(name,email,pw)");JOptionPane.showMessageDialog(**ll,"注册成功","提示",JOptionPane.INFORMATION_MESSAGE);}catch(Exceptionex){ex.getStackTrace();}}});clean.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){jt1.setText("");jt2.setText("");jpw1.setText("");jpw2.setText("");}});}publicstaticvoidmain(String[]args){Registerframe=newRegister();frame.setTitle("用户注册");frame.setLocationRelativeTo(**ll);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLO**);frame.setSize(400,400);frame.setVisible(true);}}