Java Reference
In-Depth Information
this.stmtDepth = this.connection.prepareStatement(
this.sqlDepth);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
This program begins by creating its window and then creating a background thread. The
background thread, contained in the run method, allows the application to update the sta-
tistics on a regular basis. The run method begins by entering an endless loop and opening
a connection to the database and obtaining a Graphics object.
Graphics g = null;
for (;;) {
if (this.connection == null) {
open();
}
if (g == null) {
g = getContentPane().getGraphics();
}
The database connection is established by calling the open method, which will be cov-
ered in the next section. If the Graphics object, named g , was obtained successfully, the
getStats method is called to obtain the current statistics from the database. Next, the
displayStats method is called to display the current statistics.
if (g != null) {
getStats();
displayStats(g);
}
Then the program will wait for 10,000 milliseconds, or 10 seconds, before polling for stats
again.
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
return;
}
}
Search WWH ::




Custom Search