import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
class frame extends JFrame implements ActionListener{
frame fr;
JTextField UT;
JPasswordField PT1,PT2;
JButton but;
public void fr(){
fr = new frame();
fr.setTitle("注册");
fr.setLayout(null);
JLabel user = new JLabel("昵称:");
JLabel password1 = new JLabel("密码:");
JLabel password2 = new JLabel("密码:");
but = new JButton("提交");
UT = new JTextField();
PT1 = new JPasswordField(6);
PT2 = new JPasswordField(6);
user.setBounds(160, 50, 40, 20);
password1.setBounds(160, 80, 40, 20);
password2.setBounds(160, 110, 40, 20);
UT.setBounds(200, 50, 150, 20);
PT1.setBounds(200, 80, 150, 20);
PT2.setBounds(200, 110, 150, 20);
but.setBounds(235, 160, 60, 20);
fr.setBounds(300, 300, 500, 300);
fr.add(user);
fr.add(password1);
fr.add(password2);
fr.add(UT);
fr.add(PT1);
fr.add(PT2);
fr.add(but);
UT.addActionListener(this);
PT1.addActionListener(this);
PT2.addActionListener(this);
but.addActionListener(this);
fr.setResizable(false);//窗体大小不可变
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//窗体关闭
fr.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
String name = UT.getText();
String s1 = PT1.getText();
String s2 = PT2.getText();
if(b == but){
if(name.isEmpty() == true){//提示对话框
JOptionPane.showMessageDialog(null, "提示:昵称不能为空!");
}else if(s1.isEmpty() == true){
JOptionPane.showMessageDialog(null, "提示:密码不能为空!");
}else if(s1.isEmpty() == false && s1.equals(s2)){
fr.dispose();
write();
int action = JOptionPane.showConfirmDialog(null, "注册成功,是否要登录?","提示",JOptionPane.YES_NO_OPTION);
if(action == JOptionPane.YES_OPTION){
new log();//页面跳转
}else if(action == JOptionPane.NO_OPTION){
System.exit(0);
}
// frame F = new frame();
// F.setLayout(null);
// F.setTitle("注册成功!");
// JLabel L = new JLabel("恭喜您注册成功!");
// L.setBounds(100, 60, 104, 20);
// F.setBounds(300, 300, 300, 200);
// F.add(L);
// F.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// F.setVisible(true);
// F.setResizable(false);
}else{
JOptionPane.showMessageDialog(null, "提示:两次密码输入不一致!");
// System.exit(EXIT_ON_CLOSE);
// fr.dispose();
// fr.setVisible(false);
}
}
}
public void write(){
StringBuffer sb = new StringBuffer();//String
String line = "";
try {
InputStream i = new FileInputStream("E:/shixun/Workspaces/MyEclipse 9/ej/src/chart_/write.txt");//字节输入流
BufferedReader ins = new BufferedReader(new InputStreamReader(i));//字节转字符流
while((line=ins.readLine()) != null){
sb.append(line);//保存之前已存在的字符串
}
//这是后面加上的字符串
sb.append("-"+UT.getText());
sb.append(PT1.getText());
OutputStream out = new FileOutputStream("E:/shixun/Workspaces/MyEclipse 9/ej/src/chart_/write.txt");
out.write(new String(sb.toString()).getBytes());
out.flush();
out.close();
ins.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public class reg {
public reg(){//无参构造器
frame f = new frame();
f.fr();
}
public static void main(String[] args) {
new reg();
}
}
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
class frame extends JFrame implements ActionListener{
frame fr;
JTextField UT;
JPasswordField PT1,PT2;
JButton but;
public void fr(){
fr = new frame();
fr.setTitle("注册");
fr.setLayout(null);
JLabel user = new JLabel("昵称:");
JLabel password1 = new JLabel("密码:");
JLabel password2 = new JLabel("密码:");
but = new JButton("提交");
UT = new JTextField();
PT1 = new JPasswordField(6);
PT2 = new JPasswordField(6);
user.setBounds(160, 50, 40, 20);
password1.setBounds(160, 80, 40, 20);
password2.setBounds(160, 110, 40, 20);
UT.setBounds(200, 50, 150, 20);
PT1.setBounds(200, 80, 150, 20);
PT2.setBounds(200, 110, 150, 20);
but.setBounds(235, 160, 60, 20);
fr.setBounds(300, 300, 500, 300);
fr.add(user);
fr.add(password1);
fr.add(password2);
fr.add(UT);
fr.add(PT1);
fr.add(PT2);
fr.add(but);
UT.addActionListener(this);
PT1.addActionListener(this);
PT2.addActionListener(this);
but.addActionListener(this);
fr.setResizable(false);//窗体大小不可变
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//窗体关闭
fr.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
String name = UT.getText();
String s1 = PT1.getText();
String s2 = PT2.getText();
if(b == but){
if(name.isEmpty() == true){//提示对话框
JOptionPane.showMessageDialog(null, "提示:昵称不能为空!");
}else if(s1.isEmpty() == true){
JOptionPane.showMessageDialog(null, "提示:密码不能为空!");
}else if(s1.isEmpty() == false && s1.equals(s2)){
fr.dispose();
write();
int action = JOptionPane.showConfirmDialog(null, "注册成功,是否要登录?","提示",JOptionPane.YES_NO_OPTION);
if(action == JOptionPane.YES_OPTION){
new log();//页面跳转
}else if(action == JOptionPane.NO_OPTION){
System.exit(0);
}
// frame F = new frame();
// F.setLayout(null);
// F.setTitle("注册成功!");
// JLabel L = new JLabel("恭喜您注册成功!");
// L.setBounds(100, 60, 104, 20);
// F.setBounds(300, 300, 300, 200);
// F.add(L);
// F.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// F.setVisible(true);
// F.setResizable(false);
}else{
JOptionPane.showMessageDialog(null, "提示:两次密码输入不一致!");
// System.exit(EXIT_ON_CLOSE);
// fr.dispose();
// fr.setVisible(false);
}
}
}
public void write(){
StringBuffer sb = new StringBuffer();//String
String line = "";
try {
InputStream i = new FileInputStream("E:/shixun/Workspaces/MyEclipse 9/ej/src/chart_/write.txt");//字节输入流
BufferedReader ins = new BufferedReader(new InputStreamReader(i));//字节转字符流
while((line=ins.readLine()) != null){
sb.append(line);//保存之前已存在的字符串
}
//这是后面加上的字符串
sb.append("-"+UT.getText());
sb.append(PT1.getText());
OutputStream out = new FileOutputStream("E:/shixun/Workspaces/MyEclipse 9/ej/src/chart_/write.txt");
out.write(new String(sb.toString()).getBytes());
out.flush();
out.close();
ins.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public class reg {
public reg(){//无参构造器
frame f = new frame();
f.fr();
}
public static void main(String[] args) {
new reg();
}
}