Tampilkan postingan dengan label Java Programming. Tampilkan semua postingan
Tampilkan postingan dengan label Java Programming. Tampilkan semua postingan

Kamis, 10 Mei 2012

Create A Simple Animation For HP Symbian



Creating a Qt Quick Application

Note: To complete this tutorial, you must have Qt 4.7 or later installed.
This tutorial uses basic elements and illustrates basic concepts of Qt Quick.
This tutorial describes how to use the Qt Creator to implement the states and transitions example application. The example application displays a Qt logo that moves between three rectangles on the page when you click them.
"States and transitions example"

Creating the Project

  1. Select File > New File or Project > Qt Quick Project > Qt Quick UI > Choose.
  2. Follow the instructions of the wizard to create a project called Transitions.
  3. Press Ctrl+R to run the application in the QML Viewer.
Qt Creator generates a default QML file that you can modify to create the main view of the application.
"Transitions project in Edit mode"

Creating the Main View

The main view of the application displays a Qt logo in the top left corner of the screen and two empty rectangles.
To use the states.png image in your application, you must copy it to the project directory from the examples directory in the Qt installation directory. For example: C:\QtSDK\Examples\4.7\declarative\animation\states. The image appears in the Resources pane. You can also use any other image or a QML element, instead.
  1. In the Projects view, double-click the main .qml file (Transitions.qml) to open it in the code editor.
  2. Click Design to open the file in Qt Quick Designer.
    "Transitions project in Design Mode"
  3. In the Navigator pane, select Text and press Delete to delete it.
  4. Select Rectangle to edit its properties.
    "Page properties"
    1. In the Id field, enter page, to be able to reference the rectangle from other places.
    2. In the Colors tab, Rectangle field, set the color to #343434.
  5. In the Library view, Resources tab, select states.png and drag and drop it to the canvas.
    "Image properties"
    1. In the Id field, enter icon.
    2. In the Position field, set X to 10 and Y to 20.
  6. In the Library view, Items tab, select Rectangle, drag and drop it to the canvas, and edit its properties.
    "Rectangle properties"
    1. In the Id field, enter topLeftRect.
    2. In the Size field, set W and H to 64, for the rectangle size to match the image size.
    3. In the Colors tab, Rectangle field, click the  button to make the rectangle transparent.
    4. In the Border field, set the border color to #808080.
    5. In the Rectangle tab, Border field, set the border width to 1.
      Note: If the Border field does not appear after you set the border color, try setting the border color to solid by clicking the  button.
    6. In the Radius field, select 6 to create rounded corners for the rectangle.
    7. Click Layout, and then click the top and left anchor buttons to anchor the rectangle to the top left corner of the page.
      "Layout tab"
    8. In the Margin field, select 20 for the top anchor and 10 for the left anchor.
  7. In the Navigator pane, drag and drop the Mouse Area element from page to topLeftRect to make it apply only to the rectangle and not to the whole page.
  8. Edit Mouse Area properties:
    1. Click Layout, and then click the  button to anchor the mouse area to the rectangle.
    2. In the code editor, edit the pointer to the clicked expression in the mouse area element, as illustrated by the following code snippet:
       MouseArea {
           anchors.fill: parent
           onClicked: page.state = ''
       }
      The expression sets the state to the base state and returns the image to its initial position.
  9. In the Navigator pane, copy topLeftRect (by pressing Ctrl+C) and paste it to the canvas twice (by pressing Ctrl+V). Qt Creator renames the new instances of the element topLeftRect1 and topLeftRect2.
  10. Select topLeftRect1 and edit its properties:
    1. In the Id field, enter middleRightRect.
    2. In Layout, select the right and vertical center anchor buttons to anchor the rectangle to the middle right margin of the screen.
    3. In the Margin field, select 10 for the right anchor and 0 for the vertical center anchor.
    4. In the code editor,add a pointer to a clicked expression to the mouse area element. The following expression sets the state to State1:
      onClicked: page.state = 'State1'
      You will create State1 later.
  11. Select topLeftRect2 and edit its properties:
    1. In the Id field, enter bottomLeftRect.
    2. In Layout, select the bottom and left anchor buttons to anchor the rectangle to the bottom left margin of the screen.
    3. In the Margin field, select 20 for the bottom anchor and 10 for the left anchor.
    4. In the code editor, add a pointer to a clicked expression to the mouse area element. The following expression sets the state to State2:
      onClicked: page.state = 'State2'
      You will create State2 later.
  12. Press Ctrl+S to save the changes.
  13. Press Ctrl+R to run the application in the QML Viewer.
"States and transitions example"
You should see the Qt logo in the top left rectangle, and two additional rectangles in the center right and bottom left of the screen.
You can now create additional states to add views to the application.

Adding Views

In the .qml file, you already created pointers to two additional states: State1 and State2. To create the states:
  1. Click the empty slot in the States pane to create State1.
  2. Click the empty slot in the States pane to create State2.
  3. In the code editor, bind the position of the Qt logo to the rectangle to make sure that the logo is displayed within the rectangle when the view is scaled on different sizes of screens.
Set expressions for the x and y properties, as illustrated by the following code snippet:
  1.  states: [
         State {
             name: "State1"
    
             PropertyChanges {
                 target: icon
                 x: middleRightRect.x
                 y: middleRightRect.y
             }
         },
         State {
             name: "State2"
    
             PropertyChanges {
                 target: icon
                 x: bottomLeftRect.x
                 y: bottomLeftRect.y
             }
         }
     ]
    "States"
Note: When you set the expressions, drag and drop is disabled for the icon in Qt Quick Designer.
Press Ctrl+R to run the application in the QML Viewer.

Click the rectangles to move the Qt logo from one rectangle to another.

Adding Animation to the View

Add transitions to define how the properties change when the Qt logo moves between states. The transitions apply animations to the Qt logo. For example, the Qt logo bounces back when it moves to the middleRightRect and eases into bottomLeftRect. Add the transitions in the code editor.
  1. In the code editor, add the following code to specify that when moving to State1, the x and y coordinates of the Qt logo change linearly over a duration of 1 second:
     transitions: [
         Transition {
             from: "*"; to: "State1"
             NumberAnimation {
                 properties: "x,y";
                 duration: 1000
             }
         },
  2. You can use the Qt Quick toolbar for animation to change the easing curve type from linear to OutBounce:
    1. Click NumberAnimation in the code editor to display the  icon, and then click the icon to open the toolbar:
      "Qt Quick toolbar for animation"
    2. In the Easing field, select Bounce.
    3. In the Subtype field, select Out.
  3. Add the following code to specify that when moving to State2, the x and y coordinates of the Qt logo change over a duration of 2 seconds, and an InOutQuad easing function is used:
     Transition {
         from: "*"; to: "State2"
         NumberAnimation {
             properties: "x,y";
             easing.type: Easing.InOutQuad;
             duration: 2000
         }
     },
  4. Add the following code to specify that for any other state changes, the x and y coordinates of the Qt logo change linearly over a duration of 200 milliseconds:
     Transition {
         NumberAnimation {
             properties: "x,y";
             duration: 200
         }
     }
     ]

Press Ctrl+R to run the application in the QML Viewer.
Click the rectangles to view the animated transitions.



I copied this tutorial from : http://doc.qt.nokia.com/qtcreator-2.1/creator-qml-application.html for the sake of my learning. thanks before
Read More..

Cara Membuat Program Hp java

Membuat Program HP JAVA

J2ME sendiri adalah teknologi dari Java programming language yang di khususkan untuk perangkat mobile seperti Handphone, Pocket PC dan apa lagi yah. Pokoknya buat perangkat kecil yang sering dibawa kemana-mana
itu lho. J2ME sebenarnya sama dengan pemrograman menggunakan java sendiri, hanya saja dalam J2ME ada beberapa fungsionalitas yang ditambah dan dikurangi dan di sesuaikan untuk pemrograman perangkat mobile.
Tentunya untuk bisa membuat game di HP kita harus sudah biasa dulu menggunakan pemrograman dengan java, disini saya tidak akan mengulas bahasa pemrograman java -mungkin lain kali dalam postingan
yang berbeda- saya mengharapkan anda sudah memiliki pengetahuan java sebelumnya. Disini saya hanya akan memberikan pengetahuan mengenai alat yang digunakan dalam membuat program java di HP dan konsepnya.

Untuk alatnya saya menggunakan IDE(Integrated Development Environment) NetBeans versi 6 yang bisa di download gratis di sini,
pilih NetBeans yang sudah termasuk Mobility Pack. Agar kita bisa
langusng menulis kode program tanpa harus menginstal macem-macem lagi.

Setelah anda menginstall IDE NetBeans, segera jalankan NetBeans nya. Untuk membuat projek baru pilih File-New Project. Nanti akan muncul seperti gambar di bawah.




Pilih MIDP Application dan tekan Next. Selanjutnya anda akan di bawa ke layer Name and Location seperti di bawah ini.


Input Project Name yang sesuai dengan nama project anda dan hilangkan centang di Create Hello Midlet. Tekan Next



Ini adalah layar untuk menentukan target perangkat yang akan anda buat aplikasinya. Pada baris Emulator Platform adalah pilihan emulator yang anda Install di computer anda, untuk saat
ini anda hanya menginstall emulator bawaan dari NetBeans anda. Setelah
anda merasa perlu menginstall emulator platform untuk spesifik dari
vendor lain seperti Nokia, Sony Ericsson dan Motorola anda dapat
mengubahnya disini.

Device adalah perangkat emulator atau HP yang nantinya akan anda jalankan di
computer anda, dalam menjalankan program yang akan anda buat. Apabila
nantinya anda menginstal emulator platform dari vendor lain anda akan
bisa menggunakan HP spesifik dari vendor tersebut.

Device Configuration dan Profile adalah spesifik kemampuan dari paket perangkat yang akan anda jadikan
target aplikasi anda, sebagai contoh saya punya HP K608 itu mempunyai
spesifikasi CLDC 1.1 dan MIDP 2.0 artinya HP saya bisa menjalankan
program dengan paket yang ada di CLDC 1.1 dan MIDP 2.0. Untuk lebih
lanjut mengenai perangkat yang anda jadikat target riset lah dahulu
dengan melihat spesifikasi HP atau perangkat target anda.

Untuk
mempermudah anda mengerti, cukup bayangkan HP lama adalah MIDP 1.0
seperti nokia 6015 dan nokia yang gede dengan slidenya yang saya lupa
apa mereknya dan HP lama lainnya. MIDP 2.0 HP baru seperti nokia N70,
N73, SE K600, SEW800 dan lain lain. Karena MIDP 2.0 lebih banyak ada
baiknya anda pilih MIDP 2.0 dan CLDC 1.1 untuk aplikasi kita kali ini.

Pilih Next dan langsung pilih Finish. Siap siap!

Sebenarnya
dalam NetBeans ini anda dapat membuat aplikasi HP dengan Visual MIDlet
yang ada dalam NetBeans ini, tetapi untuk lebih memahami secara
mendalam konsep pembuatan aplikasi dalam J2ME disini saya tidak akan
memakai Visual MIDlet.

Konsep program J2ME adalah sebagai
berikut. Dalam J2ME kita harus akan membuat main class turunan dari
class MIDlet, main class turunan dari MIDlet tersebut yag nantinya akan
dipanggil pertama kali saat applikasi kita berjalan di HP, dalam main
class tersebut juga ada 3 method yang nantinya berfungsi sebagai
trigger even dari HP kita. Seperti:

starApp(), method yang dipanggil apabila aplikasi kita pertama kali jalan.
pauseApp(), method yang dipanggil apabila pengguna hp mempause aplikasi kita.
destroyApp(), method yang dipanggil apabila pengguna hp menutup aplikasi kita.

Kita
mulai dengan membuat classMIDlet baru untuk project anda. Klik kanan
para project anda di project explore dan pilih new-MIDlet, namakan
class baru itu dengan nama MIDletPertama. Kode terakhir file MIDlet
anda terlihat seperti di bawah ini.



Untuk pertama kali kita akan menampilkan “Hello J2ME World” pada layar HP. Ada dua jenis tampilan dalam MIDlet,

Low Level menggunakan class Canvas

High Level menggunakan Form

Disini kita akan menggunakan form untuk mempermudah anda mengerti pembentukan tampilan di MIDlet.
Tutorial j2me
Perhatikan
kode di atas, frPertama adalah object Form yang akan kita tampilkan di
layer, kita memberi judulForm tersebut dengan “Judul”. Lalu method
append adalah method untuk menambahkan Item pada Form, Item yang ingin
saya tambahkan adalah String “Hello J2ME World”. Statement Display
adalah statement untuk menampilkan object frPertama kedalam layer.

Pilih F11 untuk build project dan F6 untuk run project.

Pilih
midlet yang ingin dijalankan dan tekan launch di emulator, selanjutnya
emulator anda akan menampilkan Form yang anda buat, seperti di bawah.



Selamat, program anda sudah berjalan baik di emulator, bagaimana caranya menjalankan di HP sesungguhnya?

Masuk kedalam folder project NetBeans anda, buka folder dist



Transfer file jar program anda ke HP anda melaluli Bluetooth, infra merah atau kabel data





From : http://stmikbandungbali.ac.id/index.php?option=com_content&view=article&id=192:tutorial-membuat-program-java-j2me-di-hp-&catid=27:java&Itemid=87
Read More..