Java Reference
In-Depth Information
22. else {
23. System.err.println("File " + inputFile + " does not exist.");
24. }
25. }
26. catch (ClassNotFoundException exc){
27. exc.printStackTrace();
28.
29. }
30. catch (IOException exc){
31. exc.printStackTrace();
32.
33. }
34. return returnValue;
35. }
36. public static void storeData(File outputFile, Serializable data){
37. try{
38. ObjectOutputStream writeOut = new ObjectOutputStream(new
FileOutputStream(outputFile));
39. writeOut.writeObject(data);
40. writeOut.close();
41. }
42. catch (IOException exc){
43. exc.printStackTrace();
44. }
45. }
46. }
RunPattern runs the demonstration, creating a CalendarEditor object (which retrieves its initial entries from
the file with test Appointments ) and matching it with a StateGui object.
Example A.107 RunPattern.java
1. import java.io.File;
2. public class RunPattern{
3. public static void main(String [] arguments){
4. System.out.println("Example for the State pattern");
5. System.out.println();
6.
7. if (!(new File("appointments.ser").exists())){
8. DataCreator.serialize("appointments.ser");
9. }
10.
11. System.out.println("Creating CalendarEditor");
12. CalendarEditor appointmentBook = new CalendarEditor();
13. System.out.println("");
14.
15. System.out.println("Created. Appointments:");
16. System.out.println(appointmentBook.getAppointments());
17.
18. System.out.println("Created. Creating GUI:");
19. StateGui application = new StateGui(appointmentBook);
20. application.createGui();
21. System.out.println("");
22. }
23. }
 
Search WWH ::




Custom Search