Pavlov sillyview

the sillyview site
 
   

sillyview Example

PDF
PDF

Simple Example

Here's a snippet showing sillyview in action. We've defined a HTML template file myTemplate.vm which has a HTML form in it. We want to:

  1. Display the HTML to the user in a Swing Widget
  2. Listen for the form submission event
  3. Parse the form data, and react to it
...
// set up the model and the view

WidgetModel mod = null;
WidgetView view = null;

try {
   URL u = new URL("file:myTemplate.vm");
   mod = new VelocityModel(u);
} catch (Exception e) {
   e.printStackTrace();
   System.out.println("Exception " + e );
}
view = new JInternalFrameView(mod, JPanelView.HTMLPANE);
view.setToken(JPanelView.TITLE,(Object)"HTMLPane View");
view.setToken(JPanelView.HYPERLINK_LISTENER,this);
if(view instanceof JInternalFrame){
   JInternalFrame jif = (JInternalFrame)view;
   addInternalFrame(jif);
   jif.reshape(0,0,400,400);
}
...

// this is the guts of the controller

public void hyperlinkUpdate(HyperlinkEvent e) {
   if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
       if(e instanceof FormSubmitEvent){
          FormSubmitEvent f = (FormSubmitEvent)e;
          System.out.println("data = " + f.getData());
          Hashtable la = URLParser.parseVariables(f.getData());
          System.out.println("User name is :" + la.get("username"));
          ... parse the data to react to user's input
       }
   }
}