十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
界面建议用可视化来做,美观且便捷。下面这个是完全用代码写的,仅供参考。
网站的建设成都创新互联公司专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为塑料袋等企业提供专业服务。
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
public class Register extends JFrame {
JLabel jl1 = new JLabel("用户名");
JTextField jt1 = new JTextField();
JLabel jl2 = new JLabel("邮箱");
JTextField jt2 = new JTextField();
JLabel jl3 = new JLabel("密码");
JPasswordField jpw1 = new JPasswordField();
JLabel jl4 = new JLabel("密码确认");
JPasswordField jpw2 = new JPasswordField();
JButton register = new JButton("注册");
JButton clean = new JButton("清空");
public Register(){
setLayout(new GridLayout(5,2));
add(jl1);
add(jt1);
add(jl2);
add(jt2);
add(jl3);
add(jpw1);
add(jl4);
add(jpw2);
add(register);
add(clean);
String name = jt1.getText();
String email = jt2.getText();
String pw = jpw1.getText();
register.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/db","root","");
Statement sta = con.createStatement();
sta.executeUpdate("INSERT INTO register VALUES(name,email,pw)");
JOptionPane.showMessageDialog(null,"注册成功","提示",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception ex){
ex.getStackTrace();
}
}
});
clean.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jt1.setText("");
jt2.setText("");
jpw1.setText("");
jpw2.setText("");
}
});
}
public static void main(String[] args){
Register frame = new Register();
frame.setTitle("用户注册");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setVisible(true);
}
}
只是参考,需要自己需改!
package com.ivory.view;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import com.ivory点抗 mon.User;
import com.ivory.sql.UserServer;
public class AddUser extends JDialog implements ActionListener
{
JLabel jl1,jl2,jl3,jl4,jl5,jl6,jl7,jl8,jl9;
JTextField jtf1,jtf2,jtf3,jtf4,jtf5,jtf6,jtf7,jtf8;
JButton jb1,jb2;
Font f1=new Font("宋体",Font.PLAIN,16);
User user;
public AddUser(User u)
{
Container ct=new Container();
jl1=new JLabel("账号");
jl1.setFont(f1);
jl1.setBounds(10, 60, 100, 30);
jl2=new JLabel("密码");
jl2.setFont(f1);
jl2.setBounds(10, 110, 100, 30);
jl3=new JLabel("密码");
jl3.setFont(f1);
jl3.setBounds(10, 160, 100, 30);
jl4=new JLabel("姓名");
jl4.setFont(f1);
jl4.setBounds(10, 210, 100, 30);
jl5=new JLabel("性别");
jl5.setFont(f1);
jl5.setBounds(10, 260, 100, 30);
jl6=new JLabel("班级");
jl6.setFont(f1);
jl6.setBounds(10, 310, 100, 30);
jl7=new JLabel("Tel");
jl7.setFont(f1);
jl7.setBounds(10, 370, 100, 30);
jl8=new JLabel("成绩");
jl8.setFont(f1);
jl8.setBounds(10, 410, 100, 30);
jl9=new JLabel("注册用户");
jl9.setFont(f1);
jl9.setBounds(100, 10, 100, 30);
jb1=new JButton(new ImageIcon("image\\queding.jpg"));
jb1.setBounds(40, 460, 70, 30);
jb1.addActionListener(this);
jb1.setActionCommand("queding");
jb2=new JButton(new ImageIcon("image\\quxiao.jpg"));
jb2.setBounds(200, 460, 70, 30);
jb2.addActionListener(this);
jb2.setActionCommand("quxiao");
jtf1=new JTextField(20);
jtf1.setBounds(50, 60, 200, 30);
jtf2=new JTextField(20);
jtf2.setBounds(50, 110, 200, 30);
jtf3=new JTextField(10);
jtf3.setBounds(50, 160, 200, 30);
jtf4=new JTextField(20);
jtf4.setBounds(50, 210, 200, 30);
jtf5=new JTextField(15);
jtf5.setBounds(50, 260, 200, 30);
jtf6=new JTextField(20);
jtf6.setBounds(50, 310, 200, 30);
jtf7=new JTextField(10);
jtf7.setBounds(50, 360, 200, 30);
jtf8=new JTextField(20);
jtf8.setBounds(50, 410, 200, 30);
jtf8.setText("100");
jtf8.setEditable(false);
ct.add(jl9);ct.add(jl1);ct.add(jl2);
ct.add(jl3);ct.add(jl4);ct.add(jl5);
ct.add(jl6);ct.add(jl7);ct.add(jl8);
ct.add(jtf1);ct.add(jtf2);ct.add(jtf3);
ct.add(jtf4);ct.add(jtf5);ct.add(jtf6);
ct.add(jtf7);ct.add(jtf8);
ct.add(jb1);ct.add(jb2);
BackIamge bi=new BackIamge();
bi.setBounds(0,0,300,500);
ct.add(bi);
this.add(ct);
this.setSize(300,500);
this.setUndecorated(true);
this.setLocation(500, 100);
this.setVisible(true);
}
//定义一个内部类(背景图片)
class BackIamge extends JPanel
{
Image im;
public BackIamge()
{
try {
im=ImageIO.read(new File("image//add.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//定义paint方法
public void paintComponent(Graphics g)
{
//画出背景图片
g.drawImage(im, 0,0,300,500,this);
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getActionCommand().equals("queding"))
{
User u=new User();
u.setUser(jtf1.getText());
u.setPassword(jtf2.getText());
u.setPassword(jtf3.getText());
u.setNumName(jtf4.getText());
u.setNumSex(jtf5.getText());
u.setNumClass(jtf6.getText());
u.setNumTel(jtf7.getText());
u.setNumMark(jtf8.getText());
u.setMessage("add");
if(!jtf2.getText().equals(jtf3.getText()))
{
JOptionPane.showMessageDialog(null, "密码不一致");
}
else
{
if(u.getMessage().equals("1"))
{
JOptionPane.showMessageDialog(null, "注册成功!");
this.dispose();
}else
{
JOptionPane.showMessageDialog(null, "注册失败!");
}
}
}
else if(e.getActionCommand().equals("quxiao"))
{
this.dispose();
}
}
}
简单举例:
functioncheckForm(){
varusername=document.getElementById('username').value;
varpwd=document.getElementById('pwd').value;
varrePwd=document.getElementById('rePwd').value;
varemail=document.getElementById('email').value;
varcheckAgree=document.getElementById('checkAgree');
varform=document.getElementById('form');
varemailReg=/^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$/;
if(username==''){
alert('用户名不能为空');
document.getElementById('username').focus();
returnfalse;
}
if(pwd==\"\"){
//不能为空
}
if(pwd.lentht
//长度不能小于6位
}
if(pwd!=rePwd){
//密码确认密码不一致
}
//日期的话建议用日历控件可以参考网上自己弄一弄
if(!emailReg.test(email)){
//邮箱格式不对
}
if(!checkAgree.checked){
//尚未统一协议
}
//所有验证通过之后提交表单
//form.submit();
}
写了基本的东西出来还是希望你能自己研究研究自己动手搞定