6/18/09

Configuring EclipseME and Eclipse


This document provides instructions on how to configure EclipseME and Eclipse for J2ME development.

  1. Import the Device Definitions
  2. Change Eclipse's Debug Settings
  3. Configure ProGuard (Optional)
  4. Configure OTA options (Optional)

1. Import the Device Definitions

In order to use EclipseME, you must configure at least one Device Definition. In order to do this, perform the following steps:

  1. Select the Preferences menu item from Eclipse's Window menu.

  2. Expand the J2ME item in the pane to the left and click on Device Management.
    screenshot

  3. Select Import...

  4. In the resulting dialog, select the root directory to be searched to find known devices definitions.

    screenshot

    As you leave the search directory text field or select the Refresh button, EclipseME will begin looking for devices in the specified directory and all subdirectories. As of version 1.5.0 of EclipseME, it is no longer necessary to pick the "perfect" directory in order to have devices imported, as EclipseME should be able to locate them if they reside anywhere within the specified directory. EclipseME will display the devices that are found as they are found. If you wish to stop the search at any time, select the Cancel button.

    After the search has completed, use the checkboxes to select the device definitions to be imported. Only devices that have been imported into your configuration may be used by project definitions and for launching. Finally, choose Finish to complete the import process.

    If EclipseME fails to locate a device definition that you expected would be found, it may be that EclipseME does not support it for the time being. In this case, please feel free to submit an RFE to ask for support for this WTK to be added. See here for how to do this.

  5. When you have successfully completed adding the device, you should see the imported devices in the device management preferences.

    screenshot

    Save the definitions by selecting Finish.

2. Change Eclipse's Debug Settings

Because of some quirks in the wireless toolkits, Sun's in particular, if you are going to debug your MIDlet using Eclipse, you must change several of the default debug settings. To do this:

  1. Select the Preferences menu item from Eclipse's Window menu.

  2. Expand the Java item in the left pane and click on the Debug entry.

  3. Ensure that both Suspend execution on uncaught exceptions and Suspend execution on compilation errors near the top of the dialog are NOT checked.

  4. Increase the Debugger timeout near the bottom of the dialog to at least 15000 ms.

  5. The resulting settings should look something like this:
    screenshot

If you do not make these changes you will get errors when you try to run your MIDlet.

3. Configure ProGuard (Optional)

If you will be using ProGuard to produce obfuscated packages, you will need to configure it into the plug-in. To do this:

  1. Select the Preferences menu item from Eclipse's Window menu.

  2. Expand the J2ME and the Packaging items in the left pane and click on the Obfuscation entry.

  3. Configure the ProGuard Root Directory near the top of the dialog.

  4. Configure any other ProGuard-specific settings that you need. For more information on ProGuard, see the ProGuard SourceForge site.

    Important note for Microsoft Windows Users: By default, ProGuard assumes that you are using an operating system that can distinguish between two file names that differ only in their case (i.e. A.java and a.java are two different files. This is clearly not the case in Microsoft Windows. Windows users should be sure to specify the -dontusemixedcaseclassnames option to ProGuard. If you fail to do this, and if you have more than 26 classes in your project, ProGuard's default use of case-sensitive file names will cause classes to overwrite one another. For safety, beginning with release 0.9.0 of EclipseME, the -dontusemixedcaseclassnames option is included as one of the default arguments to ProGuard. UNIX users with projects with many classes may be able to achieve a small reduction in the final size of their JAR file by removing this option.

  5. The resulting settings should look something like this:
    screenshot

4. Configure EclipseME's Over The Air (OTA) options (Optional)

If you will be using EclipseME to debug your MIDlet in Over The Air (OTA) mode, you may want to adjust the OTA Preferences. To do this:

  1. Select the Preferences menu item from Eclipse's Window menu.

  2. Expand the J2ME item in the left pane and click on the Over The Air entry.

  3. The default settings look like this:
    screenshot

At this point, you are ready to use EclipseME to create MIDlet suites. Before you do so, however, we strongly recommend that you read the section on Best Practices.

Writing a Hello World Midlet(Eclipse)

Creating a "Hello word!" midlet using Bizu-Me


Create a new project by going to File-->New-->Project. Then choose J2ME Midlet Suite in the list and click the next button. Then, insert a name for your project in the Project. We will put Bizu-Me-Demo for this project.

Choose a device in from the combo box. We will stick to using the DefaultColorPhone for this project.

Right click on the Bizu-Me project, go to New-->Source folder and create a source folder. Name it src.

You should now have a project with the following hierarchy:


Next we need to set up the classpath and dependencies. Right click on Bizu-Me-Demo and select properties. If you checked out the Bizu-Me project in your eclipse, go to the Project's tab and add Bizu-Me.

If you don't have Bizu-Me project in your eclipse, you can either follow the Bizu-Me setup or download a jar'd version from the website and add it as an external jar.

Once the classpath has been set, right click on the Bizu-Me-Demo project source folder and choose "create a new class". Fill in the class name as Main, the SuperClass field as org.openbizu.me.MIDlet and a package name i.e "org.openbizu.demo".

When this is done, you should end up with the following code in your Main.java class;

public class Main extends MIDlet {


protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}

protected void pauseApp() {
// TODO Auto-generated method stub
}

protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
}

You will find out that there will be a red cross at the top indicating that there is an error. Add the following lines to the Main.java class you just created to fix this.

public Main() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
super();
}

Since you are extending the org.openbizu.me.MIDlet class, you need to infer the org.openbizu.me.MIDlet super class constructor which throws three exceptions.

Next, we need to create a panel and add it to the container. There are two types of panels;

  • simple panel.

  • composite panel.

You can only do custom drawing operations on a simple panel whereas if you use a composite panel, you can both attach components, commands and custom drawing operations onto the panel.

Since we are only going to display a "Hello world !" string, we will use a simple panel. Next create a new class, name it HelloPanel. You should end up with the following hierarchy:

To draw anything onto the panel, implement the paint method by adding the following lines to the paint method.

public class HelloPanel extends SimplePanel{

public void hideNotify() {
// TODO Auto-generated method stub
}

public void paint(Graphics g) {
g.setColor(0);
g.drawString("Hello word !", getWidth()/2 , ( getWidth() - Font.getDefaultFont().getHeight() )/ 2,
Graphics.HCENTER | Graphics.TOP );

}

public void showNotify() {
// TODO Auto-generated method stub

}
}

We first set the font colour to black and draw the "Hello world!" String in the middle of the screen.

Lastly, we need to create the HelloPanel in the Main class and add it to the container. The main class should look like this:

public class Main extends MIDlet {

private HelloPanel helloPanel;

public Main() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
super();
helloPanel = new HelloPanel();
getContainer().put(0, helloPanel);

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}

protected void pauseApp() {
// TODO Auto-generated method stub
}

protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
}

The getContainer() method creates a new container and the put method adds the HelloPanel to the container. To run the midlet, right click on the main method in the package explorer and choose run as emulated .


If you checked the Bizu-ME project's source code out and added it to this project's build path and you encounter a java.lang.NoClassDefFoundError similar to this one:

java.lang.NoClassDefFoundError: org/openbizu/demo/Main: org/openbizu/me/MIDlet
at com.sun.midp.midlet.MIDletState.createMIDlet(+29)
at com.sun.midp.midlet.Scheduler.schedule(+52)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+116)

right click on the Bizu-Me-demo project you just created and make sure you export the Bizu-ME project in the build path configuration.

If you don't see any error then you should be able to see the emulator running. Congratulations, you just created your first midlet using Bizu-Me. Piece of cake right?

Lập trình J2ME trên Eclipse


I.Giới thiệu Eclipse
Những ai đã từng lập trình Java trên Eclipse thường chỉ có một nhận xét: hài lòng. Thật vậy, công cụ mã nguồn mở được viết bằng Java của anh cả IBM là một công cụ phát triển phần mềm mạnh mẽ. Eclipse được phát triển theo mô hình nền (platform), tự nó không cung cấp các chức năng cho người dùng cuối mà chỉ cung cấp một kiến trúc mở để các plugin gắn vào nó làm việc đó. Chính vì vậy Eclipse giống như một hệ điều hành để chúng ta cài đặt các công cụ cần thiết cho quá trình phát triển ứng dụng. Nó làm hài lòng giới lập trình viên Java vì có khá nhiều plugin mã nguồn mở phục vụ công việc. Hơn nữa, nếu thích, bạn còn dễ dàng phát triển một plugin phục vụ mục đích của mình.


II. EclipseME
EclipseME là một Eclipse plugin dành riêng cho phát triển ứng dụng J2ME được phát triển bởi Craig Setera. EclipseME có đầy đủ các chức năng của một J2ME IDE như: tạo J2ME project, tạo MIDlet, soạn thảo file jad, chạy ứng dụng MIDlet… Điều đặc biệt hơn cả là EclipseME thừa hưởng các tính năng Java IDE tuyệt vời từ Eclipse.

III. Cài đặt
1. Download: Xem địa chỉ download miễn phí ở cuối bài viết.
2. Yêu cầu:
3. Cài đặt EclipseME:

Để cài đặt EclipseME, bạn chỉ cần giải nén file zip đến thư mục plugins của Eclipse. Ví dụ, nếu bạn đã cài Eclipse trên C:\eclipse, bạn sẽ cài EclipseME trên C:\eclipse\plugins. Khởi động lại Eclipse nếu nó đang chạy để EclipseME đuợc khởi động.

4. Cấu hình:


Text Box: Hình 1 - Cấu hình WTKEclipseME đòi hỏi cần phải cấu hình ít nhất một WTK cho nó. Để cấu hình WTK, bạn hãy thực hiện theo các bước sau đây:
- Khởi động Eclipse
- Vào menu Window -> Preferences. Mở rộng mục J2ME, chọn mục Platform Components. Màn hình xuất hiện như trên hình 1.
- Trong khung bên phải, kích chuột phải vào mục Wireless Toolkits, kích vào Add Wireless Toolkit.
- Cửa sổ hiện ra yêu cầu bạn chọn thư mục cài đặt WTK. Nhấn nút Browse và chọn thư mục WTK bạn đã cài đặt, ví dụ: C:\WTK1.0
- Nhấn Finish rồi nhấn OK. Quá trình cài đặt và cấu hình đã hoàn tất.

IV.Tạo và chạy ứng dụng
1. Tạo J2ME project
Để tạo một J2ME project, bạn hãy làm theo các bước sau đây:

- Vào menu File -> New -> Project

- Cửa sổ New Project hiện ra. Hãy mở rộng mục J2ME, chọn J2ME MIDlet Suite. Kích Next.

- Trong cửa sổ kế tiếp, hãy gõ tên project (ví dụ HelloWorld) và chọn thư mục chứa project (ví dụ C:\projects\J2ME). Kích Next.

- Bước kế tiếp nầy cho phép bạn chọn nền WTK mà bạn đã cấu hình. EclipseME cho phép cấu hình nhiều nền J2ME (WTK1.0, WTK2.1…) nên bạn cần phải chọn một nền J2ME bạn muốn, chẳng hạn: J2ME Wireless Toolkit 1.0.4 Platform. Kích Next.

- Cuối cùng, bạn có thể thêm các thư viện cần dùng, thêm thư mục chứa source v.v… Cũng có thể để mọi thứ theo mặc định. Kích Finish để kết thúc quá trình tạo J2ME project. Bây giờ bạn đã có một J2ME project hoàn chỉnh trong workspace sẳn sàng để thực hiện mọi cái bạn muốn với J2ME.

2. Tạo MIDlet
MIDlet là lớp chính của toàn bộ ứng dụng J2ME. Có thể so sánh nó như một lớp có hàm main của J2SE, một Servlet của J2EE hay một Applet của ứng dụng applet. Để tạo mới một MIDlet, bạn hãy thực hiện theo các bước sau đây:
- Trong khung Navigator, kích chuột phải trên J2ME project (theo ví dụ ở trên là HelloWorld).
- Trong popup menu hiện ra, chọn New -> Other.

- Mở rộng mục J2ME, chọn J2ME Midlet. Kích Next.

- Nhập tên gói chứa MIDlet trong mục package, ví dụ: edu.eclipseme.helloworld

- Nhập tên lớp MIDlet trong mục Name, ví dụ: HelloWorldMIDlet.

- Nhấn nút Finish để kết thúc quá trình tạo MIDlet. Bạn đã có một MIDlet với đầy đủ các phương thức chính (constructor, startApp, pauseApp, destroyApp) trong J2ME project của mình.
Sau đây là ví dụ về chương trình HelloWorldMIDlet. Chương trình của chúng ta sẽ vẽ một dòng chữ Hello World in đậm màu đỏ ở giữa màn hình điện thoại. Trước khi in dòng chữ, chương trình hiển thị một màn hình intro trong 30 giây với một hình ảnh dạng png làm logo. Bạn có thể chọn bất kỳ hình nào bạn muốn. Ở đây, chúng tôi chọn logo của JavaVietnam.org.

a)HelloCanvas.java: Lớp vẽ dòng chữ Hello World

package edu.eclipseme.helloworld;

import javax.microedition.lcdui.Canvas;

import javax.microedition.lcdui.Font;

import javax.microedition.lcdui.Graphics;
/**

* Canvas vẽ chuỗi HelloWorld

*/
public class HelloCanvas extends Canvas{

/**
* Bạn hãy vẽ những gì bạn muốn ở đây
*/

protected void paint(Graphics g) {
clearScreen(g);
paintHello(g);
}

//Xoá màn hình (bôi màu trắng).
private void clearScreen(Graphics g){
g.setColor(0xFFFFFF);
g.fillRect(0, 0, getWidth(), getHeight());
}



//Vẽ chuỗi Hello World

private void paintHello(Graphics g){
//Chuỗi cần vẽ
String hello = "Hello World";
//Màu cần vẽ (đỏ)
g.setColor(0xFF0000);
//Font cần vẽ
Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
g.setFont(font);

//Vị trí vẽ (giữa màn hình)

int x = (getWidth() - font.stringWidth(hello)) / 2;
int y = (getHeight() - font.getHeight()) / 2;

//Vẽ chuỗi
g.drawString(hello, x, y, Graphics.TOP | Graphics.LEFT);
}

}

b) IntroCanvas.java: Lớp hiển thị màn hình intro.
package edu.eclipseme.helloworld;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
/**
* Hiển thị màn hình intro
*/

public class IntroCanvas extends Canvas{
//Bạn có thể thay bằng logo bạn thích.
private static final String logoName = "javavietnam_logo.png";
private Display display;
private Displayable nextScreen;
private int timeout;
private Timer timer = new Timer();

public IntroCanvas(Display display, Displayable nextScreen, int timeout){
this.display = display;
this.nextScreen = nextScreen;
this.timeout = timeout;
}



/**
* Bắt đầu màn hình intro.
*/
public void startIntro(){
display.setCurrent(this);
}



/**
* Kết thúc màn hình intro
*/
public void endIntro(){
display.setCurrent(nextScreen);
}



protected void paint(Graphics g) {
try {
Image logo = Image.createImage(logoName);
g.drawImage(logo, 0, 0, Graphics.TOP | Graphics.LEFT);
}

catch (IOException e) {
g.drawString(“Logo Error”, 0, 0, Graphics.TOP | Graphics.LEFT);
}

}



/**
* Thiết lập bộ đếm thời gian.
*/

protected void showNotify() {
timer.schedule(new CountDown(), timeout);
}



/**
* Kết thúc intro nếu bất kỳ phím nào được nhấn.
*/

protected void keyPressed(int keyCode) {
endIntro();
}



/**
* Kết thúc intro nếu hết thời gian.
*/

private class CountDown extends TimerTask {
public void run() {
endIntro();
}

}

}

c) HelloWorldMIDlet.java: Lớp chính
package edu.eclipseme.helloworld;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;



/**
* Day la lop chinh cua ung dung thua ke tu lop MIDlet.
*/

public class HelloWorldMIDlet extends MIDlet {
private Display display;
private IntroCanvas introCanvas;
private HelloCanvas helloCanvas;

/**
* Phuong thuc thiet lap.
*/

public HelloWorldMIDlet() {
super();
}



/**
* Phuong thuc nay thuc nay se duoc goi boi KVM khi nguoi
* dung nhan phim Launch tren dien thoai di dong.
* @see javax.microedition.midlet.MIDlet#startApp()
*/
protected void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
helloCanvas = new HelloCanvas();
introCanvas = new IntroCanvas (display, helloCanvas, 30000);
introCanvas.startIntro();
}



protected void pauseApp() {

}



protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

}

}



3. Đóng gói
Để ứng dụng J2ME chạy được trên thiết bị thật, bạn cần phải đóng gói toàn bộ ứng dụng vào file jar và file jad.
Nếu bạn phát triển ứng dụng của mình trên chế độ command line thì đây quả là một công việc nhiều rắc rối. Với EclipseME, việc đóng gói trở nên rất dễ dàng. Bạn hãy thực hiện theo các bước sau đây:
- Kích chuột phải trên J2ME project của bạn.
- Trên menu hiện ra, chọn J2ME -> Create Package.
Hãy mở rộng mục deployed, bạn đã có file .jad và .jar cho ứng dụng của mình.

4. Chạy ứng dụng
Chạy một ứng dụng J2ME cũng đơn giản như việc chạy một ứng dụng Java khác trong Eclipse. Sau đây là các bước để chạy một ứng dụng J2ME:

- Vào menu Run -> Run

- Trong khung bên trái, chọn Wireless Toolkit Emulator

- Nhấn nút New.

- Bạn có thể chọn thêm các tuỳ chọn khác. Trong khung Excutable, chọn Midlet và nhấn nút Search để EclipseME tự tìm lớp MIDlet cho bạn. Nếu bạn chọn Over the Air, EclipseME sẽ thực thi file jad.


Text Box: Hình 2 - màn hình intro

Mọi ngườii có thể download EclipseME ở đây www.eclipseme.org
V. KẾT LUẬN


Trên đây chúng tôi đã giới thiệu các chức năng chính của EclipseME. Nếu bạn đã từng lập trình trên Eclipse, thì bạn chỉ cần biết chức năng và địa chỉ download của EclipseME là đủ. Ngược lại, nếu bạn chưa bao giờ dùng đến Eclipse, đây sẽ là một dịp để bạn làm quen với nó. Và chỉ cần một lần làm quen thôi, chúng tôi tin tưởng rằng bạn sẽ khó rời xa nó :-).

Lập trình cho Black Berry

Default Quote:
Originally Posted by BBSync View Post
Hi
Actually I am a newbie into Blackberry programming...I just want to know how to start programming for this!!!

And also can anyone please tell me how to open an example given in the SDK in JDE.Actually when I open it I dont get to see the .jdw file for the project...
I get to see all the .java files....

So I am not getting how to open......


Can anyone please help!!!


Regards
Amey
ADI
Hi,

You have 2 options. use BlackBerry JDK or NetBeans or Eclipse for building Midlets.

Here is my recipe for Midlets:

-You have to install NetBeans Mobility Pack.
-Then install BlackBerry JDK, then configure NetBeans to point to the BBJDK Simulator
-Then build your App (.jad and .jar)
-Create a Project in the BBJDK (change project property instead of CLDC to Midlet)
-Compile to generate the .cod file (also .alx for the BB Desktop Loader)
-Load the .cod with javaloader -usb load yourapp.cod (javaloader is in bin directory of the BBKD)

For BB Native Java

-Use BBJDK, self explained in the BB Developer Sites

I hope to give you a general map.

Regards!

6/16/09

Phân trang by S2DAO

SELECT * FROM (
SELECT ROWNUM AS S2DAO_ROWNUMBER, S2DAO_ORIGINAL_DATA.* FROM (
SELECT * FROM A
) S2DAO_ORIGINAL_DATA
) WHERE S2DAO_ROWNUMBER BETWEEN 1 AND 20 AND ROWNUM <= 20 ORDER BY S2DAO_ROWNUMBER