45
45
46
46
// HRK code: very messy code for calculating score. We can use this link to calculate scores. https://github.com/klucar/bowling
47
47
// Type of code smell: Long method.
48
- public class AddPartyView implements ActionListener , ListSelectionListener {
48
+ public class AddPartyView implements ListSelectionListener {
49
49
50
50
private int maxSize ;
51
51
@@ -58,17 +58,13 @@ public class AddPartyView implements ActionListener, ListSelectionListener {
58
58
private Integer lock ;
59
59
60
60
private ControlDeskView controlDesk ;
61
-
61
+ private AddPartyView addpartyView ;
62
62
private String selectedNick , selectedMember ;
63
- public void addButton (JButton mybutton ,JPanel myPanel ) {
64
- myPanel .setLayout (new FlowLayout ());
65
- mybutton .addActionListener (this );
66
- myPanel .add (mybutton );
67
-
68
- }
63
+
69
64
public AddPartyView (ControlDeskView controlDesk , int max ) {
70
65
71
66
this .controlDesk = controlDesk ;
67
+ this .addpartyView = this ;
72
68
maxSize = max ;
73
69
74
70
win = new JFrame ("Add Party" );
@@ -116,20 +112,57 @@ public AddPartyView(ControlDeskView controlDesk, int max) {
116
112
buttonPanel .setLayout (new GridLayout (4 , 1 ));
117
113
118
114
addPatron = new JButton ("Add to Party" );
115
+ addPatron .addActionListener (new ActionListener () {
116
+ @ Override
117
+ public void actionPerformed (ActionEvent e ) {
118
+ if (selectedNick != null && party .size () < maxSize ) {
119
+ if (party .contains (selectedNick )) {
120
+ System .err .println ("Member already in Party" );
121
+ } else {
122
+ party .add (selectedNick );
123
+ partyList .setListData (party );
124
+ }
125
+ }
126
+ }
127
+ });
119
128
JPanel addPatronPanel = new JPanel ();
120
- addButton (addPatron , addPatronPanel );
129
+ gview . addButton (addPatron , addPatronPanel );
121
130
122
131
remPatron = new JButton ("Remove Member" );
132
+ remPatron .addActionListener (new ActionListener () {
133
+ @ Override
134
+ public void actionPerformed (ActionEvent e ) {
135
+ if (selectedMember != null ) {
136
+ party .removeElement (selectedMember );
137
+ partyList .setListData (party );
138
+ }
139
+ }
140
+ });
123
141
JPanel remPatronPanel = new JPanel ();
124
- addButton (remPatron ,remPatronPanel );
142
+ gview . addButton (remPatron ,remPatronPanel );
125
143
126
144
newPatron = new JButton ("New Patron" );
145
+ newPatron .addActionListener (new ActionListener () {
146
+ @ Override
147
+ public void actionPerformed (ActionEvent e ) {
148
+ NewPatronView newPatron = new NewPatronView (addpartyView );
149
+ }
150
+ });
127
151
JPanel newPatronPanel = new JPanel ();
128
- addButton (newPatron , newPatronPanel );
152
+ gview . addButton (newPatron , newPatronPanel );
129
153
130
154
finished = new JButton ("Finished" );
155
+ finished .addActionListener (new ActionListener () {
156
+ @ Override
157
+ public void actionPerformed (ActionEvent e ) {
158
+ if ( party != null && party .size () > 0 ) {
159
+ controlDesk .updateAddParty (addpartyView );
160
+ }
161
+ win .hide ();
162
+ }
163
+ });
131
164
JPanel finishedPanel = new JPanel ();
132
- addButton (finished , finishedPanel );
165
+ gview . addButton (finished , finishedPanel );
133
166
134
167
buttonPanel .add (addPatronPanel );
135
168
buttonPanel .add (remPatronPanel );
@@ -154,34 +187,6 @@ public AddPartyView(ControlDeskView controlDesk, int max) {
154
187
155
188
}
156
189
157
- public void actionPerformed (ActionEvent e ) {
158
- if (e .getSource ().equals (addPatron )) {
159
- if (selectedNick != null && party .size () < maxSize ) {
160
- if (party .contains (selectedNick )) {
161
- System .err .println ("Member already in Party" );
162
- } else {
163
- party .add (selectedNick );
164
- partyList .setListData (party );
165
- }
166
- }
167
- }
168
- else if (e .getSource ().equals (remPatron )) {
169
- if (selectedMember != null ) {
170
- party .removeElement (selectedMember );
171
- partyList .setListData (party );
172
- }
173
- }
174
- else if (e .getSource ().equals (newPatron )) {
175
- NewPatronView newPatron = new NewPatronView ( this );
176
- }
177
- else if (e .getSource ().equals (finished )) {
178
- if ( party != null && party .size () > 0 ) {
179
- controlDesk .updateAddParty ( this );
180
- }
181
- win .hide ();
182
- }
183
-
184
- }
185
190
186
191
/**
187
192
* Handler for List actions
0 commit comments