Getting Started with Thinlet for Desktop Application

Thinlet is a lighweight UI toolkit written Java, it's not a subset of Swing. Developing with Thinlet is a different ball game it's nowhere similar with Swing or SWT. It totally separates the UI from the business logic, one of the few native UI toolkit that takes MVC in its purest form. Good thing about thinlet is the footprint is very small and more responsive than Swing or SWT. Since it can run on Windows CE, it's a good toolkit for developing PocketPC applications.

Defining the Desktop Pane

Coding the main window frame takes just a little code.



import java.io.IOException;
import java.io.InputStream;

import thinlet.FrameLauncher;
import thinlet.Thinlet;

/**
* Description:
* the main thinlet for running the SMS Commander.
*
* @author Jared Odulio
*
*
*/
public class SMSCommander extends Thinlet {

private InputStream is;

/**
*
*/
public SMSCommander() {
super();
initialize();
}

private void initialize(){

is = this.getClass().getResourceAsStream("/smscommander.xml");

try {
add(parse(is));
} catch (IOException e) {
e.printStackTrace();
}

}
/**
* Sends a message test to the text area.
*
* @param message
* @param messagefield
*/
public void sendMessageTest(String message, Object messagefield){

setString(message, "text", message.toUpperCase());

}

public static void main(String[] args){
new FrameLauncher("SMS Commander", new SMSCommander(), 320, 240);

}


public void close(){
destroy();
}

/* (non-Javadoc)
* @see thinlet.Thinlet#destroy()
*/
public boolean destroy() {

System.out.println("Entering destroy");
return false;
}

}





Where are the rest of the widget declaration? How does the desktop pane defined or the buttons? Here's a simple example of defining your needed widgets in an XML file:



<desktop>

<panel columns="1" gap="3" border="true" scrollable="true" top="4" left="4" right="4" bottom="10">
<textarea name="messagefield" text="Test" wrap="true" weightx="2" weighty="2"/>
<panel columns="0" gap="3" bottom="1">
<button name="sendBtn" text="Start" icon="image.gif" alignment="left" tooltip="Initialize the SMS Commander" halign="right"/>
<button name="cancelBtn" text="Cancel" icon="image.gif" alignment="left" tooltip="Cancels the sending" halign="right" action="close()"/>
</panel>
</panel>

</desktop>



Ok! We have our simple desktop pane with Text Area and two buttons.



Comments

Popular Posts