adi.setButton2("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
adi.show();
}
private RefreshHandler mRedrawHandler = new RefreshHandler();
class RefreshHandler extends Handler{
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
try {
socket = new Socket("113.250.155.194", 9999);
in = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
if(username.getText().length() == 0)
{
adi.show();
loginerror.setText("账号不能为空!");
loginerror.setVisibility(loginerror.VISIBLE);
}else if(password.getText().length() == 0){
adi.show();
loginerror.setText("密码不能为空!");
loginerror.setVisibility(loginerror.VISIBLE);
}else{
UserModel users = new UserModel();
users.setUserName(username.getText().toString());
users.setUserPass(password.getText().toString());
users.setUserState(1);
users.setGuanliyuan(0);
out.println("login&" + UserModel.userToString(users));
out.flush();
String line;
try {
line = in.readLine();
System.out.println("登录窗口从服务器收到的消息为:" + line);
if (line.startsWith("LOGINOK")) {
System.out.println(line.toString());
UserModel user = UserModel.getUserByString(line);
out.println("updateList&" + UserModel.userToString(user));
out.flush();
Toast.makeText(LoginActivity.this, "登陆成功", Toast.LENGTH_SHORT).show();
//ChatFrame cf = new ChatFrame(user.getNick(), user.getGuanliyuan());
// cf.setLocation(250, 50);
//cf.setVisible(true);
//cf.connect(in, out);
//this.dispose();
// return;
}else
if (line.equals("ERROR")) {
Toast.makeText(LoginActivity.this, "登陆失败", Toast.LENGTH_SHORT).show();
adi.show();
adi.findViewById(R.id.txt_loginerror).setVisibility(View.VISIBLE);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
m_Dilog.dismiss();
}
super.handleMessage(msg);
}
}
public void sleep(long delayMillis)
{
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), delayMillis);
}
}
就这么简单,效果图如下: