java编写邮箱注册代码 java邮箱注册功能
如何用Java编写用户注册界面?
界面建议用可视化来做,美观且便捷。下面这个是完全用代码写的,仅供参考。
网站建设哪家好,找成都创新互联公司!专注于网页设计、网站建设、微信开发、微信平台小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了桥东免费建站欢迎大家使用!
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);
}
}
实现用java邮箱注册功能。请给出简单案例代码。
用户注册后先把注册信息放入数据库,状态为未注册 1.发送邮件(邮件内容为网页格式) 2.邮件内容里加确认注册的链接(链接里有指定参数),点击链接跳转到确认注册画面 3.跳转到确认注册画面后把用户状态变为已注册 要代码 发你邮箱地址 给你发邮件的代码,其他的要具体情况具体分析
求解:用Java写一段程序,能实现注册用户的,包含用户名和密码,邮箱的GUI程序。
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class TestLogin implements ActionListener {
JTextField jtf1 = new JTextField(15);
JPasswordField jtf2 = new JPasswordField(15);
JTextField jtf3 = new JTextField(15);
JLabel jl0 = new JLabel("欢迎注册!");
String result = "";
@Override
public void actionPerformed(ActionEvent e) {
String comn = e.getActionCommand();
if ("提交".equals(comn)) {
FileInputStream fis;
try {
fis = new FileInputStream("D:\\Program File\\image\\input.txt");
byte[] b = new byte[1024];
while (true) {
int num = fis.read(b);
if (num == -1)
break;
result = result + new String(b, 0, num);
}
fis.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
String[] s = result.split(";", 0);
String name = jtf1.getText();
String password = jtf2.getText();
String email = jtf3.getText();
String temp = name + "," + password + "," + email + ";";
boolean flag = true;
for (int i = 0; i s.length; i++) {
String[] name0 = s[i].split(",", 0);
if (name.equals(name0[0])) {
jl0.setText("你输入的用户名重复啦!请重新输入");
flag = false;
jtf1.setText("");
jtf2.setText("");
jtf3.setText("");
jtf1.requestFocus();
break;
}
}
if (flag) {
try {
FileOutputStream fos = new FileOutputStream(
"D:\\Program File\\image\\input.txt", true);
fos.write(temp.getBytes());
fos.close();
jl0.setText("恭喜你!注册成功!");
jtf1.setText("");
jtf2.setText("");
jtf3.setText("");
jtf1.requestFocus();
} catch (Exception ae) {
ae.printStackTrace();
}
}
} else if ("清空".equals(comn)) {
jtf1.setText("");
jtf2.setText("");
jtf3.setText("");
jtf1.requestFocus();
}
}
public TestLogin() {
JFrame jf = new JFrame("登录界面");
GridLayout gl = new GridLayout(5, 1);
jf.setLayout(gl);
JPanel[] jp = new JPanel[5];
for (int i = 0; i jp.length; i++) {
jp[i] = new JPanel();
jf.add(jp[i]);
}
jp[0].add(jl0);
JLabel jl1 = new JLabel("用户名:");
jp[1].add(jl1);
jp[1].add(jtf1);
JLabel jl2 = new JLabel(" 密码: ");
jp[2].add(jl2);
jp[2].add(jtf2);
JLabel jl3 = new JLabel(" Email:");
jp[3].add(jl3);
jp[3].add(jtf3);
JButton jb1 = new JButton("提交");
jp[4].add(jb1);
jb1.addActionListener(this);
JButton jb2 = new JButton("清空");
jp[4].add(jb2);
jb2.addActionListener(this);
jf.setLocation(300, 200);
jf.pack();
jf.setVisible(true);
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestLogin();
}
}
这个应该就是你想要的答案!
分享标题:java编写邮箱注册代码 java邮箱注册功能
URL分享:http://scjbc.cn/article/dochgci.html