Skip to content

Commit

Permalink
feat : EndGameReport 리팩토링
Browse files Browse the repository at this point in the history
커맨드 패턴 적용
  • Loading branch information
Kim-minseok123 committed May 30, 2023
1 parent b731dcc commit e621f1c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 36 deletions.
63 changes: 41 additions & 22 deletions EndGameReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
import java.util.*;
import java.text.*;

public class EndGameReport implements ActionListener, ListSelectionListener {
public class EndGameReport {

private ButtonCommand command;
private JFrame win;
private JButton printButton, finished;
private JList memberList;
Expand Down Expand Up @@ -48,10 +49,11 @@ public EndGameReport( String partyName, Party party ) {
while (iter.hasNext()){
myVector.add( ((Bowler)iter.next()).getNick() );
}
EndGameReportClickEvent listener = new EndGameReportClickEvent();
memberList = new JList(myVector);
memberList.setFixedCellWidth(120);
memberList.setVisibleRowCount(5);
memberList.addListSelectionListener(this);
memberList.addListSelectionListener(listener);
JScrollPane partyPane = new JScrollPane(memberList);
// partyPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
partyPanel.add(partyPane);
Expand All @@ -68,13 +70,13 @@ public EndGameReport( String partyName, Party party ) {
printButton = new JButton("Print Report");
JPanel printButtonPanel = new JPanel();
printButtonPanel.setLayout(new FlowLayout());
printButton.addActionListener(this);
printButton.addActionListener(listener);
printButtonPanel.add(printButton);

finished = new JButton("Finished");
JPanel finishedPanel = new JPanel();
finishedPanel.setLayout(new FlowLayout());
finished.addActionListener(this);
finished.addActionListener(listener);
finishedPanel.add(finished);

buttonPanel.add(printButton);
Expand All @@ -97,22 +99,12 @@ public EndGameReport( String partyName, Party party ) {

}

public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(printButton)) {
//Add selected to the vector.
retVal.add(selectedMember);
}
if (e.getSource().equals(finished)) {
win.hide();
result = 1;
}

}

public void valueChanged(ListSelectionEvent e) {
selectedMember =
((String) ((JList) e.getSource()).getSelectedValue());
}
public void setCommand(ButtonCommand command) {
this.command = command;
}
public void buttonPressed() {
command.execute();
}

public Vector getResult() {
while ( result == 0 ) {
Expand All @@ -126,9 +118,20 @@ public Vector getResult() {
}

public void destroy() {
win.hide();
win.setVisible(false);
}
public String getSelectMember() {
return selectedMember;
}
public void setResultNumber(int i) {
result = i;
}
public JFrame getWin(){
return win;
}
public Vector getretVal(){
return retVal;
}

public static void main( String args[] ) {
Vector bowlers = new Vector();
for ( int i=0; i<4; i++ ) {
Expand All @@ -138,6 +141,22 @@ public static void main( String args[] ) {
String partyName="wank";
EndGameReport e = new EndGameReport( partyName, party );
}
public class EndGameReportClickEvent implements ActionListener, ListSelectionListener {

public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(printButton)) {
setCommand(new PrintGameCommand(EndGameReport.this));
}
if (e.getSource().equals(finished)) {
setCommand(new FinishedGameCommand(EndGameReport.this));

}
buttonPressed();
}
public void valueChanged(ListSelectionEvent e) {
selectedMember =
((String) ((JList) e.getSource()).getSelectedValue());
}
}
}

14 changes: 0 additions & 14 deletions EndGameReportClickEvent.java

This file was deleted.

10 changes: 10 additions & 0 deletions FinishedGameCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class FinishedGameCommand implements ButtonCommand{
EndGameReport endGameReport;
public FinishedGameCommand(EndGameReport endGameReport){
this.endGameReport = endGameReport;
}
public void execute(){
endGameReport.getWin().setVisible(false);
endGameReport.setResultNumber(1);
}
}
9 changes: 9 additions & 0 deletions PrintGameCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class PrintGameCommand implements ButtonCommand{
EndGameReport endGameReport;
public PrintGameCommand(EndGameReport endGameReport){
this.endGameReport = endGameReport;
}
public void execute(){
endGameReport.getretVal().add(endGameReport.getSelectMember());
}
}
10 changes: 10 additions & 0 deletions SCOREHISTORY.DAT
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ Mike 16:26 4/2/2023 133
Jim 16:26 4/2/2023 127
Mike 16:28 4/2/2023 91
Jim 16:28 4/2/2023 111
Mike 16:43 4/2/2023 114
Jim 16:43 4/2/2023 114
Mike 16:44 4/2/2023 126
Tom 16:44 4/2/2023 128
Mike 16:45 4/2/2023 140
Tom 16:45 4/2/2023 110
Lana 18:4 4/2/2023 162
Tom 18:4 4/2/2023 109
Tom 18:9 4/2/2023 134
Jim 18:9 4/2/2023 101

0 comments on commit e621f1c

Please sign in to comment.