Skip to content

Commit

Permalink
Merge pull request #18 from lightorange0v0/jiyoon
Browse files Browse the repository at this point in the history
ControlDeskClickEvent, ControlDesk, BowlerFile, ExitProgramCommand 리팩토링
  • Loading branch information
Kim-minseok123 authored Jun 4, 2023
2 parents 552adb0 + 35accb8 commit d379975
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 35 deletions.
12 changes: 4 additions & 8 deletions ControlDesk.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public void run() {

try {
sleep(SLEEPMS);
} catch (Exception e) {}
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}

Expand All @@ -101,16 +103,10 @@ public void run() {
*
*/

private Bowler registerPatron(String nickName) {
public Bowler registerPatron(String nickName) {
return registrationManager.registerPatron(nickName);
}

//PartyQueueManager에서 사용하기 위한 public 메소드
public Bowler registerBowler(String nickName) {
return registerPatron(nickName);
}


/**
* Iterate through the available lanes and assign the paties in the wait queue if lanes are available.
*
Expand Down
47 changes: 22 additions & 25 deletions ControlDeskView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.*;

public class ControlDeskView implements ActionListener, ControlDeskObserver {
public class ControlDeskView implements ControlDeskObserver {

private JButton addParty, finished, assign;
private JFrame win;
Expand All @@ -44,6 +44,8 @@ public ControlDeskView(ControlDesk controlDesk, int maxMembers) {
this.maxMembers = maxMembers;
int numLanes = controlDesk.getNumLanes();

ControlDeskClickEvent listener = new ControlDeskClickEvent();

win = new JFrame("Control Desk");
win.getContentPane().setLayout(new BorderLayout());
((JPanel) win.getContentPane()).setOpaque(false);
Expand All @@ -55,16 +57,16 @@ public ControlDeskView(ControlDesk controlDesk, int maxMembers) {
JPanel controlsPanel = createPanel("Controls", new GridLayout(3, 1));

JPanel addPartyPanel = new JPanel();
addParty = createButton("Add Party", addPartyPanel, this);
addParty = createButton("Add Party", addPartyPanel, listener);
controlsPanel.add(addPartyPanel);

JPanel assignPanel = new JPanel();
assign = createButton("Assign Lanes", assignPanel, this);
assign = createButton("Assign Lanes", assignPanel, listener);
assignPanel.add(assign);
// controlsPanel.add(assignPanel);

JPanel finishedPanel = new JPanel();
finished = createButton("Finished", finishedPanel, this);
finished = createButton("Finished", finishedPanel, listener);
controlsPanel.add(finishedPanel);

// Lane Status Panel
Expand Down Expand Up @@ -138,27 +140,6 @@ private JPanel createPanel(String title, LayoutManager mgr){
return panel;
}

/**
* Handler for actionEvents
*
* @param e the ActionEvent that triggered the handler
*
*/

public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(addParty)) {
setCommand(new ControlDeskViewAddPartyCommand(this));
}
else if (e.getSource().equals(assign)) {
setCommand(new ControlDeskViewAssignCommand(this));
}
else if (e.getSource().equals(finished)) {
setCommand(new ExitProgramCommand(this));
}

buttonPressed();
}

// The Invoker holds a command and can use it to call a method
public void setCommand(ButtonCommand command) {
this.command = command;
Expand Down Expand Up @@ -201,4 +182,20 @@ public JFrame getWin() {
public ControlDesk getControlDesk() {
return controlDesk;
}

public class ControlDeskClickEvent implements ActionListener{
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(addParty)) {
setCommand(new ControlDeskViewAddPartyCommand(ControlDeskView.this));
}
else if (e.getSource().equals(assign)) {
setCommand(new ControlDeskViewAssignCommand(ControlDeskView.this));
}
else if (e.getSource().equals(finished)) {
setCommand(new ExitProgramCommand(ControlDeskView.this));
}

buttonPressed();
}
}
}
2 changes: 1 addition & 1 deletion ExitProgramCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public ExitProgramCommand(ControlDeskView theView) {

@Override
public void execute() {
theView.getWin().dispose();
theView.getWin().setVisible(false);
System.exit(0);
}
}
2 changes: 1 addition & 1 deletion PartyQueueManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public PartyQueueManager(ControlDesk controlDesk) {
public void addPartyQueue(Vector<String> partyNicks) {
Vector<Bowler> partyBowlers = new Vector<>();
for (String partyNick : partyNicks) {
Bowler newBowler = controlDesk.registerBowler(partyNick);
Bowler newBowler = controlDesk.registerPatron(partyNick);
partyBowlers.add(newBowler);
}
Party newParty = new Party(partyBowlers);
Expand Down

0 comments on commit d379975

Please sign in to comment.