Skip to content

Commit 4298b02

Browse files
authored
Update AddPartyView.java
1 parent 4b0177b commit 4298b02

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed

BowlingAlley/code/Views/AddPartyView.java

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
// HRK code: very messy code for calculating score. We can use this link to calculate scores. https://github.com/klucar/bowling
4747
// Type of code smell: Long method.
48-
public class AddPartyView implements ActionListener, ListSelectionListener {
48+
public class AddPartyView implements ListSelectionListener {
4949

5050
private int maxSize;
5151

@@ -58,17 +58,13 @@ public class AddPartyView implements ActionListener, ListSelectionListener {
5858
private Integer lock;
5959

6060
private ControlDeskView controlDesk;
61-
61+
private AddPartyView addpartyView;
6262
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+
6964
public AddPartyView(ControlDeskView controlDesk, int max) {
7065

7166
this.controlDesk = controlDesk;
67+
this.addpartyView = this;
7268
maxSize = max;
7369

7470
win = new JFrame("Add Party");
@@ -116,20 +112,57 @@ public AddPartyView(ControlDeskView controlDesk, int max) {
116112
buttonPanel.setLayout(new GridLayout(4, 1));
117113

118114
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+
});
119128
JPanel addPatronPanel = new JPanel();
120-
addButton(addPatron, addPatronPanel);
129+
gview.addButton(addPatron, addPatronPanel);
121130

122131
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+
});
123141
JPanel remPatronPanel = new JPanel();
124-
addButton(remPatron,remPatronPanel);
142+
gview.addButton(remPatron,remPatronPanel);
125143

126144
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+
});
127151
JPanel newPatronPanel = new JPanel();
128-
addButton(newPatron, newPatronPanel);
152+
gview.addButton(newPatron, newPatronPanel);
129153

130154
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+
});
131164
JPanel finishedPanel = new JPanel();
132-
addButton(finished, finishedPanel);
165+
gview.addButton(finished, finishedPanel);
133166

134167
buttonPanel.add(addPatronPanel);
135168
buttonPanel.add(remPatronPanel);
@@ -154,34 +187,6 @@ public AddPartyView(ControlDeskView controlDesk, int max) {
154187

155188
}
156189

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-
}
185190

186191
/**
187192
* Handler for List actions

0 commit comments

Comments
 (0)