Java Reference
In-Depth Information
else {
System.err.println(“readObject failed.”);
catch (MalformedURLException mue) {
catch (Exception e) {
The three areas of the applet you must focus on are the
jGetStatusButton_actionPerformed() , writeOrder() , and readOrder() methods. These
methods make up the functional areas of the applet.
The jGetStatusButton_actionPerformed() method is where the transaction is invoked. It
creates an Order object, setting the order attribute to the value typed into the
jOrderTextField swing component. It then opens a URL connection pointing to your
OrderStatusServlet , http://localhost/djs/servlet/OrderStatusServlet . The connec-
tion and the order are then passed to the writeOrder() method.
The writeOrder() method first sets the appropriate properties of the Connection object. It
then creates an ObjectOutputStream using the OutputStream of the connection. When the
ObjectOutputStream is successfully created, the Order object is written to it.
When the writeOrder() method returns, the readOrder() method is called. It takes the
URLConnection object passed to it and creates an ObjectInputStream . It then calls the
ObjectInputStream 's readObject() method, which block reads until a response object is
received. This new Order object is then returned to the calling method.
The jGetStatusButton_actionPerformed() method then takes the Order object that was
returned to it and calls the getStatus() method, passing the returned status to the
jStatusResultTextArea 's setText() method.
Compile these classes, making sure that the swingall.jar file, which contains all the swing
components, is in your CLASSPATH . The HTML used to load this applet is shown in Listing 6.7.
Search WWH ::

Custom Search