The JTextArea

I started using the JTextArea control in my applets. Seems all the good controls are in the "javax.swing" package. You pass in the height to the JTextArea constructor. However it seems that the thing will allow more than that many rows in the control. The control seems only bounded by the applet window size. What the heck?

You use newlines in the JTextArea text to make the thing jump to the next row in the control. One thing is strange though. The default behavior does not seem to provide anything other than the text in the control. There is no border or scrollbar or anything. Maybe there is some other control that is more like the Windows control I am used to.

Eclipse User Trends


Let's briefly look at the trends of Eclipse users. You could say they are comparable to the general Java development community. For starters they are using Subversion as the configuration management tool of choice. They also are using the Linux operating system for desktop development. These developers continually download and use the latest version of Eclipse.

CVS use is on the decline for configuration management. ANT is the build tools of choice. Maven is trying to catch up. Some are just using Eclipse itself to control builds. Web development is done using jQuery (I just got a book on jQuery, so I will be sharing what I learn). The majority of Eclipse users do not contribute to open source. That last statistic surprises me.

I hope I can get my hands on some survey data for Java developers as a whole.

Wish Upon a Star

I am moving on to writing more applets. These are simple programs to get my bearings. The most important methods in JApplet are init() and paint(). You add items or objects to the screen in the init() function. And you draw things such as labels and buttons in the paint() function.

If you handle some GUI events like button clicks, the pattern is to call repaint() to get the screen updated based on the user input. It is funny how quickly I forget my Java basics when I do not code for a long time. These rules have not been committed to heart.

For example, I had to rediscover how to convert a String to an int. You create an Integer object, passing the String into the constructor. Then you can assign the resulting Integer to a variable of type int. Also you need to qualify Math package functions with "Math." to get your Java to compile.

Some topics are universal. Break down complex routines into multiple subroutines (functions). Make use of constants instead of magic numbers. In Java this is done with public static final variables. I will say I am starting to get some bearings on how to do drawing on the Canvas. The upper left hand corner of the screen has coordinates (0,0). Increasing x goes to the right. Increasing y goes down.

My First Applet

Here I am in my full week of training. This is an independent study for me. My goal is to learn applet programing. Read a couple chapters in my school textbook. We always skipped the applet and other GUI sections. Unfortunately the applet chapter requires you to read the big Java Swing chapter. I have skipped it. So I am going to be having some troubles.

Applets do not have a main function. Instead they have an init. They close when the web page that contains them closes. The containing web page is written in HTML. The applet itself runs on the client machine. There are some security restrictions like an applet cannot run a program, read a file, or write a file. You should test your applets on many browsers including multiple versions of the same browser.

The older class for applets is Applet. Go figure. You cannot use Swing with this old style class. You also cannot do icons or menus. Use buttons instead. I found that I could load an HTML page which referenced an applet. However when I recoded and recompiled the applet, an Internet Explorer 6 refresh would not run the new version of the applet. That was annoying. Instead I decided to use appletviewer. Here is another strange thing. The reload function in appletviewer causes the window to disappear and the viewer to freeze. Another funny thing was that I tried to use Graphics2D in my paint method. It compiled but just output a light blue screen. All my graphics were gone. I guess I can make do with the normal Graphics class.

Applet Time

In my college Java class, we skipped over most of the information on applets. I wanted to learn more about them though. There was a whole chapter in the text that covered applets. I also have a lot of information on my latest book about applets for game programming in Java.

It is time for me to learn applets. I convinced my employer to let me spend a week in independent study on Java. I need some program to keep me busy to really learn practical applet programming. Initially I thought I would write a copy of an arcade classic such as Pacman. However I think I will need more than a week to get deep into applet programming.

My new plan is to actually try to duplicate the main program we have on our project at work. It is a client/server C++ Windows application that connects to an Oracle database. This might be a good sized program to implement as an applet. The thing is over 2o0k lines of code. This will keep me busy for quite some time. I figure I can work on it in the office, and not get too much attention on my sideline activities.

Access Modifiers

Just read a rant about a developer that likes to use parentheses to make the order of operations explicit. He does not want a reader of his code to need to know the operator precedence rules. As an extension, he also explicitly declares the access modifier for any java function that he writes.

This started a big discussion on what it means to not specify an access modifier for a Java function. In C++ it is easy. C++ class members without an access modifier are private. C++ structure members without an access modifier are public. However in Java, not specifying an access modifier means the function is package private.

Package private has no keyword. It is the access allowed when you do not specify a modifier. This causes the function to only be accessible by other members in the package. This is different than public, private, or protected. I am sure I learned this some time ago in my Java college class. However today it was solidified.

Web Frameworks

I found this free e-book which describes some web development frameworks for Java developers. These frameworks are like those of event driven GUI applications. However they sometimes have steep learning curves. Java provides some web technology. But it does not provide a web application framework. So these third party frameworks have come about to help you with the low level tasks.

Struts is the most well known framework. It is well documented and has a large following. A drawback of using struts are the big configuration files. You need to use a lot of XML markup files for forms and rendering. I hear that developers are moving away from this framework in general.

Java Server Faces (JSF) is another framework. It runs on an application server like WebSphere. It strives to decouple the components and the view. The most frequently used implementation of JSF is Apache's MyFaces. JSF uses a managed bean to store user info. The bean classes contains the logic. This technology is backed by big companies like the former Sun Microsystems. A few years back I did hear that JSF might not be appropriate for mission critical applications. Not sure whether this opinion has since changed yet.