大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

关于注册的代码java java中注册代码

求解:用Java写一段程序,能实现注册用户的,包含用户名和密码,邮箱的GUI程序。

import java.awt.*;

成都创新互联主要从事成都网站建设、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务始兴,10多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792

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中注册代码
转载源于:http://dzwzjz.com/article/dshogoe.html
在线咨询
服务热线
服务热线:028-86922220
TOP