Web hosting script - 386 Object-Based Programming Chapter 8 33 JOptionPane.showMessageDialog( null,
386 Object-Based Programming Chapter 8 33 JOptionPane.showMessageDialog( null, output, 34 “Testing Class Time1″, 35 JOptionPane.INFORMATION_MESSAGE ); 36 37 System.exit( 0 ); 38 } 39 40 } // end class TimeTest1 Fig. 8.2 Using an object of class Time1in a program (part 2 of 2). The statement at lines 15 18 defines a String reference output, which stores the string containing the results that will be displayed in a message box. Initially, the program assigns to output the time in universal-time format (by sending message toUniversalString to the object to which time refers) and standard-time format (by sending message toStringto the object to which timerefers) to confirm that the data were initialized properly. Note that line 18 uses a special string concatenation feature of Java. Concatenating a Stringwith any object results in an implicit call to the object s toString method to convert the object to a String; then the Strings are concatenated. Lines 17 18 illustrate that you can call toStringboth explicitly and implicitly in a Stringconcatenation operation. Line 21 sends the setTimemessage to the object to which timerefers to change the time. Then lines 22 24 append the time to outputagain in both formats to confirm that the time was set correctly. To illustrate that method setTime validates the values passed to it, line 28 calls method setTime and attempts to set the instance variables to invalid values. Then lines 29 31 append the time to output again in both formats to confirm that setTime validated the data. Lines 33 35 display a message box with the results of our program. Notice in the last two lines of the output window that the time is set to midnight the default value of a Time1 object. Now that we have seen our first non-applet, non-application class, let us consider several issues of class design. Again, note that the instance variables hour, minuteand secondare each declared private. Instance variables declared private are not accessible outside the class in which they are defined. The philosophy here is that the actual data representation used within the class is of no concern to the class s clients. For example, it would be perfectly Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01
Note: If you are looking for high quality webhost to host and run your jsp application check Vision florida web design services