关于登录界面的作业

activity_main.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout
 3     xmlns:android="http://schemas.android.com/apk/res/android"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     tools:context=".MainActivity_DL"
 8     android:orientation="vertical">
 9     <LinearLayout
10         android:layout_width="match_parent"
11         android:layout_height="wrap_content"
12         android:orientation="horizontal">
13     <TextView
14         android:layout_width="match_parent"
15         android:layout_height="wrap_content"
16         android:hint="用户名:"/>
17     <EditText
18         android:layout_width="match_parent"
19         android:layout_height="wrap_content"
20         android:id="@+id/ai_1"/>
21     </LinearLayout>
22     <LinearLayout
23         android:layout_width="match_parent"
24         android:layout_height="wrap_content"
25         android:orientation="horizontal">
26         <TextView
27             android:layout_width="match_parent"
28             android:layout_height="wrap_content"
29             android:hint="密码:"/>
30         <EditText
31             android:layout_width="match_parent"
32             android:layout_height="wrap_content"
33             android:inputType="numberPassword"
34             android:id="@+id/ai_2"/>
35     </LinearLayout>
36     <LinearLayout
37         android:layout_width="match_parent"
38         android:layout_height="wrap_content"
39         android:orientation="horizontal">
40         <Button
41             android:layout_width="0dp"
42             android:layout_height="wrap_content"
43             android:layout_weight="1"
44             android:text="登录"
45             android:onClick="bi_1"/>
46        <Button
47            android:layout_width="0dp"
48            android:layout_height="wrap_content"
49            android:layout_weight="1"
50            android:text="注册"
51            android:onClick="bi_2"/>
52     </LinearLayout>
53 </LinearLayout>
View Code

zhuce_main.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout
 3     xmlns:android="http://schemas.android.com/apk/res/android"
 4     android:orientation="vertical"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent">
 7 
 8     <EditText
 9         android:layout_width="match_parent"
10         android:layout_height="wrap_content"
11         android:hint="用户名"
12         android:id="@+id/ci_1"/>
13     <EditText
14         android:layout_width="match_parent"
15         android:layout_height="wrap_content"
16         android:hint="用户密码"
17         android:id="@+id/ci_2"
18         android:inputType="numberPassword"/>
19     <EditText
20         android:layout_width="match_parent"
21         android:layout_height="wrap_content"
22         android:hint="输入手机号码"
23         android:id="@+id/ci_3"
24         android:inputType="phone"/>
25 
26     <LinearLayout
27         android:layout_width="match_parent"
28         android:layout_height="wrap_content"
29         android:orientation="horizontal">
30         <Button
31             android:layout_width="0dp"
32             android:layout_height="wrap_content"
33             android:layout_weight="1"
34             android:text="确定"
35             android:onClick="yes"/>
36         <Button
37             android:layout_width="0dp"
38             android:layout_height="wrap_content"
39             android:layout_weight="1"
40             android:text="取消"
41             android:onClick="no"/>
42     </LinearLayout>
43 </LinearLayout>
View Code

see_main.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout
 3     xmlns:android="http://schemas.android.com/apk/res/android"
 4     android:orientation="vertical"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent">
 7 
 8     <TextView
 9         android:layout_width="match_parent"
10         android:layout_height="wrap_content"
11         android:textSize="25dp"
12         android:textStyle="bold"
13         android:id="@+id/see_1"/>
14     <TextView
15         android:layout_width="match_parent"
16         android:layout_height="wrap_content"
17         android:textSize="25dp"
18         android:textStyle="bold"
19         android:id="@+id/see_2"/>
20 </LinearLayout>
View Code

MainActivity_ZC.java

 1 package com.example.administrator.testapp;
 2 
 3 import android.content.Intent;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.os.Bundle;
 6 import android.view.View;
 7 import android.widget.EditText;
 8 import android.widget.Toast;
 9 
10 import java.io.FileOutputStream;
11 import java.io.PrintStream;
12 import java.sql.SQLSyntaxErrorException;
13 
14 public class MainActivity_ZC extends AppCompatActivity {
15     EditText ci_1;
16     EditText ci_2;
17     EditText ci_3;
18 
19     @Override
20     protected void onCreate(Bundle savedInstanceState) {
21         super.onCreate(savedInstanceState);
22         setContentView(R.layout.zhuce_main);
23 
24         ci_1 = (EditText)findViewById(R.id.ci_1);
25 
26         ci_2 = (EditText)findViewById(R.id.ci_2);
27 
28         ci_3 = (EditText)findViewById(R.id.ci_3);
29     }
30     public void yes(View v)
31     {
32         String UC = ci_1.getText().toString();
33         if (UC==null||UC.trim().length()==0)
34         {
35             Toast.makeText(MainActivity_ZC.this, "请填写用户名",
36                     Toast.LENGTH_SHORT).show();
37             return;
38         }
39         String PW = ci_2.getText().toString();
40         if (PW==null||PW.trim().length()==0)
41         {
42             Toast.makeText(MainActivity_ZC.this, "请填写密码",
43                     Toast.LENGTH_SHORT).show();
44             return;
45         }
46         String PH = ci_3.getText().toString();
47         if (PH==null||PH.trim().length()==0)
48         {
49             Toast.makeText(MainActivity_ZC.this, "请输入电话号码",
50                     Toast.LENGTH_SHORT).show();
51             return;
52         }
53         try {
54             FileOutputStream FOS = openFileOutput("SEE.txt",MODE_PRIVATE);
55 
56             PrintStream ps = new PrintStream(FOS);
57 
58             ps.print(UC);
59 
60             FileOutputStream FOS2 = openFileOutput("SEE_2.txt",MODE_PRIVATE);
61 
62             PrintStream ps2 = new PrintStream(FOS2);
63 
64             ps2.print(PW);
65 
66             FileOutputStream FOS3 = openFileOutput("SEE_3.txt",MODE_PRIVATE);
67 
68             PrintStream ps3 = new PrintStream(FOS3);
69 
70             ps3.print(PH);
71 
72             ps.close();
73 
74             ps2.close();
75 
76             ps3.close();
77 
78             FOS.close();
79 
80             Toast.makeText(MainActivity_ZC.this, "保存成功",
81                     Toast.LENGTH_SHORT).show();
82         }
83         catch (Exception e)
84         {
85 
86         }
87         Intent intent  = new Intent(this,MainActivity_DL.class);
88 
89         startActivity(intent);
90 
91         finish();
92     }
93     public void no(View v)
94     {
95         setResult(RESULT_CANCELED,null);
96 
97         finish();
98     }
99 }
View Code

MainActivity_DL.java

  1 package com.example.administrator.testapp;
  2 
  3 import android.content.Intent;
  4 import android.support.v7.app.AppCompatActivity;
  5 import android.os.Bundle;
  6 import android.view.View;
  7 import android.widget.EditText;
  8 import android.widget.Toast;
  9 
 10 import java.io.FileInputStream;
 11 
 12 public class MainActivity_DL extends AppCompatActivity {
 13     EditText ai_1,ai_2;
 14 
 15     @Override
 16     protected void onCreate(Bundle savedInstanceState) {
 17         super.onCreate(savedInstanceState);
 18         setContentView(R.layout.activity_main);
 19 
 20         ai_1 = (EditText)findViewById(R.id.ai_1);
 21         ai_2 = (EditText)findViewById(R.id.ai_2);
 22     }
 23     public void bi_1(View v)
 24     {
 25         Intent intent = new Intent(this,MainActivity_DL.class);
 26         startActivity(intent);
 27     }
 28 
 29     public void bi_2(View v) {
 30         String ID = "";
 31         String PW = "";
 32         String PH = "";
 33 
 34         String uc = ai_1.getText().toString();
 35         String pw = ai_2.getText().toString();
 36 
 37         try {
 38             FileInputStream FIS = openFileInput("see.txt");
 39 
 40             byte[] b = new byte[1024];
 41 
 42             int i;
 43 
 44             while ((i = FIS.read(b)) > 0) {
 45                 String str = new String(b, 0, i);
 46                 ID += str;
 47             }
 48             FIS.close();
 49 
 50             FileInputStream FIS2 = openFileInput("see_2.txt");
 51 
 52             byte[] b2 = new byte[1024];
 53 
 54             int i2 = 0;
 55 
 56             while ((i2 = FIS2.read(b2)) > 0) {
 57                 String str = new String(b2, 0, i2);
 58 
 59                 PW += str;
 60             }
 61             FIS2.close();
 62 
 63             FileInputStream FIS3 = openFileInput("see_3,txt");
 64 
 65             byte[] b3 = new byte[1024];
 66 
 67             int i3 = 0;
 68 
 69             while ((i3 = FIS3.read(b3)) > 0) {
 70                 String str = new String(b3,0,i3);
 71 
 72                 PH += str;
 73             }
 74             FIS3.close();
 75         } catch (Exception e) {
 76 
 77         }
 78         if (uc.trim().length() == 0 || pw.trim().length() == 0) {
 79             Toast.makeText(MainActivity_DL.this, "用户名密码不能为空",
 80                     Toast.LENGTH_SHORT).show();
 81 
 82             return;
 83         }
 84         if (ID == null || (ID != null && !ID.equals(uc))) {
 85             Toast.makeText(MainActivity_DL.this, "用户未注册",
 86                     Toast.LENGTH_SHORT).show();
 87             return;
 88         }
 89         if (!PW.equals(pw)) {
 90             Toast.makeText(MainActivity_DL.this, "密码错误!",
 91                     Toast.LENGTH_SHORT).show();
 92 
 93             return;
 94         } else {
 95             Toast.makeText(MainActivity_DL.this, "用户验证成功!",
 96                     Toast.LENGTH_SHORT).show();
 97 
 98             Intent intent = new Intent(this,MainActivity_SEE.class);
 99             startActivity(intent);
100             finish();
101         }
102     }
103 }
View Code

MainActivity_SEE.java

 1 package com.example.administrator.testapp;
 2 
 3 import android.support.v7.app.AppCompatActivity;
 4 import android.os.Bundle;
 5 import android.widget.TextView;
 6 
 7 import java.io.FileInputStream;
 8 
 9 public class MainActivity_SEE extends AppCompatActivity {
10 
11     TextView see_1;
12     TextView see_2;
13 
14     String str1 = "";
15     String str2 = "";
16 
17     @Override
18     protected void onCreate(Bundle savedInstanceState) {
19         super.onCreate(savedInstanceState);
20         setContentView(R.layout.see_main);
21 
22         see_1 = (TextView)findViewById(R.id.see_1);
23         see_2 = (TextView)findViewById(R.id.see_2);
24 
25         try
26         {
27             FileInputStream FIS = openFileInput("see_3.txt");
28             byte[]b = new byte[1024];
29             int i;
30 
31             while((i=FIS.read(b))>0)
32             {
33                 String str = new String(b,0,i);
34                 str+=str;
35             }
36             FIS.close();
37 
38             FileInputStream FIS2 = openFileInput("see_4.txt");
39             byte[]b2 = new byte[1024];
40             int i2=0;
41 
42             while((i2=FIS2.read(b2))>0)
43             {
44                 String str = new String(b2,0,i2);
45 
46                 str2+=str;
47             }
48             FIS2.close();
49         }
50         catch (Exception e)
51         {
52 
53         }
54         see_1.setText("用户名是:"+str1);
55         see_2.setText("密码是:"+str2);
56     }
57 }
View Code

 

posted @ 2016-05-27 08:43  宫崎天川  阅读(138)  评论(0编辑  收藏  举报