parent
c10fb88602
commit
d031cba09b
@ -1,70 +0,0 @@
|
||||
package com.example.hamburger;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.widget.EditText;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
import android.widget.Button;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.annotation.SuppressLint;
|
||||
import com.example.hamburger.dao.UserDao;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
//这个类主要用来进行,账号密码的验证,以及监听事件的编写。
|
||||
// 所以首先需要将一开始设计的输入文本框id name 和passwd获取。
|
||||
EditText name;//创建账号
|
||||
EditText passwd;//创建密码
|
||||
|
||||
private static final String TAG="mysql-party-MainActivity";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
}
|
||||
|
||||
public void login(View view){
|
||||
|
||||
EditText EditTextAccount = findViewById(R.id.name);
|
||||
EditText EditTextPassword = findViewById(R.id.passwd);
|
||||
|
||||
Button button = (Button) findViewById(R.id.button);
|
||||
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
UserDao userDao = new UserDao();
|
||||
int msg = userDao.login(EditTextAccount.getText().toString(),EditTextPassword.getText().toString());
|
||||
hand1.sendEmptyMessage(msg);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
public void reg(View view){
|
||||
startActivity(new Intent(getApplicationContext(),register.class));
|
||||
}
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
final Handler hand1 = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (msg.what == 0){
|
||||
Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_LONG).show();
|
||||
} else if (msg.what == 1) {
|
||||
Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_LONG).show();
|
||||
startActivity(new Intent(getApplicationContext(),MainActivity2.class));
|
||||
} else if (msg.what == 2){
|
||||
Toast.makeText(getApplicationContext(), "密码错误", Toast.LENGTH_LONG).show();
|
||||
} else if (msg.what == 3){
|
||||
Toast.makeText(getApplicationContext(), "账号不存在", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in new issue