Java Reference
In-Depth Information
22. private JLabel firstNameLabel, lastNameLabel, titleLabel, organizationLabel;
23. private JTextField firstName, lastName, title, organization;
24. private JButton update, exit;
25.
26. public ContactEditView(ContactModel model){
27. controller = new ContactEditController(model, this);
28. createGui();
29. }
30. public ContactEditView(ContactModel model, ContactEditController newController){
31. controller = newController;
32. createGui();
33. }
34.
35. public void createGui(){
36. update = new JButton(UPDATE_BUTTON);
37. exit = new JButton(EXIT_BUTTON);
38.
39. firstNameLabel = new JLabel(CONTACT_FIRST_NAME);
40. lastNameLabel = new JLabel(CONTACT_LAST_NAME);
41. titleLabel = new JLabel(CONTACT_TITLE);
42. organizationLabel = new JLabel(CONTACT_ORG);
43.
44. firstName = new JTextField(FNAME_COL_WIDTH);
45. lastName = new JTextField(LNAME_COL_WIDTH);
46. title = new JTextField(TITLE_COL_WIDTH);
47. organization = new JTextField(ORG_COL_WIDTH);
48.
49. JPanel editPanel = new JPanel();
50. editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.X_AXIS));
51.
52. JPanel labelPanel = new JPanel();
53. labelPanel.setLayout(new GridLayout(0, 1));
54.
55. labelPanel.add(firstNameLabel);
56. labelPanel.add(lastNameLabel);
57. labelPanel.add(titleLabel);
58. labelPanel.add(organizationLabel);
59.
60. editPanel.add(labelPanel);
61.
62. JPanel fieldPanel = new JPanel();
63. fieldPanel.setLayout(new GridLayout(0, 1));
64.
65. fieldPanel.add(firstName);
66. fieldPanel.add(lastName);
67. fieldPanel.add(title);
68. fieldPanel.add(organization);
69.
70. editPanel.add(fieldPanel);
71.
72. JPanel controlPanel = new JPanel();
73. controlPanel.add(update);
74. controlPanel.add(exit);
75. update.addActionListener(controller);
76. exit.addActionListener(new ExitHandler());
77.
78. setLayout(new BorderLayout());
79. add(editPanel, BorderLayout.CENTER);
80. add(controlPanel, BorderLayout.SOUTH);
81. }
82.
83. public Object getUpdateRef(){ return update; }
84. public String getFirstName(){ return firstName.getText(); }
85. public String getLastName(){ return lastName.getText(); }
86. public String getTitle(){ return title.getText(); }
87. public String getOrganization(){ return organization.getText(); }
88.
89. public void refreshContactView(String newFirstName,
90. String newLastName, String newTitle,
91. String newOrganization){
92. firstName.setText(newFirstName);
93. lastName.setText(newLastName);
94. title.setText(newTitle);
95. organization.setText(newOrganization);
96. }
97.
98. private class ExitHandler implements ActionListener{
99. public void actionPerformed(ActionEvent event){
Search WWH ::




Custom Search