This module provides a mechanism to utilize thinlet in Pnuts, which allows you to write GUI programs with XML and Pnuts scripts.
The details of the functions are described in 'thinlet module Reference'
Currently, pnuts-thinlet.jar contains modified Thinlet. If in the future our modification is incorporated into Thinlet, the modified code will be separated.
import javax.swing.*
use("thinlet")
parseThinlet("calculator.xml", f = JFrame())
function calculate(n1, n2, r){
r.text = string(int(n1)+int(n2))
}
f.pack()
f.show()
<panel gap="4" top="4" left="4"> <textfield name="number1" columns="4" /> <label text="+" /> <textfield name="number2" columns="4" /> <button text="=" action="calculate(number1.text, number2.text, result)" /> <textfield name="result" editable="false" /> </panel>
import pnuts.lang.Context;
import org.pnuts.thinlet.PnutsThinlet;
import javax.swing.JFrame;
public class Test {
public static void main(String[] args) throws Exception {
Context context = new Context();
context.usePackage("pnuts.lib");
PnutsThinlet thinlet = new PnutsThinlet(context);
thinlet.add(thinlet.parse("calculator.xml"));
thinlet.load("calculator");
JFrame f = new JFrame();
f.getContentPane().add(thinlet);
f.pack();
f.show();
}
}
function calculate(n1, n2, r){
r.text = string(int(n1)+int(n2))
}
When Thinlet is used in Java, appropriate setXXXX and getXXX methods must be used depending on the property type.
When Thinlet is used in Pnuts, component's fields are specified as if it were Bean properties.public boolean setString(Object component, String key, String value)
component . propertycomponent . property = value
When Thinlet is used in Java, operations on a component have a common pattern of method signature, which the target component is passed in the first parameter.
When Thinlet is used in Pnuts, this can be written in object oriented style.public boolean requestFocus(Object component)
componet.requestFocus()componet.repaint()componet.remove()componet.removeAll()componet.find(name)componet.add(component)componet.add(component, idx)componet.getProperty(prop)componet.putProperty(prop, value)