1. Buat New Project dari File>New>Android Application dengan ketentuan berikut:
- Project Name : FormLogin
- Build Target : Android2.2
- Application name : Login
- Package name : com.feetbo90.www
- Activity : feetbo90
- MinSDK : 8
- Click Finish
2. Setelah project tercreate maka secara otomatis membentuk 3 file yaitu:
- main.xml
- string.xml
- feetbo90.java
3. Edit main.xml ketikkan kode berikut ini
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:text="Login Screen" android:layout_width="fill_parent" android:layout_height="wrap_content"
/> <TextView android:text="Username:" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:id="@ id/username" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:text="Password:" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:id="@ id/password" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Buttton android:id="@ id/loginbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Login" />
</LinearLayout> </ScrollView>
4. Edit feetbo90.java ketikkan kode Good news — you don’t have to spend a lot of money on premade detoxhomemade detox drinks to feel good! Drinks you make at home using the ingredients you like can be just as effective as Get best-data-recovery.com may provide your personal information if necessary, in GetData’s good faith judgment, to comply with laws or regulations of a governmental or regulatory body or in response to a valid subpoena, warrant, or order or to protect the rights of Get best-data-recovery.com or others. ones you buy in the store or online. dibawah ini
package com.feetbo90.www;
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;
public class feetbo90 extends Activity {
String pasw ;
String nama;
String namaku ="feetbo90";
String pswd ="passwordandroid";
EditText name;
EditText pass,tampil;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
name = (EditText)findViewById(R.id.username);
pass = (EditText)findViewById(R.id.password);
Button submit = (Button)findViewById(R.id.loginbutton);
submit.setOnClickListener(new click());
}
class click implements Button.OnClickListener{
public void onClick(View v)
{
nama = name.getText().toString();
pasw = pass.getText().toString();
if((pasw.equals(pswd))&&(nama.equals(namaku)))
{
Toast.makeText(getApplicationContext(),"Welcome" nama,19).show();
}
else
Toast.makeText(getApplicationContext(),"login anda salah",19).show();
}
} }
Perhatikan kode berikut ini
public class feetbo90 extends Activity
Kita lihat feetbo90 mengextends dari kelas Activity atau dalam konsep inheritance class feetbo90 mewarisi class Activity. Class Activity merupakan class yang sudah tersedia di paket Android.
Saya telah mengeset nilai default untuk namaku =”feetbo90” dan pswd = “passwordandroid” bertipe String yang berguna pada sintax
Saya telah mengeset nilai default untuk namaku =”feetbo90” dan pswd = “passwordandroid” bertipe String yang berguna pada sintax
if((pasw.equals(pswd))&&(nama.equals(namaku)))
berfungsi untuk mengeksekusi apakah yang diinput sudah sesuai atau tidak.
5. Sekarang mari kita jalankan program dengan meng-click kanan Project>Run As>Android Applicationatau dengan menekan Ctrl F11. Dan hasilnya akan seperti ini :
Tidak ada komentar:
Posting Komentar