private RecordStore recordStore=null;
byte [] data=.....
try{
int id = recordStore.addRecord(data,0,data.length);
}catch(RecordStoreException rse){
}
where data will be recorded?
Example:
In Nokia6600, E:\System\Midlets\[1012...]\rms.db
E : Disk (Memory Card)
[1012...] : midlet number
You can explore your device with FExplorer and see that when u add a new record size of rms.db will increase.
Wednesday, February 28, 2007
Tuesday, February 27, 2007
Code : how to reach camera in j2me
import javax.microedition.media.*;
import javax.microedition.media.control.*;
player=Manager.createPlayer("capture://video");
player.realize();
videoControl=(VideoControl)(player.getControl("VideoControl"));
videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,
canvas);
player.start();
byte[] image = videoControl.getSnapshot(null);
Monday, February 26, 2007
Thursday, February 22, 2007
Installing and Executing j2me applications in real mobile phones
Every mobile phone dont support every API and Configuration!
Remembering this basic rule rescue you from errors like "File Manager Closed" "Wrong version".
You can see which device supports which API and configuration in J2mepolish website.
For example if you(like me) try to install a application which has CLDC 1.1 version it may not be installed in Nokia 6600 which supports CLDC 1.0.
How to install??
open file manager -->select jar file-->and installing...
Remembering this basic rule rescue you from errors like "File Manager Closed" "Wrong version".
You can see which device supports which API and configuration in J2mepolish website.
For example if you(like me) try to install a application which has CLDC 1.1 version it may not be installed in Nokia 6600 which supports CLDC 1.0.
How to install??
open file manager -->select jar file-->and installing...
Wednesday, February 21, 2007
next step
The codes below simply send data that user types to server and receive message from server which is echos of it.Next step doing a file browser, browsing a photo and sending it via HttpConnection.If you send byte you can send everything so i ll send image in this way.
Example Code:HttpConnection in J2ME #2
use SendDataViaHttp.java and HttpConnector.java together/**
*
* @author sezera.blogspot.com
* @version 0010
*/
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HttpConnector extends Thread{
private String url="http://localhost:8084/YourWebApp/YourServlet";
private String msg;
private SendDataViaHttp midlet;
/** Creates a new instance of HttpConnector */
public HttpConnector(SendDataViaHttp midlet,String msg) {
this.midlet =midlet;
this.msg = msg;
}
public synchronized void run(){
HttpConnection c = null;
InputStream is = null;
OutputStream os = null;
try{
c = (HttpConnection)Connector.open(url);
// Set the request method and headers
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-US");
os = c.openOutputStream();
os.write(msg.getBytes());
is = c.openInputStream();
int contentLength = (int)c.getLength();
if (contentLength == -1) contentLength = 255;
byte[] raw = new byte[contentLength];
int length = is.read(raw);
String response = new String(raw,0,length);
midlet.get_response(response);
os.close();
is.close();
c.close();
}
catch(IOException ioe){
ioe.printStackTrace();
}
}
}
Example Code:HttpConnection in J2ME #1
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
/**
*
* @author sezera.blogspot.com
* @version 0001
*/
public class SendDataViaHttp extends MIDlet implements CommandListener{
private Form sendForm;
public TextField sendTextField;
public TextField responseTextField;
private TextBox askUserTextBox;
private Command sendCommand;
private Command exitCommand;
private String msgString;
private String responseString;
public SendDataViaHttp(){
}
public void startApp() {
getDisplay().setCurrent(get_sendForm());
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public Display getDisplay()
{
return Display.getDisplay(this);
}
public Form get_sendForm()
{
if(sendForm == null){
sendForm = new Form(null,new Item[]{get_sendTextField(),get_responseTextField()});
sendForm.addCommand(get_sendCommand());
sendForm.addCommand(get_exitCommand());
sendForm.setCommandListener(this);
}
return sendForm;
}
public TextField get_sendTextField(){
if(sendTextField == null){
sendTextField = new TextField("Your Message",null,20,TextField.ANY);
}
return sendTextField;
}
public TextField get_responseTextField(){
if(responseTextField == null){
responseTextField = new TextField("Response From Server",null,20,TextField.ANY);
}
return responseTextField;
}
public Command get_sendCommand()
{
if(sendCommand == null){
sendCommand = new Command("Send",Command.OK,1);
}
return sendCommand;
}
public Command get_exitCommand()
{
if(exitCommand == null){
exitCommand = new Command("Exit",Command.EXIT,2);
}
return exitCommand;
}
public void commandAction(Command command,Displayable displayable){
if(displayable == sendForm){
if(command == sendCommand){
//send written data to JavaServlet via HttpConnection
msgString = new String(sendTextField.getString());
HttpConnector conn = new HttpConnector(this,msgString);
conn.start();
}else if(command == exitCommand){
//exit Midlet
exitMiddlet();
}
}else
{
getDisplay().setCurrent(get_sendForm());
}
}
public void exitMiddlet()
{
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
}
public void get_response(String response)
{
responseTextField.setString(response);
}
}
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
/**
*
* @author sezera.blogspot.com
* @version 0001
*/
public class SendDataViaHttp extends MIDlet implements CommandListener{
private Form sendForm;
public TextField sendTextField;
public TextField responseTextField;
private TextBox askUserTextBox;
private Command sendCommand;
private Command exitCommand;
private String msgString;
private String responseString;
public SendDataViaHttp(){
}
public void startApp() {
getDisplay().setCurrent(get_sendForm());
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public Display getDisplay()
{
return Display.getDisplay(this);
}
public Form get_sendForm()
{
if(sendForm == null){
sendForm = new Form(null,new Item[]{get_sendTextField(),get_responseTextField()});
sendForm.addCommand(get_sendCommand());
sendForm.addCommand(get_exitCommand());
sendForm.setCommandListener(this);
}
return sendForm;
}
public TextField get_sendTextField(){
if(sendTextField == null){
sendTextField = new TextField("Your Message",null,20,TextField.ANY);
}
return sendTextField;
}
public TextField get_responseTextField(){
if(responseTextField == null){
responseTextField = new TextField("Response From Server",null,20,TextField.ANY);
}
return responseTextField;
}
public Command get_sendCommand()
{
if(sendCommand == null){
sendCommand = new Command("Send",Command.OK,1);
}
return sendCommand;
}
public Command get_exitCommand()
{
if(exitCommand == null){
exitCommand = new Command("Exit",Command.EXIT,2);
}
return exitCommand;
}
public void commandAction(Command command,Displayable displayable){
if(displayable == sendForm){
if(command == sendCommand){
//send written data to JavaServlet via HttpConnection
msgString = new String(sendTextField.getString());
HttpConnector conn = new HttpConnector(this,msgString);
conn.start();
}else if(command == exitCommand){
//exit Midlet
exitMiddlet();
}
}else
{
getDisplay().setCurrent(get_sendForm());
}
}
public void exitMiddlet()
{
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
}
public void get_response(String response)
{
responseTextField.setString(response);
}
}
Deadlock problem in J2ME networking
Warning: To avoid potential deadlock, operations that may block, such asThe warning above says if you simply do a httpconnection in J2Me memory,you may cause a deadlock.So we should Java Threads to connect server and send/receive data.
networking, should be performed in a different thread than the
commandAction() handler.
How To Transfer Data Via HttpConnection
You can send data from your mobile phone via Http Connection.In our thesis we will use this method.Our j2me interface is:
javax.microedition.io
Interface HttpConnection
How to open a connection?
private HttpConnection c = null;
private InputStream is = null;
private OutputStream os = null;
private static String ="http://localhost:8084/YourWebApp/YourServlet/
8084:Default TomCat Port in NetBeans IDE
c = (HttpConnection)Connector.open(url);
// Set the request method and headers
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-US");
os = c.openOutputStream();
os.write(msg.getBytes());
os.close();
c.close();
Add try catch for bold area.
javax.microedition.io
Interface HttpConnection
How to open a connection?
private HttpConnection c = null;
private InputStream is = null;
private OutputStream os = null;
private static String ="http://localhost:8084/YourWebApp/YourServlet/
8084:Default TomCat Port in NetBeans IDE
c = (HttpConnection)Connector.open(url);
// Set the request method and headers
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-US");
os = c.openOutputStream();
os.write(msg.getBytes());
os.close();
c.close();
Add try catch for bold area.
Etiketler:
j2me,
java servlets,
thesis
Sunday, February 18, 2007
MIDLET
In MIDP, when you develop a program actually you develop a midlet.
As you see below our HelloPhone midlet extends from Midlet class and implements CommandListener.
Midlet : javax.microedition.midlet.MIDLET class, which contains main application management functions, is a interface between application management software(AMS) and MIDP application.Every MIDP application must extend MIDLET class
As you see below our HelloPhone midlet extends from Midlet class and implements CommandListener.
startApp() : When program starts it call this method but it maybe recalled again and again during program.
pauseApp() : Simply pauses midlet.When user wants to continue executing program midlet invokes startApp()
destroyApp(boolean unconditional) : Ends program and release sources.If boolean unconditional set to true middlet have to release sources immediately.But if it is set to false middlet can throw "MIDletStateChangeException" to continue executing.
Example Code : Hello World!
As you guess, our first mobile program is HelloWorld which simply say HelloWorld lol
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
*
* @author sezera.blogspot.com
* @version 0000
*/
public class HelloPhone extends MIDlet implements CommandListener{
private Form helloForm;
private Command okCommand;
private StringItem msgStringItem;
public void startApp() {
getDisplay().setCurrent(get_helloForm());
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command,Displayable displayable)
{
if(displayable == helloForm){
if(command == okCommand){
//exit Midlet
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
}
}
}
public Form get_helloForm()
{
if(helloForm == null){
helloForm = new Form(null,new Item[]{get_helloStringItem()});
helloForm.addCommand(get_okCommand());
helloForm.setCommandListener(this);
}
return helloForm;
}
public Display getDisplay()
{
return Display.getDisplay(this);
}
public StringItem get_helloStringItem() {
if (msgStringItem == null) {
msgStringItem = new StringItem(null,"Hello World!");
}
return msgStringItem;
}
public Command get_okCommand() {
if (okCommand == null) {
okCommand = new Command("Okey", Command.OK,1);
}
return okCommand;
}
}
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
*
* @author sezera.blogspot.com
* @version 0000
*/
public class HelloPhone extends MIDlet implements CommandListener{
private Form helloForm;
private Command okCommand;
private StringItem msgStringItem;
public void startApp() {
getDisplay().setCurrent(get_helloForm());
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command,Displayable displayable)
{
if(displayable == helloForm){
if(command == okCommand){
//exit Midlet
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
}
}
}
public Form get_helloForm()
{
if(helloForm == null){
helloForm = new Form(null,new Item[]{get_helloStringItem()});
helloForm.addCommand(get_okCommand());
helloForm.setCommandListener(this);
}
return helloForm;
}
public Display getDisplay()
{
return Display.getDisplay(this);
}
public StringItem get_helloStringItem() {
if (msgStringItem == null) {
msgStringItem = new StringItem(null,"Hello World!");
}
return msgStringItem;
}
public Command get_okCommand() {
if (okCommand == null) {
okCommand = new Command("Okey", Command.OK,1);
}
return okCommand;
}
}
MIDP
In the previous post, there is a word called MIDP in this figure.So what is MIDP?
* java.io
* java.lang
* java.util
* javax.microedition.io
* javax.microedition.lcdui
* javax.microedition.midlet
* javax.microedition.rms
Java packages belong to MIDP 2.0
* MIDP 1.0 packages
* javax.microedition.lcdui.game
* javax.microedition.media
* javax.microedition.media.control
* javax.microedition.pki
MIDP(Mobile Information Device Profile) :Is a widely-common java me library for CLDC devices.Java packages belong to MIDP 1.0
* java.io
* java.lang
* java.util
* javax.microedition.io
* javax.microedition.lcdui
* javax.microedition.midlet
* javax.microedition.rms
Java packages belong to MIDP 2.0
* MIDP 1.0 packages
* javax.microedition.lcdui.game
* javax.microedition.media
* javax.microedition.media.control
* javax.microedition.pki
J2ME
Think that you want to develop a java platform for mobile devices such as mobile phones,PDAs etc.How do you do it?You probably think simplifying J2SE and adding special attributes for mobile devices to it like Sun exactly did.Look at this platform.
JVM is java virtual machine as you know. KVM(first version is announced in javaOne conference,1999) is a JVM minimized and adopted for mobile phones and entry level PDAs as you see on image.CDC and CLDC are configurations and shows which devices will be used on this platform.
CDC (Connected Device Configuration) :High-end PDAs,TV set-top boxes,embedded devices
CLDC (Connected Limited Device Configuration) :Mobile phones and entry-level PDAs
Because we will use a mobile phone(old but useful nokia 6600) our platform configuration is CLDC so i ll examine this.
Java packages belong to CLDC:
JVM is java virtual machine as you know. KVM(first version is announced in javaOne conference,1999) is a JVM minimized and adopted for mobile phones and entry level PDAs as you see on image.CDC and CLDC are configurations and shows which devices will be used on this platform.
CDC (Connected Device Configuration) :High-end PDAs,TV set-top boxes,embedded devices
CLDC (Connected Limited Device Configuration) :Mobile phones and entry-level PDAs
Because we will use a mobile phone(old but useful nokia 6600) our platform configuration is CLDC so i ll examine this.
Java packages belong to CLDC:
- java.io
- java.lang
- java.lang.ref
- java.util
- javax.microediton.io
Tuesday, February 06, 2007
NetBeans IDE 5.5
I have to say that i found Java Community NetBeans IDE 5.5 amazing and we ll use this tool for doing thesis.Jakarta Tom Cat,Java Servlet,J2ME...we begin to work.Nowadays i m working on this IDE to transfer a photo image from a mobile phone to a pc program. So i am going to write about this and leaving image processing for a while.
here again
After a long time i begin to study my thesis again.Forgive me for delay:)Although nobody read this blog except me i need having some responsibility lol
Monday, December 25, 2006
how to find edges?
To find edges in a photo you can use a sobel filter.
float [] data = {-1,-1,-1,-1,8,-1,-1,-1,-1};//Sobel filter
Kernel kernel = new Kernel(3,3,data);
ConvolveOp cop = new ConvolveOp(kernel);
BufferedImage filteredImg = cop.filter(bufImg,dst);
filteredImg is a black-white colored image (edges are white,others are black).To detect an object i will use edge and color informations.
float [] data = {-1,-1,-1,-1,8,-1,-1,-1,-1};//Sobel filter
Kernel kernel = new Kernel(3,3,data);
ConvolveOp cop = new ConvolveOp(kernel);
BufferedImage filteredImg = cop.filter(bufImg,dst);
filteredImg is a black-white colored image (edges are white,others are black).To detect an object i will use edge and color informations.
Etiketler:
sobel filter,
thesis
Friday, December 22, 2006
how to read images in java easily?
Java Class javax.imageio.ImageIO has a static read() method so you can read images easily.
try{
File file = new File("C:\photo.jpg');
BufferedImage bufferedImg = ImageIO.read(file);
}
catch(IOException ioe)
{
System.exit(0);
}
You can easily manipulate BufferedImage instances.You can call setRGB(),getRGB() methods to set or get Red Green Blue parts in pixel color.
After read image to bufferedImg i need to get pixels so lets do it:
final int imwidth = bufImg.getWidth(null);
final int imheight = bufImg.getHeight(null);
for(int i=0; i < imheight;i++)
{
for(int j=0; j< imwidth;j++)
{
argb = getARGBs(j,i);
//do sth with Red Green Blue parts of a pixel color.
}
}
//Get Alpha Red Green Blue parts of a pixel color.
public int [] getARGBs(int x,int y)
{
int [] argbs = new int[4];
argbs[0] = (bufImg.getRGB(x,y) >> 24) & 0xff;//alpha
argbs[1] = (bufImg.getRGB(x,y) >> 16) & 0xff;//red
argbs[2]=(bufImg.getRGB(x,y) >> 8) & 0xff;//green
argbs[3] =(bufImg.getRGB(x,y)) & 0xff;//blue
return argbs;
}
try{
File file = new File("C:\photo.jpg');
BufferedImage bufferedImg = ImageIO.read(file);
}
catch(IOException ioe)
{
System.exit(0);
}
You can easily manipulate BufferedImage instances.You can call setRGB(),getRGB() methods to set or get Red Green Blue parts in pixel color.
After read image to bufferedImg i need to get pixels so lets do it:
final int imwidth = bufImg.getWidth(null);
final int imheight = bufImg.getHeight(null);
for(int i=0; i < imheight;i++)
{
for(int j=0; j< imwidth;j++)
{
argb = getARGBs(j,i);
//do sth with Red Green Blue parts of a pixel color.
}
}
//Get Alpha Red Green Blue parts of a pixel color.
public int [] getARGBs(int x,int y)
{
int [] argbs = new int[4];
argbs[0] = (bufImg.getRGB(x,y) >> 24) & 0xff;//alpha
argbs[1] = (bufImg.getRGB(x,y) >> 16) & 0xff;//red
argbs[2]=(bufImg.getRGB(x,y) >> 8) & 0xff;//green
argbs[3] =(bufImg.getRGB(x,y)) & 0xff;//blue
return argbs;
}
first move
The MathWorks Matlab Image Processing Toolbox is really useful for processing images.You can filter images easily with different filters and see results immediately.So i choose this toolbox.
The MathWorks Matlab : http://www.mathworks.com/
After practising in matlab, i will study java image processing.My first target is processing an image in java and detect and recognize significant objects in photo.So lets go:)
The MathWorks Matlab : http://www.mathworks.com/
After practising in matlab, i will study java image processing.My first target is processing an image in java and detect and recognize significant objects in photo.So lets go:)
graduate thesis
Nowadays i really have to work on my graduate thesis project.So,i hope it will cover my blog topics until i complete it.
key words:
image processing
artificial intelligence
j2me
key words:
image processing
artificial intelligence
j2me
Wednesday, September 27, 2006
First of all
First of all,we need answering the question what is really 'intelligence'?How can we say a system is a 'intelligent'?Because i like chess very much i want to give this example:
Let's think about a chess program which have 3 play modes:human vs human,computer vs human and computer vs computer.If computer play against us or against another computer sensibly can we call it 'intelligent'?Actually not.But if computer 'learns' some new tricks,variations from any source and develop itself on his 'own' then there stands an intelligent system.
For computer chess history look:
http://www.geocities.com/SiliconValley/Lab/7378/comphis.htm
One of computer chess championship:
http://www.cs.unimaas.nl/wccc2006/
Let's think about a chess program which have 3 play modes:human vs human,computer vs human and computer vs computer.If computer play against us or against another computer sensibly can we call it 'intelligent'?Actually not.But if computer 'learns' some new tricks,variations from any source and develop itself on his 'own' then there stands an intelligent system.
For computer chess history look:
http://www.geocities.com/SiliconValley/Lab/7378/comphis.htm
One of computer chess championship:
http://www.cs.unimaas.nl/wccc2006/
Etiketler:
artificial intelligence
Subscribe to:
Posts (Atom)