Android studio 通过mysql连接数据库完成注册登录,登陆后通过tcp协议与电脑的网络调试助手互发信息

先不多直接看软件截图

这个是首页等陆界面

xml代码如下

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/port"
    tools:context=".MainActivity"
    android:orientation="vertical">


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:layout_marginTop="20dp"
        android:gravity="center">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/jxlkjlog" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="@string/welcome"
            android:textColor="#000000"
            android:textSize="20.5sp"
            android:textStyle="bold" />



    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_marginStart="50dp"
        android:layout_marginTop="200dp"
        android:layout_marginEnd="50dp"
        >

        <TextView
            android:id="@+id/text_username"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="@string/username"
            android:textColor="#000000"
            android:textSize="25sp"
            android:textStyle="bold">

        </TextView>

        <EditText
            android:id="@+id/Edit_username"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_toEndOf="@id/text_username"
            android:hint="用户名不少于三位"
            android:inputType="text"
            android:autofillHints=""></EditText>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_marginStart="50dp"

        android:layout_marginEnd="50dp">

        <TextView
            android:id="@+id/text_passwold"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="@string/passwold"
            android:textColor="#000000"
            android:textSize="25sp"
            android:textStyle="bold">

        </TextView>

        <EditText
            android:id="@+id/Edit_passwold"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_toEndOf="@id/text_passwold"
            android:inputType="textPassword"
            android:hint="密码不少于四位"

            ></EditText>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center">

        <Button
            android:id="@+id/btn_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/login"
            tools:ignore="ButtonStyle">



        </Button>

        <Button
            android:id="@+id/btn_enroll"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/enroll"
            tools:ignore="ButtonStyle">

        </Button>
    </LinearLayout>

</LinearLayout>

MainActivity文件

public class MainActivity extends AppCompatActivity {
private Button mButtonLongin;
private Button mButtonEnroll;
private EditText mEditTextUsername;
private EditText mEditTextPassword;
private String username;
private String password;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mButtonLongin=findViewById(R.id.btn_login);
        mButtonEnroll=findViewById(R.id.btn_enroll);
        mEditTextUsername=findViewById(R.id.Edit_username);
        mEditTextPassword=findViewById(R.id.Edit_passwold);
        UserDao userDao=new UserDao();
        mButtonEnroll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,MainActivity3.class);
                startActivity(intent);
            }

        });
        mButtonLongin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
        EditText editTextusername=findViewById(R.id.Edit_username);
        EditText editTextpassword=findViewById(R.id.Edit_passwold);
                if (editTextusername.length() < 3) {
//                    Toast.makeText(MainActivity.this, "用户名不能小于三位", Toast.LENGTH_LONG).show();
                    CommonUtils.showLontMsg(MainActivity.this, "用户名不能小于三位");

                } else if (editTextpassword.length() < 4) {

                    CommonUtils.showLontMsg(MainActivity.this, "密码不能小于四位");

                }else
                {
                    new Thread() {
                        public void run() {
                          boolean aa=  userDao.longin(editTextusername.getText().toString(),editTextpassword.getText().toString());
                          if(aa==true){

                              Intent intent=new Intent(MainActivity.this,MainActivity2.class);
                              startActivity(intent);

                          }else{
                              Looper.prepare();
                             CommonUtils.showDlgMsg(MainActivity.this, "账号密码不正确");
                             Looper.loop();
                          }

                        }
                    }.start();
                }
            }



        });

    }

以下是注册界面

 

 注册界面的xlm文件  这个界面比较简单就不介绍了

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity3">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:layout_marginTop="20dp"
        android:layout_gravity="center"
        android:gravity="center"
        >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/jxlkjlog" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="@string/welcome"
            android:textColor="#000000"
            android:textSize="20.5sp"
            android:textStyle="bold" />



    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_marginStart="50dp"
        android:layout_marginTop="200dp"
        android:layout_marginEnd="50dp"
        android:layout_margin="5dp"
        >

        <TextView
            android:id="@+id/text_username"
            android:layout_width="wrap_content"
            android:layout_height=&#
  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值