Bismillahirohmanirohim ...
MainActivity.Java
package com.example.login;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener {
Button masuk;
AlertDialog alert;
EditText password;
EditText user;
String isi_passwd, username;
Intent i=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
masuk=(Button) this.findViewById(R.id.button1);
masuk.setOnClickListener(this);
//edit text untuk username
user=(EditText)findViewById(R.id.editText1);
user.getText();
//edit text untuk password
password=(EditText)findViewById(R.id.editText2);
password.getText();
username="bela_yulianita@yahoo.com";
isi_passwd="12345";
}
public void onClick(View tombol_act){
//TODO Auto-generated method stub
if(tombol_act==masuk){
if(password.getText().toString().equals(isi_passwd) && user.getText().toString().equals(username)){
AlertDialog.Builder pesan=new AlertDialog.Builder(this);
pesan.setMessage("username dan password anda benar").setCancelable(false).setPositiveButton("OK",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
i=new Intent(MainActivity.this,ActivitySegitiga.class);
startActivity(i);
}
});
alert=pesan.create();
alert.show();
}else{
AlertDialog.Builder pesan=new AlertDialog.Builder(this);
pesan.setMessage("Username: " + user.getText() + "dan Password: "+password.getText()+"anda masih SALAH").setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
user.setText("");
password.setText("");
}
});
alert=pesan.create();
alert.show();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
MainActivity.Java
package com.example.login;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener {
Button masuk;
AlertDialog alert;
EditText password;
EditText user;
String isi_passwd, username;
Intent i=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
masuk=(Button) this.findViewById(R.id.button1);
masuk.setOnClickListener(this);
//edit text untuk username
user=(EditText)findViewById(R.id.editText1);
user.getText();
//edit text untuk password
password=(EditText)findViewById(R.id.editText2);
password.getText();
username="bela_yulianita@yahoo.com";
isi_passwd="12345";
}
public void onClick(View tombol_act){
//TODO Auto-generated method stub
if(tombol_act==masuk){
if(password.getText().toString().equals(isi_passwd) && user.getText().toString().equals(username)){
AlertDialog.Builder pesan=new AlertDialog.Builder(this);
pesan.setMessage("username dan password anda benar").setCancelable(false).setPositiveButton("OK",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
i=new Intent(MainActivity.this,ActivitySegitiga.class);
startActivity(i);
}
});
alert=pesan.create();
alert.show();
}else{
AlertDialog.Builder pesan=new AlertDialog.Builder(this);
pesan.setMessage("Username: " + user.getText() + "dan Password: "+password.getText()+"anda masih SALAH").setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
user.setText("");
password.setText("");
}
});
alert=pesan.create();
alert.show();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
ActivitySegitiga.Java
package com.example.login;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class ActivitySegitiga extends Activity {
private EditText txtAlas;
private EditText txtTinggi;
private EditText txtLuas;
private Button btnHitung;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_segitiga);
txtAlas=(EditText)findViewById(R.id.editText1);
txtTinggi=(EditText)findViewById(R.id.editText2);
txtLuas=(EditText)findViewById(R.id.editText3);
btnHitung=(Button)findViewById(R.id.button1);
}
public void hitungLuas(View view){
try{
int alas=
Integer.parseInt(txtAlas.getText().toString());
int tinggi=
Integer.parseInt(txtTinggi.getText().toString());
int luas=(alas*tinggi)/2;
txtLuas.setText(String.valueOf(luas));
}catch(Exception e){
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_segitiga, menu);
return true;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="18dp"
android:text="Username" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="66dp"
android:text="Password" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="14dp"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="17dp"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/editText2"
android:layout_marginRight="54dp"
android:layout_marginTop="34dp"
android:text="Login" />
</RelativeLayout>
activity_activity_segitiga.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ActivitySegitiga" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="25dp"
android:text="Alas" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="66dp"
android:text="Tinggi" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/button1"
android:layout_marginTop="45dp"
android:text="Luas" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignLeft="@+id/button1"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_alignRight="@+id/editText2"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginLeft="39dp"
android:layout_toRightOf="@+id/textView4"
android:onClick="hitungLuas"
android:text="Hitung" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/editText3"
android:layout_alignLeft="@+id/button1"
android:ems="10" />
</RelativeLayout>
utama.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="18dp"
android:text="Selamat Datang Admin" />
</LinearLayout>
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.login"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="3" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.login.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.login.ActivitySegitiga"
android:label="@string/title_activity_activity_segitiga" >
</activity>
</application>
</manifest>
0 komentar:
Posting Komentar