java点击按键之后,另一个界面隐藏 5
java中,注册界面成功后,点击确认,使得注册界面消失。代码如下,求大神指点!!packageclient.login;importjava.awt.Button;imp...
java中,注册界面成功后,点击确认,使得注册界面消失。代码如下,求大神指点!!
package client.login;
import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import javax.swing.JOptionPane;
import com.liang.view.StudentView;
public class Register {
public static void main(String[] args) throws IOException{
File xx=new File("f:/信息.txt");
final BufferedWriter bws=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xx)));
BufferedReader brs=new BufferedReader(new InputStreamReader(new FileInputStream(xx)));
Frame fr=new Frame("注册");
Label be1=new Label("姓名:",Label.CENTER);
Label be2=new Label("密码:",Label.CENTER);
Label be3=new Label("确认密码:",Label.CENTER);
final TextField[] tf=new TextField[]{
new TextField(20),new TextField(20),new TextField(20)};
// final TextField tf2=new TextField(20);
// final TextField tf3=new TextField(20);
Button btok=new Button("注册");
Button btce=new Button("取消");
btok.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
// TODO Auto-generated method stub
String name=tf[0].getText(),psw = tf[1].getText(),again=tf[2].getText();
if("".equals(name)){
JOptionPane.showMessageDialog(null,"用户名空了");
return;}
if("".equals(psw)){
JOptionPane.showMessageDialog(null,"密码空了");
return;}
if(psw.length()<5||psw.length()>18){
JOptionPane.showMessageDialog(null,"密码不合格,长度应在5~17位之间");
return;}
if("".equals(again)){
JOptionPane.showMessageDialog(null,"确认密码为空");
return;}
if(!psw.equals(again)){
JOptionPane.showMessageDialog(null,"两次密码不一致,请从新输入");
return;}
JOptionPane.showMessageDialog(null,"恭喜登录成功");
FrmLogin sv=new FrmLogin();
sv.setVisible(true);
//Register.this.setVisible(false);//打开聊天室之后隐藏登录界面
try {
bws.write("用户名:"+name);
bws.newLine();
bws.write("密码为:"+psw);
bws.newLine();
bws.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}});
btce.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(JOptionPane.showConfirmDialog(null,"退出?","what",JOptionPane.OK_CANCEL_OPTION)==JOptionPane.YES_OPTION)
System.exit(0);}});
fr.setLayout(new GridLayout(4,4));
fr.add(be1);fr.add(tf[0]);
fr.add(be2);fr.add(tf[1]);
fr.add(be3);fr.add(tf[2]);
fr.add(btok);fr.add(btce);
fr.pack();
fr.setVisible(true);
}
} 展开
package client.login;
import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import javax.swing.JOptionPane;
import com.liang.view.StudentView;
public class Register {
public static void main(String[] args) throws IOException{
File xx=new File("f:/信息.txt");
final BufferedWriter bws=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xx)));
BufferedReader brs=new BufferedReader(new InputStreamReader(new FileInputStream(xx)));
Frame fr=new Frame("注册");
Label be1=new Label("姓名:",Label.CENTER);
Label be2=new Label("密码:",Label.CENTER);
Label be3=new Label("确认密码:",Label.CENTER);
final TextField[] tf=new TextField[]{
new TextField(20),new TextField(20),new TextField(20)};
// final TextField tf2=new TextField(20);
// final TextField tf3=new TextField(20);
Button btok=new Button("注册");
Button btce=new Button("取消");
btok.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
// TODO Auto-generated method stub
String name=tf[0].getText(),psw = tf[1].getText(),again=tf[2].getText();
if("".equals(name)){
JOptionPane.showMessageDialog(null,"用户名空了");
return;}
if("".equals(psw)){
JOptionPane.showMessageDialog(null,"密码空了");
return;}
if(psw.length()<5||psw.length()>18){
JOptionPane.showMessageDialog(null,"密码不合格,长度应在5~17位之间");
return;}
if("".equals(again)){
JOptionPane.showMessageDialog(null,"确认密码为空");
return;}
if(!psw.equals(again)){
JOptionPane.showMessageDialog(null,"两次密码不一致,请从新输入");
return;}
JOptionPane.showMessageDialog(null,"恭喜登录成功");
FrmLogin sv=new FrmLogin();
sv.setVisible(true);
//Register.this.setVisible(false);//打开聊天室之后隐藏登录界面
try {
bws.write("用户名:"+name);
bws.newLine();
bws.write("密码为:"+psw);
bws.newLine();
bws.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}});
btce.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(JOptionPane.showConfirmDialog(null,"退出?","what",JOptionPane.OK_CANCEL_OPTION)==JOptionPane.YES_OPTION)
System.exit(0);}});
fr.setLayout(new GridLayout(4,4));
fr.add(be1);fr.add(tf[0]);
fr.add(be2);fr.add(tf[1]);
fr.add(be3);fr.add(tf[2]);
fr.add(btok);fr.add(btce);
fr.pack();
fr.setVisible(true);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询