Java Reference
In-Depth Information
54. controlPanel.add(undo);
55. controlPanel.add(redo);
56. controlPanel.add(exit);
57. content.add(controlPanel);
58.
59. update.addActionListener(this);
60. undo.addActionListener(this);
61. redo.addActionListener(this);
62. exit.addActionListener(this);
63.
64. refreshDisplay();
65. mainFrame.addWindowListener(new WindowCloseManager());
66. mainFrame.pack();
67. mainFrame.setVisible(true);
68. }
69.
70. public void actionPerformed(ActionEvent evt){
71. Object originator = evt.getSource();
72. if (originator == update){
73. executeCommand();
74. }
75. if (originator == undo){
76. undoCommand();
77. }
78. if (originator == redo){
79. redoCommand();
80. }
81. else if (originator == exit){
82. exitApplication();
83. }
84. }
85.
86. private class WindowCloseManager extends WindowAdapter{
87. public void windowClosing(WindowEvent evt){
88. exitApplication();
89. }
90. }
91.
92. public Location getNewLocation(){
93. return new LocationImpl(updatedLocation.getText());
94. }
95.
96. private void executeCommand(){
97. command.execute();
98. refreshDisplay();
99. }
100.
101. private void undoCommand(){
102. command.undo();
103. refreshDisplay();
104. }
105.
106. private void redoCommand(){
107. command.redo();
108. refreshDisplay();
109. }
110.
111. private void refreshDisplay(){
112. display.setText(appointment.toString());
113. }
114.
115. private void exitApplication(){
116. System.exit(0);
117. }
118. }
Notice that the CommandGui class implements the interface LocationEditor . This interface defines a method
getNewLocation , which provides a way for the ChangeLocationCommand to retrieve the new location from the
GUI.
Example A.45 LocationEditor.java
1. public interface LocationEditor{
2. public Location getNewLocation();
3. }
Search WWH ::




Custom Search