Setting up the Application
Let's start by creating a new NetBeans Platform application.
- Choose File > New Project (Ctrl+Shift+N). Under Categories, select NetBeans Modules. Under Projects, select NetBeans Platform Application. Click Next.
- In the Name and Location panel, type "ShakespeareSearch" in the Project Name field. Click Finish.
The IDE creates the ShakespeareSearch project. The project is a container for all the other modules you will create.
Run the application and notice that you have quite a few features out of the box already. Open some of the windows, undock them, and get to know the basic components that the NetBeans Platform provides without you doing any work whatsoever:
Note: Everything you see in the screenshot above can be hidden, if superfluous to your business needs, or enabled, e.g., the "Save" menu item can be enabled as described in How to Create a Swing CRUD Application on NetBeans Platform 6.8.
Once you've familiarized yourself with the framework of your application (by looking through the menus and clicking the buttons shown in the screenshot above), continue with the next section, where you'll wrap the three Groovy JARs into a NetBeans module and add it to the application.
Wrapping the Groovy JARs in a NetBeans Module
In this section, you add your first module to your application. The new NetBeans module will wrap the Groovy JAR files you worked on in the first section, above.
- To simplify the next step, put the three JARs ("groovy-all.jar", "groovyws-standalone-xxx.jar", and "ShakesGroovy.jar") into one folder somewhere on your hard disk. Once they are in the same folder folder, you'll be able to select them more easily, via Ctrl-Click in the wizard in the next step, when wrapping them into a NetBeans module.
- Right-click the ShakespeareSearch "Modules" node in the Projects window
and choose "Add New Library".
Select the three JARs ("groovy-all.jar", "groovyws-standalone-xxx.jar", and "ShakesGroovy.jar")
by clicking "Browse" and then "Ctrl-Click" to select all three JARs in the folder where you put them above.
Then complete the wizard, specifying any values you like, such as by filling in the values below:
You now have your first custom module in your new application, wrapping the JARs containing the Groovy-related classes. Take a look in your new NetBeans module's "Libraries" node in the Projects window and you will see your three JARs:
Right-click the new NetBeans module, choose Properties, and in the "API Versioning" node you will see that all the packages of the three JARs in the module are available to the rest of the applications. I.e., these are application-wide packages. That's the default. However, the only package you need to expose is the last one, i.e., "shakesgroovy", because that's the package providing the Java code compiled from your Groovy class, i.e., for interacting with the web service:
Therefore, if you like, you can uncheck the checkmarks for all the other packages listed in the dialog above, because all you need to expose to the rest of the application is the "shakesgroovy" package.
Now that the Groovy JARs are available in your application, the next section will show you how you can create a new NetBeans module that will access the Groovy class to retrieve Shakespeare quotations from the web service. Then we'll spend some time making a nice UI, using the many advanced Swing components that the NetBeans Platform makes available for free out of the box.