Create a Griffon project

Once you have installed Griffon you can use the built-in target for creating new projects:

The target will prompt you for the name of your project and create the project structure below:

Create an Application Model

Make sure you are in the root directory of your project (for argument sake "DemoConsole", a simple script evaluator) by typing

The "create-app" target created a Griffon MVC Triad for you in the models, views, and controllers directory named after the application. Hence you already have a model class DemoConsoleModel in the models directory.

The application model for the quick start is simple: the script to be evaluated and the results of the evaluation. Make sure to paste the following code into your copy of DemoConsoleModel.

DemoConsoleModel.groovy

Create the Controller Logic

The controller for our quick start app is also simple: throw the contents of the script from the model at a groovy shell. Copy the following code into your controller.

DemoConsoleController.groovy

The Griffon framework will inject references to the other portions of the MVC triad if fields named model, view, and controller are present in the model or controller. This allows us to access the view widgets and the model data if needed

The executeScript method will be used in the view for the button action. Hence the ActionEvent parameter, and the default value so it can be called without an action event.

Finally, the Griffon framework can be configured to inject portions of the builders it uses. By default, the Threading classes are injected into the controller, allowing the use of the edt, doOutside and doLater methods from the SwingBuilder.

Also, the threading may look a bit obsessive. But good thread management is essential to a well functioning Swing application.

Add Content to the View

The view classes contain the visual components for your application. As with the previous artifacts, copy the contents of the following snippet into its corresponding file: DemoConsoleView.

DemoConsoleView.groovy

The view script is a fairly straightforward SwingBuilder script. Griffon will execute these groovy scripts in context of it's UberBuilder (a composite of the SwingBuilder and whatever else is thrown in).

Run the Application

To start your Griffon app run the following target

This will run the application as a Java application. You can also use the run-webstart target to run the application from a WebStart/JNLP file.

The run-app script implies the execution of the package script. The package script creates file artifacts suitable for a Java application, a WebStart application, and an Applet, with code signed by a self-signed certificate. All from the same source tree. By default they go in the 'staging' directory.

Try out the applet by bringing up the applet.html file in a browser. Or you can try them out directly by running the following commands

What's Next

This is just the first pass at the framework. The sky's the limit! More information about the framework, artifacts, conventions and commands can be found at the Griffon Guide.

This page isn't clear. What do you do after the command 'griffon create-app'? It seems you 'cd DemoConsole'. I did that and that works. But then what? What do you type in next? 'griffon run-app' seems to be the next thing you do but that doesn't work on Windows XP with griffon versions 0.3.1, 0.9, 0.9.1, 0.9.2(beta). I get a class not found error. So what is the missing instruction?

I believe you stumbled upon http://jira.codehaus.org/browse/griffon-156 when running with Griffon 0.9. Our primary development platforms are Linux and MacOSX, this is why we missed the problems on Windows at first. I added a couple hints more on what to do on this page. You basically need to copy and paste the snippets shown into their respective files then execute the run-app command. I'd recommend you to visit the Griffon Guide to learn more about what you can do with the framework.

Just like to point out that this "Quick Start" is broken in Groovy 0.9.3. Apparently, it will be fixed in .9.4, but until then, you can't create projects that start with an uppercase name, when asked for an application name you must put 'demoConsole' in this example to get it to work.