SHARE
TWEET

Latihan 9_MainActivity.java

adesuryadi_ Jun 18th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.tugas;
  2.  
  3. import android.content.Intent;
  4. import android.support.v7.app.AlertDialog;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.Toast;
  11.  
  12. public class MainActivity extends AppCompatActivity {
  13.  
  14.     EditText username, password;
  15.     Button btnLogin;
  16.  
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.activity_main);
  21.  
  22.         username = (EditText) findViewById(R.id.username);
  23.         password = (EditText) findViewById(R.id.password);
  24.         btnLogin = (Button)findViewById(R.id.login);
  25.     }
  26.  
  27.     public void masuk(View view) {
  28.         String usernameKey = username.getText().toString();
  29.         String passwordKey = password.getText().toString();
  30.  
  31.         if (usernameKey.equals("admin") && passwordKey.equals("admin")){
  32.             Toast.makeText(getApplicationContext(), "LOGIN SUKSES",
  33.                     Toast.LENGTH_SHORT).show();
  34.             Intent intent = new Intent(MainActivity.this, Menu.class);
  35.             MainActivity.this.startActivity(intent);
  36.             finish();
  37.         }else {
  38.             AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  39.             builder.setMessage("Username atau Password Anda salah!")
  40.                     .setNegativeButton("Retry", null).create().show();
  41.         }
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top