APLIKASI SUHU UDARA ANDROID MENGGUNAKAN ECLIPSE
Kali ini saya akan menampilkan langkah-langkah dalam membuat aplikasi suhu udara android dengan menggunakan software eclipse. Adapun sebagai berikut:
1) Buatlah project pada eclipse, kemudian buatlah design pada graphical layout, seperti ini:
2) setelah membuat design seperti diatas, activiy main xml akan otomotasi tampil source code seperti berikut:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/a1"
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" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="54dp"
android:text="@string/suhu" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignParentRight="true"
android:ems="10"
android:inputType="number" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/txt1"
android:layout_marginTop="26dp"
android:text="@string/st" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/cbox1"
android:ems="10"
android:inputType="number" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="16dp"
android:text="@string/cel" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/cbox1"
android:layout_below="@+id/cbox1"
android:text="@string/kl" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/cbox1"
android:layout_alignLeft="@+id/hasil"
android:text="@string/hsl" />
3) Kemudian, masukan source code seperti gambar berikut:
package com.rivafaridha.suhu;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.*;
import android.widget.*;
public class MainActivity extends Activity {
CheckBox Celsius;
CheckBox Farhenheit;
CheckBox Kelvin;
CheckBox Reamur;
Button buttonkonversi;
EditText Text1, Text2, Text3, Text4, Text5;
Double awal, satuan;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonkonversi = (Button) findViewById(R.id.button1);
Text1 = (EditText) findViewById(R.id.txt1);
Text2 = (EditText) findViewById(R.id.hasil);
Text3 = (EditText) findViewById(R.id.txtkelvin);
Text4 = (EditText) findViewById(R.id.txtreamur);
Text5 = (EditText) findViewById(R.id.txtfahrenheit);
}
public void klikhasil(View v){
if(Text1.getText().toString().equals("")){
Toast.makeText(getBaseContext(), "Masukkan suhu awal, default suhu awal = 0 jika tidak dimasukkan suhu awal", Toast.LENGTH_LONG).show();
awal = 0.0;
}else{
awal = Double.parseDouble(Text1.getText().toString());
}
Celsius = (CheckBox) findViewById(R.id.cbox1);
Farhenheit = (CheckBox) findViewById(R.id.cbox2);
Kelvin = (CheckBox) findViewById(R.id.cbox3);
Reamur = (CheckBox) findViewById(R.id.cbox4);
if(Celsius.isChecked()){
satuan = awal;
Text2.setText(""+satuan);
int bil2 = Integer.parseInt(Text1.getText().toString());
int kelvin = bil2 + 273;
Text3.setText(""+kelvin);
int bil3 = Integer.parseInt(Text1.getText().toString());
double reamur = (bil3 * 0.8);
Text4.setText(""+reamur);
int bil4 = Integer.parseInt(Text1.getText().toString());
double farhenheit = (bil4 * 1.8)+32;
Text5.setText(""+farhenheit);
}
if(Farhenheit.isChecked()){
satuan = awal;
Text5.setText(""+satuan);
int bil2 = Integer.parseInt(Text1.getText().toString());
int kelvin = (bil2-32) + 273;
Text3.setText(""+kelvin);
int bil3 = Integer.parseInt(Text1.getText().toString());
double reamur = (bil3 * 0.44444)-32;
Text4.setText(""+reamur);
int bil4 = Integer.parseInt(Text1.getText().toString());
double celcius = (bil4 * 0.55544)-32;
Text5.setText(""+celcius);
}
if(Kelvin.isChecked()){
satuan = awal;
Text3.setText(""+satuan);
int bil2 = Integer.parseInt(Text1.getText().toString());
int celcius = bil2 - 273;
Text3.setText(""+celcius);
int bil3 = Integer.parseInt(Text1.getText().toString());
double reamur = (bil3 * 0.8);
Text4.setText(""+reamur);
int bil4 = Integer.parseInt(Text1.getText().toString());
double farhenheit = (bil4 * 1.8)-273+32;
Text5.setText(""+farhenheit);
}
if(Reamur.isChecked()){
satuan = awal;
Text4.setText(""+satuan);
int bil2 = Integer.parseInt(Text1.getText().toString());
int kelvin = bil2 + 273;
Text3.setText(""+kelvin);
int bil3 = Integer.parseInt(Text1.getText().toString());
double celcius = (bil3 * 1.25);
Text4.setText(""+celcius);
int bil4 = Integer.parseInt(Text1.getText().toString());
double farhenheit = (bil4 * 2.25)+32;
Text5.setText(""+farhenheit);
}
}
@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;
}
}
4) Setelah itu cobalah untuk menjalankan aplikasi yang sudah selesai, akan keluar tampilan seperti ini dilayar komputer anda:
6) Saat kamu telah berhasil menjalankan aplikasi, maka tampilah gambar berikut:
Semoga bermanfaat dan membantu kamu dari apa yang sudah saya berikan, terimakasih, selamat mencoba.
Komentar
Posting Komentar