(BlackBerry)Aplikasi Luas Segitiga Sederhana

Assalammualaikum semua pendatang dan pencinta e-lab, kali ini kami membagikan aplkasi sederhana yang berbasis blackberry , ini aplikasi pertama dan yang paling utama dari helloworld , ini di kutip dari web mas agus , sedikit modifikasi.langsung kita mulai aja ya.

1. Buat project file-new- blackberry project.

2. next

3. Next

4. Finish

5. myapp

6. MyApp
MyApp merupakan main utama yang akan di eksekusi.

package mypackage;

import net.rim.device.api.ui.UiApplication;

/**
 * This class extends the UiApplication class, providing a
 * graphical user interface.
 */
public class MyApp extends UiApplication
{
    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */ 
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        MyApp theApp = new MyApp();       
        theApp.enterEventDispatcher();
    }
    

    /**
     * Creates a new MyApp object
     */
    public MyApp()
    {        
        // Push a screen onto the UI stack for rendering.
        pushScreen(new MyScreen());
    }    
}
<pre> 

6. Myscreen
MyScreen merupakan tempat untuk memberi tampilan GUI yang diinginkan

package mypackage;


import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class MyScreen extends MainScreen
{
    /**
     * Creates a new MyScreen object
     */
	
	//Pendeklerasian variabel alas dan tinggi.
	private BasicEditField alas;
	private BasicEditField tinggi;
	private BasicEditField Hasil;
    public MyScreen()
    {        
        // Set the displayed title of the screen       
        setTitle("Aplikasi Segitiga");
        
        //Menambahkan input alas 
        alas = new BasicEditField("Alas :",
        		"",5,BasicEditField.EDITABLE);
        add(alas);
        
        //Menambahkan input tinggi
        tinggi = new BasicEditField("Tinggi :"
        		,"",5,BasicEditField.EDITABLE|BasicEditField.FILTER_NUMERIC);
        add(tinggi);
        
        //menambahkan eksekusi button 
        ButtonField cetak = new ButtonField("Hitung Luas " 
        		,ButtonField.CONSUME_CLICK |ButtonField.FIELD_LEFT|BasicEditField.FILTER_NUMERIC);
        add(cetak);
        
        //proses pencetakan
        cetak.setChangeListener(new FieldChangeListener() {
			
			public void fieldChanged(Field field, int context) {
				// TODO Auto-generated method stub
				Hitungluas(); //method hitung luas
			}
		});
        //menambah input hasil dari proses dengan ReadOnly.
        Hasil=new BasicEditField("Hasil :","",100,BasicEditField.READONLY);
        add(Hasil);
    }
    //method proses Hitungluas
    private void Hitungluas(){
    	float Alas = Float.parseFloat(alas.getText());
    	float Tinggi = Float.parseFloat(tinggi.getText());
    	float hasil = (float) ((0.5*Alas)*Tinggi);
    	Hasil.setText(String.valueOf(hasil));
    }
    
}
<pre> 

7. Hasil tampilannya.
.

Good luck..

jangan pernah bosan untuk mencoba hal yang baru

Download projectnya di sini

Advertisements

Published by

jarcode

hello I am jarcode

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s