android实现登录注册.docx

上传人:b****6 文档编号:6676340 上传时间:2023-01-08 格式:DOCX 页数:21 大小:20.49KB
下载 相关 举报
android实现登录注册.docx_第1页
第1页 / 共21页
android实现登录注册.docx_第2页
第2页 / 共21页
android实现登录注册.docx_第3页
第3页 / 共21页
android实现登录注册.docx_第4页
第4页 / 共21页
android实现登录注册.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

android实现登录注册.docx

《android实现登录注册.docx》由会员分享,可在线阅读,更多相关《android实现登录注册.docx(21页珍藏版)》请在冰豆网上搜索。

android实现登录注册.docx

android实现登录注册

全局代码publicclassIPAddress{

publicstaticfinalStringIP="http:

//202.118.89.148:

8080/Education/";}

登录界面:

java代码

publicclassLoginActivityextendsActivity{

privatestaticButtonloginButton,registerButton,OutButton;

privatestaticEditTextusername,password;

privateButtonListenerb1=newButtonListener();

privateIntentintent;

privateStringinfo="";

privateStrings;

privateBuilderbuilder;

privateExitAllgol=newExitAll();

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.login);

ExitAll.getInstance().addActivity(this);

loginButton=(Button)findViewById(R.id.btn_Login);

loginButton.setOnClickListener(b1);

registerButton=(Button)findViewById(R.id.btn_Reset);

registerButton.setOnClickListener(b1);

username=(EditText)findViewById(R.id.et_staff_no);

password=(EditText)findViewById(R.id.et_password);

OutButton=(Button)findViewById(R.id.btn_Out);

OutButton.setOnClickListener(newView.OnClickListener(){

@Override

publicvoidonClick(Viewv){

builder.setTitle("确定退出?

”);

builder.setNegativeButton("确定",newandroid.content.DialogInterface.OnClickListener(){

@Override

publicvoidonClick(DialogInterfacedialog,intwhich){

//TODOAuto-generatedmethodstub

dialog.dismiss();

}

});

builder.setPositiveButton("退出",newandroid.content.DialogInterface.OnClickListener(){

@Override

publicvoidonClick(DialogInterfacedialog,intwhich){

//TODOAuto-generatedmethodstub

ExitAll.getInstance().exit();

}

});

builder.create().getWindow().setGravity(Gravity.BOTTOM);

builder.show();

}

});

builder=newAlertDialog.Builder(this);

}

publicclassButtonListenerimplementsView.OnClickListener{

publicbooleanlogin(Stringstr1,Stringstr2){

booleanb=false;

Stringss=IPAddress.IP+"Login?

username="+str1+"&password="+str2;

URLurl=null;

HttpURLConnectionconn=null;

try{

url=newURL(ss);

}catch(MalformedURLExceptione){

e.printStackTrace();

}

try{

conn=(HttpURLConnection)(url.openConnection());

}catch(IOExceptione){

e.printStackTrace();

}

InputStreamis=null;

try{

is=conn.getInputStream();

BufferedReaderin=newBufferedReader(newInputStreamReader(is));

Stringline;

while((line=in.readLine())!

=null){

if(line.equals("true")){

b=true;

}

}

is.close();

}catch(IOExceptione){

e.printStackTrace();

}

conn.disconnect();

returnb;

}

publicvoidonClick(Viewview){

if(view==loginButton){

if((username.getText().toString()).equals("")||(password.getText().toString()).equals("")){

Toast.makeText(getApplicationContext(),"用户名或密码不可为空",Toast.LENGTH_SHORT).show();

return;

}

if(login(username.getText().toString(),password.getText().toString())){

IPAddress.StaffNo=username.getText().toString();

s=username.getText().toString();

intent=newIntent();

Toast.makeText(LoginActivity.this,"登录成功"+info,Toast.LENGTH_SHORT).show();

intent.setClass(LoginActivity.this,MainActivtity.class);

startActivity(intent);//IPAddress.username=s;

gol.setLoginName(s);

password.setText("");

}

else{

Toast.makeText(LoginActivity.this,"用户名或密码错误",Toast.LENGTH_SHORT).show();

}

}

elseif(view==registerButton){

intent=newIntent();

intent.setClass(LoginActivity.this,RegisterActivity.class);

startActivity(intent);

}

}

}

}

}

Xml布局:

xmlversion="1.0"encoding="utf-8"?

>

xmlns:

android="

android:

orientation="vertical"

android:

gravity="center_horizontal"

android:

layout_width="fill_parent"

android:

layout_height="fill_parent”>

android:

orientation="horizontal"

android:

paddingTop="35px"

android:

layout_gravity="center_horizontal"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

>

android:

text="用户名"

android:

textSize="20sp"

android:

layout_width="100sp"

android:

layout_height="wrap_content"

android:

layout_gravity="center_vertical"

android:

textColor="#000000"

/>

android:

id="@+id/et_staff_no"

android:

singleLine="true"

android:

text="0"

android:

layout_width="200sp"

android:

layout_height="wrap_content"/>

android:

orientation="horizontal"

android:

layout_gravity="center_horizontal"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content">

android:

text="密码"

android:

textSize="20sp"

android:

layout_width="100sp"

android:

layout_height="wrap_content"

android:

layout_gravity="center_vertical"

android:

textColor="#000000"/>

android:

id="@+id/et_password"

android:

singleLine="true"

android:

password="true"

android:

text="0"

android:

layout_width="200sp"

android:

layout_height="wrap_content"/>

android:

orientation="horizontal"

android:

layout_gravity="center_horizontal"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

>

android:

id="@+id/btn_Login"

android:

layout_width="80dp"

android:

layout_height="wrap_content"

android:

text="登录"

android:

textSize="18sp"

/>

android:

id="@+id/btn_Reset"

android:

layout_width="80dp"

android:

layout_height="wrap_content"

android:

text="注册"

android:

textSize="18sp"

/>

android:

id="@+id/btn_Out"

android:

layout_width="80dp"

android:

layout_height="wrap_content"

android:

text="退出”

android:

textSize="18sp"

/>

 

注册界面:

java代码

publicclassRegisterActivityextendsActivity{

privateEditTextetv1,etv2,etv3,etv4,etv5,etv6,etv7,etv8;

privateButtonb1=null,b2=null;

privatePersonuser=newPerson();

@Override

publicvoidonCreate(BundlesavedInstanceState){

//TODOAuto-generatedmethodstub

super.onCreate(savedInstanceState);

this.setContentView(R.layout.register);

ExitAll.getInstance().addActivity(this);

etv1=(EditText)this.findViewById(R.id.reset_name);

etv2=(EditText)this.findViewById(R.id.reset_password);

etv3=(EditText)this.findViewById(R.id.reset_mail);

etv4=(EditText)this.findViewById(R.id.reset_telephone);

etv5=(EditText)this.findViewById(R.id.reset_xing);

etv6=(EditText)this.findViewById(R.id.reset_ming);

etv7=(EditText)this.findViewById(R.id.reset_colleage);

etv8=(EditText)this.findViewById(R.id.reset_address);

b1=(Button)findViewById(R.id.btn_command);

b2=(Button)findViewById(R.id.btn_cback);

b1.setOnClickListener(newView.OnClickListener(){

@Override

publicvoidonClick(Viewv){

//TODOAuto-generatedmethodstub

if((etv1.getText().toString()).equals("")||(etv2.getText().toString()).equals("")){

Toast.makeText(getApplicationContext(),"请填完信息",Toast.LENGTH_LONG).show();

return;

}

else{

sendData();}

}

});

b2.setOnClickListener(newView.OnClickListener(){

publicvoidonClick(Viewv){

Intentintent=newIntent();

intent.setClass(getApplicationContext(),LoginActivity.class);

startActivity(intent);

}

});

}

privatevoidgetData(){

try{

user.setusername(URLEncoder.encode(etv1.getText().toString(),"gb2312"));//发送人姓名

user.setpassword(URLEncoder.encode(etv2.getText().toString(),"gb2312"));

user.setStu_email(URLEncoder.encode(etv3.getText().toString(),"gb2312"));

user.setStu_tel(URLEncoder.encode(etv4.getText().toString(),"gb2312"));

user.setStu_fname(URLEncoder.encode(etv5.getText().toString(),"gb2312"));//发送人姓名

user.setStu_lname(URLEncoder.encode(etv6.getText().toString(),"gb2312"));

user.setStu_Department(URLEncoder.encode(etv7.getText().toString(),"gb2312"));

user.setStu_address(URLEncoder.encode(etv8.getText().toString(),"gb2312"));

}catch(UnsupportedEncodingExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

}

privatevoidsendData(){

getData();

Stringss=IPAddress.IP+"ResetServlet";

URLurl=null;

HttpURLConnectionconn=null;

booleanbb=true;

try{

url=newURL(ss);

}catch(MalformedURLExceptione){

e.printStackTrace();

}

try{

conn=(HttpURLConnection)(url.openConnection());

}catch(IOExceptione){

e.printStackTrace();

}

try{

ClientChangTypecc=newClientChangType();

cc.ObjectToXML(user,bean.Person.class,conn);

if(conn.getResponseCode()!

=200){

Toast.makeText(getApplicationContext(),"请求url失败",Toast.LENGTH_LONG).show();

thrownewRuntimeException("请求url失败");

}

InputStreamis=conn.getInputStream();//获取返回数据

BufferedReaderbf=newBufferedReader(newInputStreamReader(is));

Stringline="";

while((line=bf.readLine())!

=null){

if("false".equals(line))

bb=false;

}

is.close();

}catch(IOExceptione){

bb=false;

e.printStackTrace();

}

conn.disconnect();

if(bb){

Intentintent=newIntent();

Toast.makeText(getApplicationContext(),"申请成功!

",Toast.LENGTH_LONG).show();

intent.setClass(RegisterActivity.this,LoginActivity.class);//登录成功跳转到主功能界面

startActivity(intent);//启动Activity

}

else

Toast.makeText(getApplicationContext(),"注册失败!

",Toast.LENGTH_LONG).show();

}

}

Xml布局:

xmlversion="1.0"encoding="UTF-8"?

>

xmlns:

android="

android:

orientation="vertical"

android:

gravity="center_horizontal

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1