Tuesday, June 24, 2008

Easy AJAX with jMaki Framework

If you are web application developer I think you know about Rich Internet Application, Web 2.0.
AJAX is way to bring you for purpose. You can use jMaki Framework. You are amazed.

Quick start Guides
Download Plugin Netbeans

Tuesday, June 17, 2008

Eclipse JVM Terminate on MAC OS

On MAC OS, after you change JDK HOME from JDK 1.5.0 to 1.6.0 when you run Eclipse system alert JVM Terminate will appear. 
The solution, modifier file info.plist in Eclipse HOME/Eclipse.app/contents

remove comment 
-vm/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Commands/java

It's easy.

Monday, June 9, 2008

Extract zip file with Java

File file = new File("c:/test.zip");
BufferedOutputStream dest = null;
BufferedInputStream is = null;
ZipEntry entry;
ZipFile zipfile = new ZipFile(file);
Enumeration e = zipfile.entries();
while (e.hasMoreElements()) {
entry = (ZipEntry) e.nextElement();
System.out.println("Extracting: " + entry);
is = new BufferedInputStream(zipfile.getInputStream(entry));
int count;
byte data[] = new byte[BUFFER];
String fileName = "c:/" + entry.getName();
File outFile = new File(fileName);
if (entry.isDirectory()) {
outFile.mkdirs();
System.out.println("Create Folder " + outFile);
} else {
FileOutputStream fos = new FileOutputStream(outFile);
dest = new BufferedOutputStream(fos, BUFFER);
while ((count = is.read(data, 0, BUFFER)) != -1){
dest.write(data, 0, count);
}
dest.flush();
dest.close();
is.close();
}
}

Friday, June 6, 2008

Flex vs Silverlight

เมื่อวานผมได้ไปงาน MSDN Sneak Peek มาครับ โดยตัวเรื่องจะเป็นการกล่าวถึง technology ที่ชื่อ Silverlight ของ Microsoft เป็นหลัก ผมเองก็สงสัยมานานแล้วกับ Technology ตัวนี้ ว่ามันจะมีอานุภาพมาเทียบเคียงกับ Flex ได้ไหม ผมก็ได้ concept คร่าวๆ จาก พี่… (จำชื่อไม่ได้นะคร้าบ ^ ^ ขออภัยมา ณ ที่นี่) ที่เป็น MVP และที่อยู่ของเขาก็อยู๋ที่ ThaiSharp.net ครับ ผมก็อยากหยิบยกประสบการณ์ของผมมาเปรียบเทียบความ “เหมือน” ที่แตกต่างพวกนี้กัน (อ่านเล่นๆ มีสาระนะครับ)

Round 1: XAML vs. MXML

คู่แรกที่เห็นได้ชัดที่สุดเลยคือ 2 ฟอร์แมตที่ใช้ในการจัด layout พร้อมทั้งกำหนด คุณลักษณะของทุก object ที่เป็น visual component โดย Microsoft ได้ศึกษามาเป็นอย่างดี โดยทำการปรับปรุงใน XAML สามารถทำงานได้บน Cross-application ในการพัฒนา web ของเขาเอง ได้แก่ Microsoft Expression Studio (คล้ายๆ กับ เหล่า CS ของ Adobe) และ VS 2008 (ซึ่งก็คือ Adobe Flex builder นั่นเอง) โดยในความเห็นของผม คิดว่า Microsoft จะอาศํยฐานนักพัฒนา .net ของตัวเองในการเรียนรู้ XAML เพียงนิดเดียว เพื่อที่จะสร้าง solution ขึ้นมาต่อกร กับ Adobe ยกนี้ให้ เสมอกัน

Round 2 : VS2008 vs. Flex Builder 3

แน่นอนว่าการพัฒนาอย่างมีประสิทธิภาพ ก็เหมือนการต่อเรือโดยใช้เครื่องมือชั้นดี (บวกกับทักษะของช่างเอง) VS2008 เป็นเครื่องมือที่ยืนยงคงกระพันมาราว เขาเหลียงซาน พร้อมด้วยการพัฒนาให้ “เหมาะสม” กับ developer ทั้งมวล ทำให้การปล่อยหมัดแต่ละครั้ง หนักหน่วงและมั่นคง แต่ทว่า Adobe Flex ดึงเอาจุดเด่นของชั้นเชิง Eclipse รุ่นพี่ออกมาพัฒนาต่อยอด แต่ทำให้สูญเสียข้อดีบางอย่างไปในการพัฒนาให้รับกับ Actionscript 3 อาจทำให้ นักวิจารณ์พูดกดดันเล็กน้อย หากแต่เพียงการพัฒนาให้มีลักษณะ ที่เป็นเอกลักษณ์ โดยการดึงความสามารถเฉพาะตัวของ Adobe Flex framework เข้าไป (Custom component, Data Binding) ทำให้เชิงที่ออกมานั้น ผมว่าทำเอา Microsoft เดาทางไม่ถูกเช่นกัน ยกนี้ผลัดกันกระทุ้ง เสมอ…

Round 3 : Flexibility & Performance

ยกนี้น่าสนใจมากๆ ครับ เพราะเหมือนการให้กรรมการนับแต้มกันจาก ข้อมูลที่แต่ละฝ่ายกล่าวอ้างกัน เรามาดูกันดีกว่า

Silverlight Flex
+ Better video compression (no lossless) - JPEG algorithm video compression
- No common component (like button, for now) + provide common component
- Tool still in beta version + Release full version 3
- .NET framework seems using more tool to complete a product + Flex seems to allow using only one technology to complete a product
+ In Thailand, developer love Microsoft .net framework (?) - look like actionscript is belonging to designer (very miss-understanding!)

ซึ่ง ก็ซํดกันไปเป็นช่วงๆ ครับ ในความเห็นของผม ผมขอสรุปว่า Microsoft กำลังกลับไปศึกษาเชิงมวยของ Flex กันยกใหญ่ เพราะเนื่องจากตัวนี้ยังไม่ เสถียร และเครื่องมือพัฒนาก็ยังไม่พร้อม ความหวังที่กำลังจะไปเทียบเคียงกับ Adobe Flex คงต้องรอในอีก 2 - 3 เดือนข้างหน้าครับ ในวันนี้ Microsoft พาขุนศึกออกมาประจันบาญ ซึ่ง Adobe ก็คงเตรียมกระบวนทัพใหม่รอต้อนรับอยู่เหมือนกัน


ที่มา http://webflex.wordpress.com/tag/adobe-flex/


Thursday, June 5, 2008

Convention in Macromedia Flex [Flex part II]

ก็ลองเขียนดูเล่นๆนา

มันก็จามีอยู่ 2 แบบอย่างที่บอก คือ เขียนเป็น mxml ซึ่ง ข้อดึของมัน ก็คือ สามารถลากแปะๆ ได้ เนื่องจาก flex builder มันมี tool ในการ สร้าง UI ให้ลากไปใช้งาน อีกส่วนหนึ่งก็ตือ เขียนเป็น ActionScript

หากลองเปรียบเทียบกับ jsp ให้เข้าใจง่ายหน่อย ก็อาจจะ คิดว่า MXML ก็เหมือนกับ HTML โดยหารเขียนจะเป็น และสามารถแทรกส่วนที่เป็น Script ลงไปได้

แล้วหากสร้างไฟล์ที่เป็น actionscript เลย ก้เหมือนกับ สร้าง servlet ที่เขียนเป็น java แล้วแทรก HTML ลงไปได้ แต่ว่า !!! ยังไม่ได้ลองสร้าง แบบนี้เลย เลยไม่รู้ว่าจาแทรก แบบ mxml ลงไปได้ป่าว


หลายคนอาจจะสงสัยว่า Flex ทำมาทำไม ทั้งๆที่มี Flash แล้ว (Flash ก็มี action script) เออ พูดตั่งนาน กูก็สงสัย

55+
แต่ว่า Flash จริงแล้วที่มันออกแบบมาเพื่อให้ใช้ต่างกัน Flex มันเป็นการเขียนแบบ MVC

แต่เวลา compile มันก็จาแปลงจาก MXML > ActionScript > SWF ไอเจ้า swf ก็คือไฟล์ของ flash ที่ใช้ flash player ในการ render อยู่ดี

(PS. เหมือนที่เขียนไปแล้วในอันแรก หากเขียนเป็น App ก็จาใช้ AIR ในการ compile )


ตั้งหัวข้อว่า Convention in Flex แต่ยังไม่ได้พูดถึง convention สิ
DataType:
int
String
Boolean

มี Setter, Getter เหมือน .Net

มี protocal ในการ binding ไปยัง java ได้อีกด้วย แต่ต้องมีการเขียน class ที่คล้ายๆกันเอาไว้
ไม่เหมือนกับ web service ที่ มันสร้า web reference ไป แล้วใช้งานได้เลย

เราต้องสร้าง 2 class ที่เหมือนๆกัน ทั้ง 2 ฝั่ง เพื่อให้ ส่งข้อมูลถึงกันได้ แล้วทำการ mark ที่ flex นิดหน่อยเพื่อให้มันรู้ว่า เราจา mapping ไปยัง java ( ยังไม่เขียนเลย เด๋วจาทำเป็น Sample เล็กมาให้ หลังจาก ทำ sample flex ธรรมดาเสร็จ)

เออเนื่องจากมันเน้นเอาไว้ทำ RIA จึงทำ drag n drop ง่ายๆ เช่น พวก list (list view) มันก็จามี attribute ประมาณว่า จาให้ drag ได้ป่าว จาให้ drop ได้ป่าว เลย

Wednesday, June 4, 2008

Getting start Macromedia Flex [part I]

กำลังหัดเขียน เพราะว่าต้องทำ RIA เด๋วว่างๆจามา เขียนคร่าวๆให้อ่านว่ามัน เขียนไง เอาไว้ทำอะไร

ง่ายๆมันคือ Flash นี่แหละ แต่เขียนเป็น XML เรียกว่า MXML และใช้ ActionScript เข้าไปด้วย

ถ้ามันทำเป็น App ก็จาไปรันผ่าน Adobe AIR ถ้าไปรันบนเวป ก็ใช้ Macromedia Flash ในการ render


Tools ใช้ Eclipse + plugin ไม่ก็ใช้ Flex builder 3 ซึ่งก็คือ eclipse ที่ customize มาให้ใช้เขียน flex (มัน base on eclipse )

Thursday, May 29, 2008

Google Maps on GWT 1.5

Normaly Google Map API for Goolgle Web Toolkits (GWT) work properly on GWT 1.4.x.
Now GWT 1.5 RC is avaliable but GWT Google Map can not work on its.
So I modify something for GWT 1.5. It works fine as run on GWT 1.4.x, you can download here
http://file.citec.us/download.php?id=769C5AD6

Tuesday, May 27, 2008

How to get Primary Keys with DB2

Commonly when you want to retrieve information of database that you connect, for example primary key, schema name, table name etc. You can use DatabaseMetaData

Code Example:

DatabaseMeataData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getPrimaryKeys(catalog, schema, tablename);

But when your database is DB2. You cann't use DatabaseMetaData (The method can be executed, but it returns an empty ResultSet)

ref :http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.java/rjvjdapi.htm in Table 11

You can use this solution :
This solution select column name of primary key from syscat.keycoluse and syscat.tabconst of DB2.

String SqlStatement = "select colseq, colname from syscat.keycoluse k, syscat.tabconst t where k.constname = t.constname and k.tabname = t.tabname";
conn = Connector.getDBConnection(url, username, password);
pstm = conn.prepareStatement(SqlStatement);
rs = pstm.executeQuery();

ref : http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0401melnyk/?S_TACT=105AGX11&S_CMP=LP in Table 1

Monday, May 26, 2008

Send SMS by using Java

This code is example for send sms by using java programming.



Code:

import java.io.*;

import java.util.*;

import javax.comm.*;
public class GSMConnect implements SerialPortEventListener, CommPortOwnershipListener {
private String comPort = "COM3"; // This COM Port must be connect with GSM Modem or your mobile phone


private String messageString = "";

private CommPortIdentifier portId = null;

private Enumeration portList;

private InputStream inputStream = null;

private OutputStream outputStream = null; private SerialPort serialPort;
/** Creates a new instance of GSMConnect */


public GSMConnect(String comm) {

this.comPort = comm;

}
public boolean init() {


portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {

portId = (CommPortIdentifier) portList.nextElement();

if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL){

if (portId.getName().equals(comPort)) {

return true;

}

}

}

return false;

}
public void checkStatus() {


send("AT+CREG?\r\n");

}
public void dial(String phoneNumber) {


try {

//dial to this phone number

messageString = "ATD" + phoneNumber + ";\n\r";

outputStream.write(messageString.getBytes());

} catch (IOException e) {

e.printStackTrace();

}

}
public void send(String cmd) {


try {

outputStream.write(cmd.getBytes());

} catch (IOException e) {

e.printStackTrace();

}

}
public void sendMessage(String phoneNumber, String message) {


send("AT+CMGS=\"" + phoneNumber + "\"\r\n");

send(message + '\032');

}
public void hangup() {


send("ATH\r\n");

}
public void connect() throws NullPointerException {


if (portId != null) {

try {

portId.addPortOwnershipListener(this);

serialPort = (SerialPort) portId.open("MobileGateWay", 2000);

} catch (PortInUseException e) {

e.printStackTrace();

}

try {

inputStream = serialPort.getInputStream();

outputStream = serialPort.getOutputStream();

} catch (IOException e) {

e.printStackTrace();

}

try {/** These are the events we want to know about*/

serialPort.addEventListener(this);

serialPort.notifyOnDataAvailable(true);
} catch (TooManyListenersException e) {


e.printStackTrace();

}

//Register to home network of sim card

send("ATZ\r\n");

} else {

throw new NullPointerException("COM Port not found!!");

}

}
public void serialEvent(javax.comm.SerialPortEvent serialPortEvent) {


switch (serialPortEvent.getEventType()) {

case SerialPortEvent.BI:

case SerialPortEvent.OE:

case SerialPortEvent.FE:

case SerialPortEvent.PE:

case SerialPortEvent.CD:

case SerialPortEvent.CTS:

case SerialPortEvent.DSR:

case SerialPortEvent.RI:

case SerialPortEvent.OUTPUT_BUFFER_EMPTY:

case SerialPortEvent.DATA_AVAILABLE:

byte[] readBuffer = new byte[2048];

try {

while (inputStream.available() > 0) {

int numBytes = inputStream.read(readBuffer);

}

//print response message

System.out.print(new String(readBuffer));

} catch (IOException e) {}

break;

}

}
public void ownershipChange(int type) {


switch (type) {

case CommPortOwnershipListener.PORT_UNOWNED:

System.out.println(portId.getName() + ": PORT_UNOWNED"); break;
case CommPortOwnershipListener.PORT_OWNED:


System.out.println(portId.getName() + ": PORT_OWNED"); break;
case CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED:


System.out.println(portId.getName() + ": PORT_INUSED"); break;

}

}


public static void main(String args[]) {

GSMConnect gsm = new GSMConnect(comPort);

if (gsm.init()) {

try {

gsm.connect();

gsm.checkStatus();

Thread.sleep(5000);

gsm.sendMessage("Mobile Phone Number", "Your Message");

Thread.sleep(20000);

gsm.hangup();

} catch (Exception e) { e.printStackTrace(); }
} else {
System.out.println("Can't init this card");
}
}
}

Wednesday, May 14, 2008

JavaFX Ep2 : "Hello World"

Say "Hello World"
New Project> JavaFx> JavaFx Script Application












Let's start like instructed by trying to run the Hello World example featured on the JavaFX tutorial page.

import javafx.ui.*;

Frame {
title: "Hello World JavaFX"
width: 250
height: 50
content: Label {
text: "Hello World. From Javalobby!"
}
visible: true
}

























This code uses the declarative source code "annotation", it is also possible to use the procedural source code "annotation".

  var win = new Frame();
win.title = "Hello World JavaFX";
win.width = 250;
win.height = 50;
var label = new Label();
label.text = "Hello World. From Javalobby!";
win.content = label;
win.visible = true;

[JavaFX Tutorial]Getting start JavaFX with Netbeans IDE 6.1

How to install JavaFX plugin to Netbeans 6.10 IDE
  1. Download and Install Netbeans IDE 6.1
  2. Download this Developmental built of the JavaFx Netbeans 6.1 plugin that base on OpenJFX compiler.
  3. Unzip the local file
  4. In Netbeans program Main Menu Choose Tool>Plugin.
  5. Select Downloaded tab and click Add Plugins.
  6. Select all the .nbm files included in the downloaded bits, and click Open.
  7. Restart the IDE.

NetBeans IDE: Adding/Changing JVM command line args

You can indeed set your favorite JVM command line args to use with NetBeans. Here's how to do it.

1. Go to the directory where you installed NetBeans IDE.

2. In that directory, go to the 'etc' directory.

3. In that 'etc' directory, there is a file called 'netbeans.conf'.

Open that netbeans.conf file


Here's an explanation of the command line switches I use:
-J-Xms128m -> initial Java heap size
-J-Xmx384m -> max Java heap size
-J-XX:NewRatio=20 -> Ratio of old generation to young generation space
-J-XX:+UseConcMarkSweepGC -> use the concurrent old generation garbage collector
-J-XX:+UseParNewGC -> use the parallel young generation garbage collector
-J-XX:+CMSPermGenSweepingEnabled -> enable concurrent gc in permanent generation
-J-XX:+CMSClassUnloadingEnabled -> enable class unloading in permanent generation with the concurrent gc collector
-J-XX:+CMSPermGenPrecleaningEnabled -> enable pre-cleaning when using concurrent gc collector in permanent generation
-J-XX:PermSize=64m -> initial size of permanent generation space set to 64m
-J-XX:MaxPermSize=96m -> max size of permanent generation space set to 96m
-J-Dswing.aatext=true -> use font anti-aliasing

* Keep in mind that I am running on a machine with 1G of RAM. However, these settings should work fine on a machine with 512m. Just keep an eye on swapping activity. If you can keep your system from swapping, you're responsiveness will be much better.

Thursday, May 8, 2008

Gwt-Ext lib in Netbeans

Problem when add Gwt-Ext lib in Netbeans

I found this problem in netbeans 5.5. even if you add Gwt-Ext in your project and following step from getting started, the application didn't work. and show this error.

[ERROR] Out of memory; to increase the amount of memory, use the -Xmx flag at startup (java -Xmx128M ...)
[ERROR] Build failed

this is solution.
http://www.gwt-ext.com/forum/viewtopic.php?f=5&t=755

GWT (Google Web Toolkit)

Now, I use GWT to develop web application project and i want to collect many information at here for people who want to learn.

Get GWT : http://code.google.com/webtoolkit/
GWT plugin for Netbeans : https://gwt4nb.dev.java.net/
GWT plugin for Eclipse : http://code.google.com/p/cypal-studio/
GWT more look and feel , GWT-Ext: http://code.google.com/p/gwt-ext/
GWT e-book you can downloadfrom : http://www.ebookee.com/ such as GWT in Action

That is now i had collected. When i have cool ideas or sample you will see in my blog.

Intercommunication programming

I want to communicate between programming languages, call java from c. i found solution first at here call java from c it use system function to call process to run(java). and another way is using named pipes. this here to try example named piped.

c# detect usb device event

One day. i think if i want to get data from thumb drive by plugged in usb port and it will automatic download data to my computer.
i found my solution at here. How to detect a USB Device and i can finished my c# program
this my video how it work?. AutoDump

if you want my program plz contact me.

Font Thai in mysql like ??? on Ubuntu

My environment:
Ubuntu 7.04
mysql 5.0.38

If you see Thai font like ??????. because character set in mysql server and client was different.
You should set character set in server and client matched.
Check status in mysql.

In your computer No.2 may be latin. I had changed from latin to tis620.
First, You should edit file config in /etc/mysql/my.cnf and add default-character-set in

[client]
default-character-set = tis620

And....

[mysqld]
default-character-set = tis620
init_connect = 'SET NAMES tis620'

Save it and restart mysql with /etc/init.d/mysql restart
Thai font will be fixed

Nmap scan port

Nmap utility for network exploration or security auditing. Many systems and network administrators also find it useful for tasks such as network inventory, managing service upgrade schedules, and monitoring host or service uptime. Nmap runs on all major computer operating systems, and both console and graphical versions are available.

This example on my computer(satann)
if you want to know port just use nmap. and anything what to do..........

my command --> nmap -sT ip
result

Android Query Email From Contacts

This is good one sample
http://groups.google.com/group/android-developers/browse_thread/thread/9e44fa66e1849c1b/f2bd7a6edfe5e68f?lnk=st&q=android+contactmethods

Android Contact Management Example Code

I read the good one example about android vs contact management.
http://groups.google.com/group/android-developers/browse_thread/thread/c68dac6a3b38f4ad

Sunday, March 2, 2008

Android GUI Tools

If you need to design GUI layout for android application, it use xml to design. There are the easy way to do the same thing.
DroidDraw
is the easy way to build the gui for android application. It can generate xml tag by drag and drop the component and you only copy xml tag to your application layout xml file. Try its.

Sunday, February 3, 2008

Java Comm Problem

Java Communication problem on Windows
Almost Java Comm on Window can not open comport
solution to fix this problem is add this code
String driverName = "com.sun.comm.Win32Driver"; // or get as a JNLP property
CommDriver commDriver = (CommDriver)Class.forName(driverName).newInstance();
commDriver.initialize();
or see http://en.wikibooks.org/wiki/Serial_Programming:Serial_Java