Debugging Applets
In the Exceptions Trail of the Java Tutorial, the catch Blocks lesson gives the following as an example of a catch block:
} catch (IOException e) {
System.err.println("Caught IOException: "
+ e.getMessage());
}
This works fine if you are running an app from the command line, or even an applet using appletviewer
, but it is absolutely useless if you are testing an applet in an ordinary browser.
My applet is supposed to record performance data, and I found it frustrating not knowing whether it had actually written anything to the database without running a separate query on the database. I therefore added a GUI object to the applet to display the message:
if(dbDEBUG) {
jTADiagnosics = new JTextArea();
jTADiagnosics.setFont(new Font("Arial", Font.PLAIN, 14));
jTADiagnosics.setColumns(60);
jTADiagnosics.setRows(2);
c.insets = new Insets(0,10,10,10); //12oc,9oc,6oc,3oc padding
c.gridx = 0; //aligned with button 2
c.gridy = 8; //eighth row
c.gridwidth = 3; //3 columns wide
add(jTADiagnosics, c);
}
and a method to display errors in this text area:
private void addItem(String newWord) {
if(dbDEBUG) {
System.out.println(newWord);
jTADiagnosics.append(newWord);
}
}
Then for the reasons explained in my previous blog, the arguments passed to this method are the return values of the method used to do the data related stuff - loading the driver, making the connection, and most importantly, adding lines to the database.
On reflection, I think I have written these two blogs back to front, and the last one should have come before this one, but who cares? My intention now is to leave coding for a while and get back to Rasch theory.
Comments