diff --git a/EndGameReport.java b/EndGameReport.java index ebef2ce..1d03a9f 100644 --- a/EndGameReport.java +++ b/EndGameReport.java @@ -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; @@ -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); @@ -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); @@ -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 ) { @@ -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++ ) { @@ -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()); + } + } } diff --git a/EndGameReportClickEvent.java b/EndGameReportClickEvent.java deleted file mode 100644 index ba52186..0000000 --- a/EndGameReportClickEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; - -public class EndGameReportClickEvent implements ActionListener { - private EndGameReport endGameReport; - - EndGameReportClickEvent(EndGameReport endGameReport) { - this.endGameReport = endGameReport; - } - - public void actionPerformed(ActionEvent e) { - - } -} diff --git a/FinishedGameCommand.java b/FinishedGameCommand.java new file mode 100644 index 0000000..ff026cf --- /dev/null +++ b/FinishedGameCommand.java @@ -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); + } +} diff --git a/PrintGameCommand.java b/PrintGameCommand.java new file mode 100644 index 0000000..5793339 --- /dev/null +++ b/PrintGameCommand.java @@ -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()); + } +} diff --git a/SCOREHISTORY.DAT b/SCOREHISTORY.DAT index be3911d..76d8adb 100644 --- a/SCOREHISTORY.DAT +++ b/SCOREHISTORY.DAT @@ -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