Senin, 06 Juli 2015

File Main Activity.java

package com.example.coba;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.content.Context;

public class MainActivity extends Activity implements SensorEventListener
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
magnetX = (TextView) findViewById(R.id.textView5);
magnetY = (TextView) findViewById(R.id.textView1);
magnetZ = (TextView) findViewById(R.id.textView3);

/* Use the LocationManager class to obtain GPS locations */
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener locListener = new MyLocationListener();
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);


mSensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE);
mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
mAccel = 0.00f;
mAccelCurrent = SensorManager.GRAVITY_EARTH;
mAccelLast = SensorManager.GRAVITY_EARTH;
}

SensorManager mSensorManager;
private float mAccel; // acceleration apart from gravity
private float mAccelCurrent; // current acceleration including gravity
private float mAccelLast; // last acceleration including gravity

TextView longitu;
TextView latitu;
TextView magnetX;
TextView magnetY;
TextView magnetZ;

/* Class My Location Listener */
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
double latitude = loc.getLatitude();
double longitude = loc.getLongitude();
longitu.setText(Double.toString(longitude));
latitu.setText(Double.toString(latitude));
Toast toast = Toast.makeText(getApplicationContext(),"Device has shaken.", Toast.LENGTH_SHORT);
toast.show();
}

@Override
public void onProviderDisabled(String provider)
{
Toast.makeText(getApplicationContext(), "GPS Disabled", Toast.LENGTH_SHORT).show();
}

@Override
public void onProviderEnabled(String provider)
{
Toast
.makeText(getApplicationContext(), "GPS Enabled", Toast.LENGTH_SHORT)
.show();
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}



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;
}

public void onAccuracyChanged(Sensor sensor, int accuracy)
{
// Ignoring this for now
}

public void onSensorChanged(SensorEvent se)
{
float x = se.values[0];
float y = se.values[1];
float z = se.values[2];
mAccelLast = mAccelCurrent;
mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z));
float delta = mAccelCurrent - mAccelLast;
mAccel = mAccel * 0.9f + delta; // perform low-cut filter
magnetX.setText(Float.toString(x));
magnetY.setText(Float.toString(y));
magnetZ.setText(Float.toString(z));
if (mAccel > 12)
{
Toast toast = Toast.makeText(getApplicationContext(),"Device has shaken.", Toast.LENGTH_SHORT);
toast.show();
}

}

protected void onPause()
{
// Unregister the listener
mSensorManager.unregisterListener(this);
super.onPause();
}

protected void onStop()
{
// Unregister the listener
mSensorManager.unregisterListener(this);
super.onStop();
}

protected void onResume()
{
super.onResume();
// Register magnetic sensor
mSensorManager.registerListener(this,mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
}

}




File activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mag_x"
    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/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="188dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textZ"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_below="@+id/textY"
        android:layout_marginLeft="49dp"
        android:layout_marginTop="29dp"
        android:text="Z"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textY"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/textZ"
        android:layout_below="@+id/textView2"
        android:layout_marginTop="28dp"
        android:text="Y"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textY"
        android:layout_alignRight="@+id/textView2"
        android:layout_marginRight="52dp"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textZ"
        android:layout_alignBottom="@+id/textZ"
        android:layout_alignLeft="@+id/textView1"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textY"
        android:layout_alignLeft="@+id/textZ"
        android:text="X"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignRight="@+id/textView1"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView5"
        android:layout_marginBottom="18dp"
        android:layout_toLeftOf="@+id/textView5"
        android:text="Acceleration"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView6"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        android:text="Longitude :"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView7"
        android:layout_below="@+id/textView7"
        android:layout_marginTop="28dp"
        android:text="Latitude :"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView8"
        android:layout_marginLeft="23dp"
        android:layout_toRightOf="@+id/textView7"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView8"
        android:layout_alignBottom="@+id/textView8"
        android:layout_alignLeft="@+id/textView9"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>




File AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.coba"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.coba.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>
    </application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

</manifest>

Posted by Unknown On 23.59 No comments READ FULL POST

Senin, 29 Juni 2015

File 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" >

    <EditText
        android:id="@+id/editpas"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editanda"
        android:layout_marginTop="19dp"
        android:layout_toRightOf="@+id/spas"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editanda"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editpas"
        android:layout_alignParentTop="true"
        android:layout_marginTop="40dp"
        android:ems="10" />

    <EditText
        android:id="@+id/editresult"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btnhitung"
        android:layout_alignRight="@+id/btnhitung"
        android:layout_below="@+id/btnhitung"
        android:layout_marginTop="37dp"
        android:ems="10" />

    <TextView
        android:id="@+id/spas"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/editpas"
        android:layout_alignBottom="@+id/editpas"
        android:layout_alignRight="@+id/sanda"
        android:text="Nama Pasangan" />

    <TextView
        android:id="@+id/sanda"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/editanda"
        android:layout_alignBottom="@+id/editanda"
        android:layout_alignParentLeft="true"
        android:text="Nama Anda" />

    <TextView
        android:id="@+id/sresult"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/editresult"
        android:layout_alignBottom="@+id/editresult"
        android:layout_alignParentLeft="true"
        android:text="Result" />

    <Button
        android:id="@+id/btnhitung"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:onClick="hitung"
        android:text="Proses" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/editresult"
        android:layout_marginLeft="14dp"
        android:layout_toRightOf="@+id/editresult"
        android:text="%" />

</RelativeLayout>



File MainActivity.java
package com.example.android_tugas1;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.ArrayList;

public class MainActivity extends Activity{

    private EditText editanda,editpas,editresult;
    private String sanda,spas,sresult;
    private Button btnhitung;

    @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editanda=(EditText) findViewById(R.id.editanda);
        editpas = (EditText) findViewById(R.id.editpas);
        btnhitung = (Button) findViewById(R.id.btnhitung);
        editresult = (EditText) findViewById(R.id.editresult);
    }
 
 


    /**

     * Method untuk Menghitung Luas Persegi panjang dipanggil pada saat button

     * Hitung Luas diklik

     *

     * @param view

     */

    public void hitung(View view) {
        String stranda = "";
        String strpas = "";
        try{
        stranda = editanda.getText().toString();
        strpas = editpas.getText().toString();
        char[] arrCharStr = stranda.toCharArray();
        char[] arrCharStr2 = strpas.toCharArray();
        }catch(Exception e){
         
        }
         //untuk mengambil masing2 karakter dari str ::
        //dengan cara merubah string tersebut menjadi array cahr
        char[] arrCharStr = stranda.toCharArray();
        char[] arrCharStr2 = strpas.toCharArray();
        //untuk konversi biner ke ASCII
        int sum_a=0;
        int sum_pas=0;
        for (char c : arrCharStr) {
            String biner = "0" + Integer.toBinaryString(c);
            int ASCII = Integer.parseInt(biner, 2);
            char karakter = (char) ASCII;
            System.out.println(biner + " :: " + ASCII + " :: " + karakter);
            sum_a = sum_a + ASCII;
        }
        System.out.println(sum_a + "");
        for (char c : arrCharStr2) {
            String biner = "0" + Integer.toBinaryString(c);
            int ASCII = Integer.parseInt(biner, 2);
            char karakter = (char) ASCII;
            System.out.println(biner + " :: " + ASCII + " :: " + karakter);
            sum_pas= sum_pas + ASCII;
        }
     
        System.out.println(sum_pas + "");
        int nilai_anda=sum_a%100;
        int nilai_pas=sum_pas%100;
        System.out.println(nilai_anda + "");
        System.out.println(nilai_pas + "");
        int selisih;
        if (nilai_anda > nilai_pas){
            selisih=nilai_anda - nilai_pas;
            System.out.println(selisih + "");
        }
        else{
            selisih=nilai_pas-nilai_anda;
            System.out.println(selisih + "");
        }
        int hasil = 100 - selisih;
        System.out.println(hasil + "% cocok");
        String x= String.valueOf(hasil);
        editresult.setText(x);
    }
}


Hasilnya seperti gambar dibawah ini
Posted by Unknown On 22.50 No comments READ FULL POST

Senin, 04 Mei 2015

Tampilan :



















Kode Pemograman


package Lab;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;


public class CaturMidlet extends MIDlet {
    private Display display;
    papancatur pantur;
 
    public void startApp() {
        if(display==null){
            pantur = new papancatur(this);
            display = Display.getDisplay(this);
        }
        display.setCurrent(pantur);
    }
 
    public void pauseApp() {
    }
 
    public void destroyApp(boolean unconditional) {
    }
 
    protected void Quit(){
        destroyApp(true);
        notifyDestroyed();
    }
    class papancatur extends Canvas implements CommandListener{
        private Command exitCommand = new Command("Exit", Command.EXIT, 0);
        private CaturMidlet persegi;
 
        public papancatur(CaturMidlet persegi){
            this.persegi = persegi;
            addCommand(exitCommand);
            setCommandListener(this);
        }
 
        protected void paint(Graphics g) {
            int width = getWidth();
            int height = getHeight()-61;
            g.setGrayScale(255);
            g.fillRect(0, 0, width-1, height-1);
          
            g.setColor(0, 0, 0); //pengaturan canvas warna hitam
          
            //untuk potongan diagonal kanan
            for (int baris = 0; baris < width; baris+=30) {
                for (int kolom = 330; kolom>= 30; kolom-=60) {
                    g.fillRect(baris+kolom, baris, 30, 30);
                }
            }
           
            //untuk potongan diagonal kiri
            for (int baris = 0; baris < width; baris+=30) {
                for (int kolom = 30; kolom <= 330; kolom+=60) {
                    g.fillRect(baris, baris+kolom, 30, 30);
                }
              
            }
          
 
        }
 
        public void commandAction(Command c, Displayable d) {
            if(c==exitCommand){
                persegi.Quit();
            }
        }
    }
}
Posted by Unknown On 14.49 No comments READ FULL POST

Sabtu, 11 April 2015

Menu Utama

















Pilihan menu

















Page 1 :

















Pilihan Menu Page 1 :


















Page 2 :

















Pilihan Menu Page 2 :

















Page 3 :

















Pilihan Menu Page 3 :


















Coding :

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author Lidia @ 11.04.2015
 */
public class Tugas1 extends MIDlet implements CommandListener{
    Display dis;
    Command exitCommand = new Command("Exit", Command.EXIT,1);
    Command page1Command = new Command("Page 1", Command.OK,1);
    Command page2Command = new Command("Page 2", Command.OK,1);
    Command page3Command = new Command("Page 3", Command.OK,1);
    Command homeCommand = new Command("Home", Command.OK,1);
   
    Form homeForm = null;
    Form page1Form = null;
    Form page2Form = null;
    Form page3Form = null;
   
    public Tugas1(){
        super();
        homeForm=new Form("Selamat Datang Di Polmed");
        homeForm.addCommand(exitCommand);
        homeForm.addCommand(page1Command);       
        homeForm.addCommand(page2Command);       
        homeForm.addCommand(page3Command);
        homeForm.setCommandListener(this);
        page1Form=new Form("Page 1");
        page1Form.addCommand(homeCommand);
        page1Form.addCommand(page2Command);
        page1Form.addCommand(page3Command);
        page1Form.addCommand(exitCommand);
        page1Form.setCommandListener(this);
        page2Form=new Form("Page 2");
        page2Form.addCommand(homeCommand);
        page2Form.addCommand(page1Command);
        page2Form.addCommand(page3Command);
        page2Form.addCommand(exitCommand);
        page2Form.setCommandListener(this);
        page3Form=new Form("Page 3");       
        page3Form.addCommand(homeCommand);
        page3Form.addCommand(page1Command);
        page3Form.addCommand(page2Command);
        page3Form.addCommand(exitCommand);
        page3Form.setCommandListener(this);
       
    }
    public void startApp() {
        if (dis==null){
            dis=Display.getDisplay(this);
        }
       
        dis.setCurrent(homeForm);
       
    }
   
    public void pauseApp() {
    }
   
    public void destroyApp(boolean unconditional) {
    }
   
   
    public void commandAction(Command c, Displayable d){
        if(c==exitCommand){
            destroyApp(true);
            notifyDestroyed(); //Exit
        }
        else if(c==page1Command){
            dis.setCurrent(page1Form);
        }
        else if(c==page2Command){
            dis.setCurrent(page2Form);
        }
        else if(c==page3Command){
            dis.setCurrent(page3Form);
        }
        else if(c==homeCommand){
            dis.setCurrent(homeForm);
        }
        }



Posted by Unknown On 23.09 No comments READ FULL POST

Categories

    Blogger news

    Blogroll

    About