Thursday, February 1, 2007

My first simple .NET Framwork 3.0 app

My friends and I had just submitted the project proposals for Imagine Cup 2007: Software Design (You can find more info about Imagine Cup at http://www.imaginecup.com). One of the requirements of the project, only for the first round here in Thailand, is to build the application on the .NET Framework 3.0 which means it's time to start learning WPF, WCF, WF now!

To get started, make sure you have Visual Studio 2005 and these extensions.


First, I created a new project of type Windows Application under .NET Framework 3.0 category. I named it "HelloWPF".

I then designed the form. The Visual Studio's WPF designer is seperated into 2 panes : one for the visual designer and the other for editing raw XAML code. You can click on the "swap" button to swap the XAML pane and visual designer pane too. However, this CTP version of designer is hard to use and is not very impressive.

After that, I tried to add an event handler to the click event of the button. But there is no same old "Events" tab in the property window. Double clicked the button in the designer also not work. It takes me some time to figured out that I has to map event to code in XAML or to map it in the code under the constructor. I choose the latter way. Here is my C# code.



public partial class Window1 : System.Windows.Window
{

public Window1()
{
InitializeComponent();
btnSayHello.Click +=
new RoutedEventHandler(btnSayHello_Click);
}

void btnSayHello_Click(object sender,
RoutedEventArgs e)
{
txtMessage.Text = "WPF : สวัสดี ว่าไง";
}

}


I could finally press the F5 button and this is the result.


Wednesday, January 24, 2007

J2ME Applications to run on Sony's PSP




People at java4psp are porting J2ME Virtual Machine to the PSP which means we will see J2ME apps (and games) running on the PSP soon! The project's name is BLUEKVM. This also enable we programmers to program the PSP in Java language (which is easier to code/debug than those alien C/C++).

Welcome to PSP Java Development!

This is an experimental project on the Java technology for the PSP platform.

Current Subprojects
1. BLUEKVM - A port of the J2ME technology's Kilobyte Virtual Machine (KVM). The KVM core libraries, virtual machine

features, security, input/output, and networking is defined by the Connected Limited Device Configuration,

version 1.1.

Please visit http://java.sun.com/javame/index.jsp for more details of the J2ME technology.

Download the BLUEKVM demo version (bluekvm-psp-demo-version.zip)
to see a sample Java code running on your PSP!

2. PlayStation Device Profile (under research)


QPOINT Software Group
PHYSIKA, THe U.P. Applied Physics Society

Thursday, January 18, 2007

UTF-8 in Netbeans 5.5

I have Netbeans 5.5 with JDK 6.0 running on my Windows Vista RC1 for a month now. Problem arises when I need to use Thai language in my Java Applet project.


From the figure in the left, I try to draw a string, "สวัสดีครับ", but it was displayed as "??????????". By the way, If you enter your Thai texts via Netbeans' properties editor they will be displayed properly like the caption of JButton in my applet. (If you examined the designer generated sources, you would see escaped string instead of pure Thai text)

To fix the problem, right click on your java source file, click on properties, change the encoding to "utf-8".


After changed the file encoding, you have to close your file and reopen it. You can now edit your file and it will be saved as UTF-8.



But if you compile your file at this point, you will get something like "unmappable character for encoding XXX" error. There is one more little thing to change, Go to project properties window by right click on the project name in the project navigator and click on properties, Go to build->compile and add "-encoding utf-8" at the Additional Compiler Options.


This is my result,


This solution may apply to other foreign languages too.