Wednesday, December 31, 2008

Learning Swing with the NetBeans IDE

This is where the tutorial begins to get interesting, and for me it was the launch pad to my own first Java applet. I even like the form of the example. It not only contains the essential components of a GUI, but also a tiny bit of mathematics, and it performs a calculation which many of us perform in our head from time to time (if we come from an Anglo-Saxon culture with continental European influences).

The lesson Setting up the Celsius Converter Project is important to read very slowly. Stuff this up and you stuff up your whole project. I think there might be a mistake in it. Certainly I made a mistake on my first run through, and it did stuff me right up.

In Step 1: Create a New Project, the instructions are just fine. Step 2 is fine. Step 3 is also fine in so far as it goes. Obviously if you are using the lesson as a guide for your own custom project you will choose a name which suits you, but that is not the main issue. The main issue here is that nothing is said about packages.

I know I criticised earlier lessons for introducing the package concept too early, but that is because I was using the early lessons to learn Java commands and syntax, and I was not then interested in building a whole application. The situation is now reversed. These lessons are about building an application, albeit a small one, and this when the learner needs to be thinking about placing his or her work in the context of a larger structure.

So I am quite surprised that there is not a reference to packages here, and I am even more surprised that the the create project dialog box does not offer an invitation to assign the project to a package.

Perhaps the answer comes in Steps 4 and 5. Here one is invited to assign the new JFrame to a package. The instruction is in very small print and would be easy to miss or gloss over. There is no mention of the significance of packages or the implications of assigning a class to the wrong package.

In VB, the project or project location is all important. What Java calls a JFrame, VB calls a form, and the file defining the form sits in the project folder, and can be used or dropped by the project, or indeed used by future projects, located in the same folder. So in VB, if you stuff up a project and need to start a new one, you can still use all the graphics created in the first incarnation of the project, without having to think too hard. Obviously you can reuse code in Java (that's what packages and classes are all about), but if you don't assign a class to a package correctly in the first place, using it all may be difficult, and using it in future projects may be nearly impossible.

Tuesday, December 30, 2008

Getting Started with Swing

Getting Started with Swing is the first lesson in the so-called Swing Tutorial. The lesson has two parts: About the JFC and Swing and Compiling and Running Swing Programs.

The first is as dull as it sounds, albeit of theoretical importance. It is essentially a reminder of the transparency of Java - a reminder that the power of Java lies in the huge collection of classes, already written by someone else, but made available for everyone. So while you can use a development environment like NetBeans, you can also access the functionality of the classes with hand written code.

This is important. If you want to program in VB (to create a Windows app) but you don't like the development environment, you are pretty well buggered. But if you want to create a GUI with Java, and you don't like NetBeans, you can either use another development environment, or you can do the whole thing with a text editor, provided you follow the rules very carefully.

The second part of the lesson is also very dull (another sodding "Hello World" variant), but it includes a moderately interesting link in small print. This is Running Tutorial Examples in NetBeans IDE. A link is provided to download NetBeans (for anyone who missed the riveting "Hello World!" for the NetBeans IDE). After installing NetBeans, you can download one or more example projects. Instructions are then provided on how to load a project into NetBeans, and from there compile it and run it.

Monday, December 15, 2008


Since my last post I have been musing on the question of where to go next. Should I plough through more turgid lessons on the language or should I have some fun with the Swing thread. After some deliberation I have decided to go with A Brief Introduction to Swing.

The first branch of this trail is a philosophical piece entitled What is Swing? It is best to ignore this as the tutorial tends to get muddled when it tries to be philosophical. The second branch, A Swing Demo, is much more fun. It talks you through a real applet, and it inspires enthusiasm because it is so neat, and it works so well.

The Swing Features trail is pretty much a reference document with illustrations of what VB would call GUI objects, but which here are called Swing components. There is in my opinion rather too much space devotes to the so called "Look and Feel", and then there are the usual sections on internationalisation and accessibility, which in a politically correct world they have to put in, but which I'm afraid I find rather dull, and skip over.

The post interesting link in the Swing thread is given in very small print. The same link also appears on the Tutorial home page, also in small print, under the heading Creating Graphical User Interfaces. It is the trail: Creating a GUI with JFC/Swing. This is where you should go to learn about Swing, by doing rather than just reading. And this is where I shall begin in my next blog entry.