Java Reference
In-Depth Information
RunPattern loads the data for a sample Appointment and creates an instance of CommandGui . The GUI enables
you to make changes to the location of the Appointment , with update, undo and redo behavior.
Example A.50 RunPattern.java
1. import java.util.Calendar;
2. import java.util.Date;
3.
4. public class RunPattern{
5. private static Calendar dateCreator = Calendar.getInstance();
6.
7. public static void main(String [] arguments){
8. System.out.println("Example for the Command pattern");
9. System.out.println();
10. System.out.println("This sample will use a command class called");
11. System.out.println(" ChangeLocationCommand to update the location");
12. System.out.println(" of an Appointment object.");
13. System.out.println("The ChangeLocationCommand has the additional");
14. System.out.println(" ability to undo and redo commands, so it can");
15. System.out.println(" set the locaition back to its original value,");
16. System.out.println(" if desired.");
17. System.out.println();
18.
19. System.out.println("Creating an Appointment for use in the demo");
20. Contact [] people = { new ContactImpl(), new ContactImpl() };
21. Appointment appointment = new Appointment("Java Twister Semi-Finals",
22. people, new LocationImpl(""), createDate(2001, 10, 31, 14, 30),
23. createDate(2001, 10, 31, 14, 31));
24.
25. System.out.println("Creating the ChangeLocationCommand");
26. ChangeLocationCommand cmd = new ChangeLocationCommand();
27. cmd.setAppointment(appointment);
28.
29. System.out.println("Creating the GUI");
30. CommandGui application = new CommandGui(cmd);
31. application.setAppointment(appointment);
32. cmd.setLocationEditor(application);
33. application.createGui();
34.
35. }
36. public static Date createDate(int year, int month, int day, int hour, int minute){
37. dateCreator.set(year, month, day, hour, minute);
38. return dateCreator.getTime();
39. }
40. }
 
Search WWH ::




Custom Search