Skip to content

Getting Started: Creating Hello World UI

Jeff Martin edited this page Apr 11, 2019 · 17 revisions

Getting Started: Creating a basic UI app

ViewOwner

The top level object in a SnapKit application is usually a subclass of snap.view.ViewOwner. This class contains the following key methods for creating UI, initializing it, updating it from app data and responding to changes:

import snap.view.*;

public class HelloWorld extends ViewOwner {

/** Create UI here. */
protected View createUI()  { return new Button("Hello World"); }

/** Initial UI configuration. */
protected void initUI()  { getUI().setName("MyButton"); }

/** Update UI after any user input. */
protected void resetUI()  { }

/** Respond to UI. */
protected void respondUI(ViewEvent anEvent)
{
    if(anEvent.equals("MyButton"))
        System.out.println("Button was pressed");
}

/** Standard main. */
public static void main(String args[])  { new HelloWorld().setWindowVisible(true); }

}```

Clone this wiki locally