/Users/lyon/j4p/src/addBk/addressBook/NavigationPanel.java
|
1 package addBk.addressBook;
2
3 //NavigationPanel.java
4
5
6 import java.awt.*;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9 import java.awt.event.FocusEvent;
10
11 public class NavigationPanel
12 extends Panel
13 implements ActionListener {
14
15 PreviousButton prevButton
16 = new PreviousButton();
17
18 Button nextButton
19 = new NextButton();
20
21 Button indexButton
22 = new IndexButton();
23
24 Button editButton
25 = new EditButton();
26
27 public void
28 actionPerformed(ActionEvent e) {
29 ((Runnable)
30 e.getSource()).run();
31 }
32
33 public void focusLost(FocusEvent e) {
34 System.out.println("blur ");
35 }
36
37 public void focusGained(FocusEvent e) {
38 System.out.println("sharp");
39 }
40
41
42 NavigationPanel() {
43 setLayout(
44 new GridLayout(0, 1));
45 add(prevButton);
46 add(nextButton);
47 add(indexButton);
48 add(editButton);
49 prevButton.addActionListener(this);
50 nextButton.addActionListener(this);
51 indexButton.addActionListener(this);
52 editButton.addActionListener(this);
53 }
54
55 public class PreviousButton extends Button
56 implements Runnable {
57 PreviousButton() {
58 super("Prev");
59 }
60
61 public void run() {
62 System.out.println("Run previous");
63 AddressBookMediator display =
64 new AddressBookMediator();
65 if (display.isEditFlag())
66 display.saveCurrentRecord();
67 display.prevRecord();
68 }
69 }
70
71 public class NextButton extends Button
72 implements Runnable {
73 NextButton() {
74 super("Next");
75 }
76
77 public void run() {
78 System.out.println("Run next");
79 AddressBookMediator display =
80 new AddressBookMediator();
81 if (display.isEditFlag())
82 display.saveCurrentRecord();
83 display.nextRecord();
84 }
85 }
86
87 public class IndexButton extends Button
88 implements Runnable {
89 IndexButton() {
90 super("Index");
91 }
92
93 public void run() {
94 System.out.println("Run index");
95 AddressBookMediator display =
96 new AddressBookMediator();
97 display.toggleIndexDisplay();
98 }
99 }
100
101 public class EditButton extends Button
102 implements Runnable {
103 EditButton() {
104 super("Edit");
105 }
106
107 public void run() {
108 System.out.println("Run edit");
109 AddressBookMediator display =
110 new AddressBookMediator();
111 if (display.isEditFlag())
112 display.saveCurrentRecord();
113 display.toggleEditPanel();
114 }
115 }
116
117
118 } // end class NavigationPanel
119