Skip to content

Instantly share code, notes, and snippets.

@jtulach
jtulach / ProjectsDemo.java
Last active November 12, 2017 12:55
List of favorite projects via MVVM paradigm
package dew.demo.favorite;
import net.java.html.json.*;
/** Generates class Projects with getter and setter for
* string property "name" and another for an array/a list
* of strings.
*/
@Model(className="Projects", properties={
@Property(name="name",type=String.class),
@jtulach
jtulach / Counting.java
Last active August 13, 2016 09:30
Counting button clicks in Java with low level JavaScript interaction
package dew.demo.lowlevel;
import net.java.html.js.JavaScriptBody;
final class Java2JsAndBack implements Runnable {
private int cnt = 0;
@Override public void run() {
String msg = "I was pressed";
if (++cnt > 1) {
@jtulach
jtulach / ListGists.java
Last active April 22, 2020 02:28
Networking with JSON and Java
package dew.demo.gists;
import java.util.Arrays;
import net.java.html.json.*;
@Model(className="UI", properties={
@Property(name="user",type=String.class),
@Property(name="current",type=String.class),
@Property(name="names", type=String.class, array = true),
@Property(name="gists",type=Gist.class, array = true)
@jtulach
jtulach / ThrowException.java
Last active December 26, 2015 12:29
Hello World with Exception
package dew.demo.exception;
class ThrowException {
static {
if (true) throw new IllegalStateException("Hello World!");
}
}
@jtulach
jtulach / HelloViaKO.java
Last active December 26, 2015 12:29
Hello World via Knockout4Java
package dew.demo.ko4j;
import net.java.html.json.*;
@Model(className="Hello", properties={
@Property(name="say", type=String.class)
})
class HelloViaKO {
static {
Hello model = new Hello("Hello World!");
model.applyBindings();
@jtulach
jtulach / Sample.java
Last active December 26, 2015 20:58 — forked from ivargrimstad/HelloViaKO.java
Spinning Duke by Ivar
package dew.demo.duke2brwsr;
import net.java.html.json.*;
@Model(className = "Data", properties = {
@Property(name = "image", type = String.class),
@Property(name = "buttonText", type =String.class),
@Property(name = "on", type = boolean.class)
})
class Duke2Brwsr {
static {
@jtulach
jtulach / MulDivPlusMinus.java
Created November 1, 2013 09:37
Math for Kids
package dew.demo.muldiv;
import java.util.Random;
import net.java.html.json.ComputedProperty;
import net.java.html.json.Function;
import net.java.html.json.Model;
import net.java.html.json.Property;
/** Represents a computational quiz.
*/
@jtulach
jtulach / Factorial.java
Last active November 12, 2017 12:29
Compute Factorial in a Web Page
package dew.demo.factorial;
import java.math.BigInteger;
import net.java.html.json.*;
@Model(targetId="", className="UI", properties={
/** n is the number we want to compute factorial
* when the Compute! button is pressed
*/
@Property(name="n", type=int.class),
@jtulach
jtulach / Data.java
Created November 17, 2013 08:28
Histogram in Java and HTML+CSS
package dew.demo.histogram;
import java.util.ArrayList;
import java.util.List;
import net.java.html.json.ComputedProperty;
import net.java.html.json.Model;
import net.java.html.json.Property;
/** Model annotation generates class Data with
* one property for list of of numbers and read-only property
@jtulach
jtulach / Prime.java
Created November 19, 2013 13:45
Is it a prime?
package dew.demo.prime;
import net.java.html.json.Model;
import net.java.html.json.ComputedProperty;
import net.java.html.json.Property;
@Model(className="PrimeUI", properties={
@Property(name="number", type=int.class),
})
class PrimeDemo {