Latest ESXX Release


Friday, February 6, 2009

F-Script vs. JavaScript


I read about F-Script on Ars Technica today and couldn't help wondering how the example might have looked like if written as an ESXX command line application. Something like this, perhaps?
#!/usr/bin/env esxx-js

with (JavaImporter(java.awt, javax.swing)) {
function main() {
// Create the window
let window = new JFrame("TimeSetter");
window.setLayout(null);
window.setPreferredSize(new Dimension(383, 175));
window.setLocation(125, 513);
window.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE;

// Add a button
let button = new JButton("Push Me");
button.setBounds(100, 50, 150, 50);
window.add(button);

// Set up the two scripts -- one beeps, the other updates the window title
function beepScript() { Toolkit.defaultToolkit.beep(); }
function titleScript() { window.title = new Date(); }

// When the button is clicked, do something
button.addActionListener(titleScript);
window.rootPane.defaultButton = button;

window.pack();
window.visible = true;
esxx.wait(this);
}
}

No comments: