The Thinlet Calculator in XThinlet terms
Hover your mouse over the 's to see the tips.

Handler code for the Calculator

package xthinlet.demo;
import java.io.IOException;
import java.io.InputStream;

import xthinlet.XThinlet;

/**
 @author Koen Roevens
 */
public class Calculator {
  private XThinlet x;
  public Calculator(XThinlet xthrows IOException {
    this.x = x;
    parse();
  }
  private void parse() throws IOException {
    InputStream stream = getClass().getResourceAsStream("calculator.xml");
    x.add(x.parse(stream,this));
  }

  public void calculate(String number1, String number2, Object result) {
    try {
      int i1 = Integer.parseInt(number1);
      int i2 = Integer.parseInt(number2);
      x.setString(result, "text", String.valueOf(i1 + i2));
    catch (NumberFormatException nfe) {
      x.setString(result, "text""error");
    }
  }
}
Java2html

Plumbing code to register
and launch the Calculator


package xthinlet.demo;

import java.io.IOException;

import thinctx.ThinContext;
import thinctx.StaticThinContext;
import xthinlet.RegisterXThinlet;

/**
 @author Koen Roevens
 */
public abstract class LaunchCalculator {
  // Register the required modules
  static {
    Class clazz = RegisterXThinlet.class;
  }
    
  public static void main(String[] args) {
    ThinContext ctx = StaticThinContext.getTheCtx();
    try {
      new Calculator(ctx.getXThinlet());
      ctx.launch("Calculator");
    catch (IOException e) {
      e.printStackTrace();
    }
  }  
}
Java2html

Handler code and plumbing code can be combined
in one Class, if wanted


package xthinlet.demo;

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

import thinctx.StaticThinContext;
import thinctx.ThinContext;
import xthinlet.RegisterXThinlet;
import xthinlet.XThinlet;

/**
 @author Koen Roevens
 */
public class PackedCalculator {
  // Register the required modules
  static {
    Class clazz = RegisterXThinlet.class;
  }
  
  /////////////////////////////////////////////

  private XThinlet x;
  public PackedCalculator(XThinlet xthrows IOException {
    this.x = x;
    parse();
  }
  private void parse() throws IOException {
    InputStream stream = getClass().getResourceAsStream("calculator.xml");
    x.add(x.parse(stream,this));
  }

  public void calculate(String number1, String number2, Object result) {
    try {
      int i1 = Integer.parseInt(number1);
      int i2 = Integer.parseInt(number2);
      x.setString(result, "text", String.valueOf(i1 + i2));
    catch (NumberFormatException nfe) {
      x.setString(result, "text""error");
    }
  }
  
  ///////////////////////////////////////////////
  
  public static void main(String[] args) {
    ThinContext ctx = StaticThinContext.getTheCtx();
    try {
      new PackedCalculator(ctx.getXThinlet());
      ctx.launch("PackedCalculator");
    catch (IOException e) {
      e.printStackTrace();
    }
  }  
}
Java2html