以下是登陆类login.java:
package chatroom;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.Socket;
import java.util.*;
import javax.swing.*;
public class Login extends JFrame {
JLabel lblUsername, lblPassword;
JComboBox comboUsername;
JPasswordField txtPassword;
JButton jbnButton1, jbnButton2,jbnButton3;
BufferedReader read1;
PrintWriter write1;
JLabel lblname,lblwelcome,lb_ServerName,lb_port;
JTextField jt_servername,jt_port;
String s32;
TreeSet tr1;
Socket clientSocket;
BufferedReader sin;
PrintWriter sout;
liaotianshi lt1;
String ServerIp="localhost";
int ServerPort=10001;
boolean loginSucc;
String nickname;
public Login(String title) {
super(title);
tr1=new TreeSet();
String s="";
loginSucc=false;
try{
comboUsername = new JComboBox();
if ((new File("user.txt")).exists()){
read1 = new BufferedReader(new FileReader("user.txt"));
while ((s = read1.readLine()) != null)
{
comboUsername.addItem(s);
comboUsername.setSelectedIndex(0);
tr1.add(s);
}
read1.close();
}
lblname= new JLabel("好朋友聊天室");
lblname.setFont(new Font("宋体",Font.PLAIN,20));
lblname.setForeground(Color.RED);
lblwelcome= new JLabel("欢迎您!");
lblUsername = new JLabel("用户名:");
lblPassword = new JLabel("密 码:");
txtPassword = new JPasswordField(10);
lb_ServerName=new JLabel("服务器名称/IP");
lb_port=new JLabel("端口号");
jt_servername = new JTextField(15);
jt_servername.setText("localhost");
jt_port = new JTextField(15);
jt_port.setText("10001");