Saturday, July 4, 2009

Linguistic Rules

I have been silent for six weeks because I have been bogged in theory. At the end of my last blog I reported that I had been urged to revisit the core language lessons. So I went right back to the concepts trail and looked up the Inheritance lesson to better understand the extends key word, and the Interface lesson to better understand the implements key word. Then in the Language Basics trail the Variables lesson refreshed my memory on the static key word, Class Variables (Static Fields), Instance Variables (Non-Static Fields), and Local Variables. The this key word is described in the Classes and Objects trail in a lesson by the same name.

After re-reading this lessons I was able to better understand the posts in this thread at the end of which I posted some code, which for me tied it all together, and solved my event listener problem.

I went on to have problems with Window Listeners, but they arose because of my obsession with walking before I run. My main project is going to be web based, so I shall never need a window listener. I was fiddling around with a JFrame, because I had a mental blockage with applets, perhaps because building an applet represents the end game for me.

When I bit the bullet and embraced the Applet Trail I was reminded that the Applet interface has two built in "closing" events, Stop and Destroy. I therefore had no need for a window listener. However, there was another problem I had not bargained for: security restrictions of which the most serious for me was the inability to read or write files on the host.

When I first read this I gave it little attention because I don't want to write to the client, I want to store information at my end. But as I muddled my way through the mire of data connections, I learnt that the (easiest to use) embedded Derby database engine writes on the local host.

I therefore needed to take another bull by the horns and embrace the Apache Derby Documentation. This is well written, with easy to follow examples, but the was a lot to learn. Essentially I needed to run the NetServer application on my web server, specify that it should receive connections from anywhere, and then use the client driver with my applet.

There was no need for any other supporting classes. As long as the communication was with a server app running from the same address from with the applet was downloaded, all the code can be contained in the single applet. Put another way, calling supporting non-applet classes from the applet to make the data connection is not a way around the security restrictions. I had seen some sample code which used supporting classes to make a connection, and I foolishly thought I could use it to break the rules, but I could not.

Instead, I ended up making a successful test connection straight out of an applet, and I posted the code at the end of this thread for future reference.

No comments: