lanjut ke tutorial ke dua, pada tutorial ke dua disini kita membuat class login java

login.java

package com.aplikasimotor;

import driver.Utils;
import driver.XMLParser;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

public class login extends Activity {
String nama,pass;
String otentikasi=””;
EditText edNama,edPass;
XMLParser parser = new XMLParser();

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

edNama=(EditText)findViewById(R.id.edUsername);
edPass=(EditText)findViewById(R.id.edPassword);

Button  btnReg=(Button)findViewById(R.id.iReg);
btnReg.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(login.this, registrasi.class);
startActivity(i);
}});

Button  btnBatal=(Button)findViewById(R.id.ibatal);
btnBatal.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
keluarYN();
}});

Button  btnLogin=(Button)findViewById(R.id.ilogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {

nama=edNama.getText().toString();
pass=edPass.getText().toString();

if(nama.equalsIgnoreCase(“”)){
isiNama();
}
else if(pass.equalsIgnoreCase(“”)){
isiPass();
}

else{
Utils ip=new Utils();
String myip=ip.getIP();
nama=nama.replaceAll(” “, “_”);
pass=pass.replaceAll(” “, “_”);
String URL = myip+”android/login.php?username=”+nama+”&password=”+pass+”&ket=ok”;
String xml =parser.getXmlFromUrl(URL);

if(xml.indexOf(“sukses”)>=0){
Intent i = new Intent(login.this, listmenu.class);
i.putExtra(“xml”, xml);//PGW02#ORD1412008#CST001#sukses
startActivity(i);
//finish();
}
else{
salah();
}
}}});
}
//——————————————————————————————-
public void isiNama(){
new AlertDialog.Builder(this)
.setTitle(“Silakan Isi Nama”)
.setMessage(“Maaf, Silakan isi Nama Anda terlebih dahulu….”)
.setNeutralButton(“Tutup”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}})
.show();
}

public void pesan(String ps){
new AlertDialog.Builder(this)
.setTitle(“Pesan”)
.setMessage(ps)
.setNeutralButton(“Tutup”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}})
.show();
}
//——————————————————————————————-
public void isiPass(){
new AlertDialog.Builder(this)
.setTitle(“Silakan Isi Pass”)
.setMessage(“Maaf, Silakan isi Pass Anda terlebih dahulu….”)
.setNeutralButton(“Tutup”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}})
.show();
}

public void isiKodeCustomer(){
new AlertDialog.Builder(this)
.setTitle(“Silakan Isi Kode Customer”)
.setMessage(“Maaf, Silakan isi Kode Customer terlebih dahulu….”)
.setNeutralButton(“Tutup”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}})
.show();
}
//——————————————————————————————-
public void salah(){
new AlertDialog.Builder(this)
.setTitle(“ontentikasi salah”)
.setMessage(“Maaf, username “+nama+” dan pass “+pass+” SALAH ! cek kembali dengan benar….”)
.setNeutralButton(“Tutup”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}})
.show();
}

//——————————————————————————————-
public void keluarYN(){
AlertDialog.Builder ad=new AlertDialog.Builder(login.this);
ad.setTitle(“Konfirmasi”);
ad.setMessage(“Apakah benar ingin keluar?”);

ad.setPositiveButton(“Yes”,new OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
finish();
}});

ad.setNegativeButton(“No”,new OnClickListener(){
public void onClick(DialogInterface arg0, int arg1) {
}});
ad.show();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}

}

Kemudian pada login.xml

<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background = “#000000″
android:orientation=”vertical”>

<TableLayout
android:layout_width = “wrap_content”
android:layout_height= “wrap_content”
android:orientation = “vertical”
>

</TableLayout>

<LinearLayout
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:layout_marginBottom=”10dp”
android:layout_marginLeft=”7dp”
android:layout_marginRight=”7dp”
android:layout_marginTop=”20dp”
android:background=”@drawable/hitam”
android:orientation=”vertical” >

<ScrollView
android:layout_marginBottom=”50dip”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”

>

<TableLayout
android:id=”@+id/TableLayout01″
android:layout_width = “wrap_content”
android:layout_height= “wrap_content”
android:orientation = “vertical”

>

<TableRow>
<TextView
android:text=””
android:textColor=”#ffffff”
android:textSize=”15dp”
android:layout_marginLeft=”60dp” />

</TableRow>

<TableRow>
<TextView
android:text=””
android:textColor=”#ffffff”
android:textSize=”15dp”
android:layout_marginLeft=”60dp” />

</TableRow>
<TableRow android:id=”@+id/TableRow00″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”>

<TextView
android:text=”Username ”
android:textColor=”#ffffff”
android:textSize=”15dp”
android:layout_marginLeft=”30dp” />

<EditText
android:id=”@+id/edUsername”
android:textColor=”#ffffff” />

</TableRow>
<TableRow android:id=”@+id/TableRow02″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”>

<TextView
android:text=”Password”
android:textColor=”#ffffff”
android:textSize=”15dp”
android:layout_marginLeft=”30dp” />

<EditText
android:id=”@+id/edPassword”
android:inputType=”textPassword”
android:textColor=”#ffffff” />

</TableRow>

<TableRow>
<TextView
android:text=””
android:textColor=”#ffffff”
android:textSize=”15dp”
android:layout_marginLeft=”30dp” />

</TableRow>
<TableRow android:id=”@+id/TableRow02″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”>

<Button
android:id=”@+id/ilogin”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginLeft=”50dp”
android:text=”Login”
android:textColor=”#ffffff” />

<Button
android:id=”@+id/ibatal”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginLeft=”50dp”
android:text=”Batal”
android:textColor=”#ffffff”
android:visibility=”visible” />

</TableRow>

<Button
android:id=”@+id/iReg”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginLeft=”50dp”
android:text=”Registrasi”
android:textColor=”#ffffff” />

</TableLayout>
</ScrollView>

</LinearLayout>
</LinearLayout>

tampilan di atas seperti gambar di bawah :

penjualan2jasa pembuatan program skripsi dan tugas akhir

× Konsultasi Sekarang