2024.3.21軟體工程日報

liuxuechao發表於2024-03-24

學習時間:2h

程式碼量:100

package com.example.text_five;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.text_five.dao.UserDao;
import com.example.text_five.entity.User;

/**
* function:註冊頁面
*/

public class register extends AppCompatActivity {
private static final String TAG = "mysql-party-MainActivity";

EditText userAccount = null;

EditText userName = null;

EditText userPhone = null;
EditText userClass = null;


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

userAccount = findViewById(R.id.e2);
userName = findViewById(R.id.e3);
userPhone = findViewById(R.id.e4);
userClass= findViewById(R.id.e5);
}

public void sure(View view) {

String userAccount1 = userAccount.getText().toString();
String userName1= userName.getText().toString();
String userPhone1= userPhone.getText().toString();
String userClass1= userClass.getText().toString();

User user = new User();

user.setUserAccount(userAccount1);
user.setUserName(userName1);
user.setUserPhone(userPhone1);
user.setUserClass(userClass1);


new Thread(){
@Override
public void run() {

UserDao userDao = new UserDao();

boolean flag = userDao.register(user);
if(flag){
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(register.this, "註冊成功", Toast.LENGTH_LONG).show();
startActivity(new Intent(register.this, MainActivity.class));
}
});
}

}


}.start();

}

}


相關文章