diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..159e7f1 Binary files /dev/null and b/.DS_Store differ diff --git a/ballingSystem/src/AbortNewPatronCommand.java b/AbortNewPatronCommand.java similarity index 100% rename from ballingSystem/src/AbortNewPatronCommand.java rename to AbortNewPatronCommand.java diff --git a/AddPartyView.java b/AddPartyView.java index c1dd706..15e87f6 100644 --- a/AddPartyView.java +++ b/AddPartyView.java @@ -39,8 +39,7 @@ * */ -public class AddPartyView implements ActionListener, ListSelectionListener { - +public class AddPartyView { private int maxSize; private ButtonCommand command; private JFrame win; @@ -73,11 +72,12 @@ public AddPartyView(ControlDeskView controlDesk, int max) { party = new Vector(); Vector empty = new Vector(); empty.add("(Empty)"); - + + AddPartyViewClickEvent listener = new AddPartyViewClickEvent(); partyList = new JList(empty); partyList.setFixedCellWidth(120); partyList.setVisibleRowCount(5); - partyList.addListSelectionListener(this); + partyList.addListSelectionListener(listener); JScrollPane partyPane = new JScrollPane(partyList); // partyPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); partyPanel.add(partyPane); @@ -88,7 +88,7 @@ public AddPartyView(ControlDeskView controlDesk, int max) { bowlerPanel.setBorder(new TitledBorder("Bowler Database")); try { - bowlerdb = new Vector(BowlerFile.getBowlers()); + bowlerdb = new Vector(BowlerFile.getInstance().getBowlers()); } catch (Exception e) { System.err.println("File Error"); bowlerdb = new Vector(); @@ -99,7 +99,7 @@ public AddPartyView(ControlDeskView controlDesk, int max) { JScrollPane bowlerPane = new JScrollPane(allBowlers); bowlerPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - allBowlers.addListSelectionListener(this); + allBowlers.addListSelectionListener(listener); bowlerPanel.add(bowlerPane); // Button Panel @@ -108,10 +108,10 @@ public AddPartyView(ControlDeskView controlDesk, int max) { Insets buttonMargin = new Insets(4, 4, 4, 4); - addPatron = createButton("Add to Party", new JPanel()); - remPatron = createButton("Remove Member", new JPanel()); - newPatron = createButton("New Patron", new JPanel()); - finished = createButton("Finished", new JPanel()); + addPatron = createButton("Add to Party", new JPanel(), listener); + remPatron = createButton("Remove Member", new JPanel(), listener); + newPatron = createButton("New Patron", new JPanel(), listener); + finished = createButton("Finished", new JPanel(), listener); buttonPanel.add((JPanel) addPatron.getParent()); buttonPanel.add((JPanel) remPatron.getParent()); @@ -135,9 +135,9 @@ public AddPartyView(ControlDeskView controlDesk, int max) { win.setVisible(true); } - private JButton createButton(String buttonText, JPanel panel) { // 버튼 객체 생성 + private JButton createButton(String buttonText, JPanel panel, AddPartyViewClickEvent listener) { // 버튼 객체 생성 JButton button = new JButton(buttonText); - button.addActionListener(this); + button.addActionListener(listener); panel.setLayout(new FlowLayout()); panel.add(button); return button; @@ -148,92 +148,97 @@ public void setCommand(ButtonCommand command) { public void buttonPressed() { command.execute(); } - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(addPatron)) { - if (selectedNick != null && party.size() < maxSize) { - if (party.contains(selectedNick)) { - System.err.println("Member already in Party"); - } else { - party.add(selectedNick); - partyList.setListData(party); - } - } - } - if (e.getSource().equals(remPatron)) { - if (selectedMember != null) { - party.removeElement(selectedMember); - partyList.setListData(party); - } - } - if (e.getSource().equals(newPatron)) { - NewPatronView newPatron = new NewPatronView( this ); - } - if (e.getSource().equals(finished)) { - if ( party != null && party.size() > 0) { - controlDesk.updateAddParty( this ); - } - win.setVisible(false); - } - + public String getSelectedNick() { + return selectedNick; } - -/** - * Handler for List actions - * @param e the ListActionEvent that triggered the handler - */ - - public void valueChanged(ListSelectionEvent e) { - if (e.getSource().equals(allBowlers)) { - selectedNick = - ((String) ((JList) e.getSource()).getSelectedValue()); - } - if (e.getSource().equals(partyList)) { - selectedMember = - ((String) ((JList) e.getSource()).getSelectedValue()); - } + public String getSelectedMember() { + return selectedMember; } + public int getMaxSize() { + return maxSize; + } + public JList getPartyList() { + return partyList; + } + public JFrame getWindow() { + return win; + } + public ControlDeskView getControlDesk() { + return controlDesk; + } + /** + * Accessor for Party + */ -/** - * Accessor for Party - */ + public Vector getParty() { + return party; + } + /** + * Accessor for Party + */ public Vector getNames() { return party; } - -/** - * Called by NewPatronView to notify AddPartyView to update - * - * @param newPatron the NewPatronView that called this method - */ - - public void updateNewPatron(NewPatronView newPatron) { - try { - Bowler checkBowler = BowlerFile.getBowlerInfo( newPatron.getNick() ); - if ( checkBowler == null ) { - BowlerFile.putBowlerInfo( - newPatron.getNick(), - newPatron.getFull(), - newPatron.getEmail()); - bowlerdb = new Vector(BowlerFile.getBowlers()); - allBowlers.setListData(bowlerdb); - party.add(newPatron.getNick()); - partyList.setListData(party); - } else { - System.err.println( "A Bowler with that name already exists." ); + public class AddPartyViewClickEvent implements ActionListener, ListSelectionListener { + public void actionPerformed(ActionEvent e) { + if (e.getSource().equals(addPatron)) { + setCommand(new AddPatronCommand(AddPartyView.this)); + } + if (e.getSource().equals(remPatron)) { + setCommand(new RemovePatronCommand(AddPartyView.this)); + } + if (e.getSource().equals(newPatron)) { + setCommand(new NewPatronCommand(AddPartyView.this)); + } + if (e.getSource().equals(finished)) { + setCommand(new FinishedAddPartyCommand(AddPartyView.this)); } - } catch (Exception e2) { - System.err.println("File I/O Error"); + buttonPressed(); } - } - -/** - * Accessor for Party - */ + /** + * Handler for List actions + * @param e the ListActionEvent that triggered the handler + */ + + public void valueChanged(ListSelectionEvent e) { + if (e.getSource().equals(allBowlers)) { + selectedNick = + ((String) ((JList) e.getSource()).getSelectedValue()); + } + if (e.getSource().equals(partyList)) { + selectedMember = + ((String) ((JList) e.getSource()).getSelectedValue()); + } + } - public Vector getParty() { - return party; + /** + * Called by NewPatronView to notify AddPartyView to update + * + * @param newPatron the NewPatronView that called this method + */ + + public void updateNewPatron(NewPatronView newPatron) { + try { + Bowler checkBowler = BowlerFile.getInstance().getBowlerInfo( newPatron.getNick() ); + if ( checkBowler == null ) { + BowlerFile.getInstance().putBowlerInfo( + newPatron.getNick(), + newPatron.getFull(), + newPatron.getEmail()); + bowlerdb = new Vector(BowlerFile.getInstance().getBowlers()); + allBowlers.setListData(bowlerdb); + party.add(newPatron.getNick()); + partyList.setListData(party); + } else { + String errMsg = "A Bowler with that name already exists."; + System.err.println(errMsg); + JOptionPane.showMessageDialog(win, errMsg, "Error", JOptionPane.ERROR_MESSAGE); + } + } catch (Exception e2) { + System.err.println("File I/O Error"); + } + } } } diff --git a/ballingSystem/src/AddPatronCommand.java b/AddPatronCommand.java similarity index 100% rename from ballingSystem/src/AddPatronCommand.java rename to AddPatronCommand.java diff --git a/BOWLERS.DAT b/BOWLERS.DAT index d280245..a407a51 100644 --- a/BOWLERS.DAT +++ b/BOWLERS.DAT @@ -3,4 +3,3 @@ Jim J. R. Vallino jv@nowhere.net Tom T. R. Reichmayr tr@nowhere.net Lana L. R. Verschage lv@nowhere.net TomH T. Hilburn th@nowhere.net -yeonjoo yeonjoo yeonjoo@mail.com diff --git a/Bowler.java b/Bowler.java index 3702377..a3b82dd 100644 --- a/Bowler.java +++ b/Bowler.java @@ -54,16 +54,8 @@ public String getEmail ( ) { } public boolean equals ( Bowler b) { - boolean retval = true; - if ( !(nickName.equals(b.getNickName())) ) { - retval = false; - } - if ( !(fullName.equals(b.getFullName())) ) { - retval = false; - } - if ( !(email.equals(b.getEmail())) ) { - retval = false; - } - return retval; + return nickName.equals(b.getNickName()) + && fullName.equals(b.getFullName()) + && email.equals(b.getEmail()); } } \ No newline at end of file diff --git a/ballingSystem/src/BowlerDatabase.java b/BowlerDatabase.java similarity index 100% rename from ballingSystem/src/BowlerDatabase.java rename to BowlerDatabase.java diff --git a/BowlerFile.java b/BowlerFile.java index 5948804..d7123a9 100644 --- a/BowlerFile.java +++ b/BowlerFile.java @@ -22,11 +22,20 @@ import java.util.*; import java.io.*; -class BowlerFile { +class BowlerFile implements BowlerDatabase { /** The location of the bowelr database */ - private static String BOWLER_DAT = "BOWLERS.DAT"; + private static String BOWLER_DAT = "/Users/yeonjoo/Desktop/pattern_team/src/BOWLERS.DAT"; + private BowlerFile() {} + + private static class LazyHolder { + static final BowlerFile INSTANCE = new BowlerFile(); + } + + public static BowlerFile getInstance() { + return LazyHolder.INSTANCE; + } /** * Retrieves bowler information from the database and returns a Bowler objects with populated fields. * @@ -35,28 +44,28 @@ class BowlerFile { * @return a Bowler object * */ - - public static Bowler getBowlerInfo(String nickName) - throws IOException, FileNotFoundException { - - BufferedReader in = new BufferedReader(new FileReader(BOWLER_DAT)); - String data; - while ((data = in.readLine()) != null) { - // File format is nick\tfname\te-mail - String[] bowler = data.split("\t"); - if (nickName.equals(bowler[0])) { - System.out.println( - "Nick: " - + bowler[0] - + " Full: " - + bowler[1] - + " email: " - + bowler[2]); - return (new Bowler(bowler[0], bowler[1], bowler[2])); - } - } - System.out.println("Nick not found..."); - return null; + private static List readBowlersFromFile() throws IOException { + List bowlers = new ArrayList<>(); + + try (BufferedReader in = new BufferedReader(new FileReader(BOWLER_DAT))) { + String data; + while ((data = in.readLine()) != null) { + // File format is nick\tfname\te-mail + String[] bowler = data.split("\t"); + bowlers.add(bowler); + } + } + + return bowlers; + } + @Override + public Bowler getBowlerInfo(String nickName) throws IOException { + for (String[] bowler : readBowlersFromFile()) { + if (nickName.equals(bowler[0])) { + return new Bowler(bowler[0], bowler[1], bowler[2]); + } + } + return null; } /** @@ -67,8 +76,8 @@ public static Bowler getBowlerInfo(String nickName) * @param email the E-mail Address of the Bowler * */ - - public static void putBowlerInfo( + @Override + public void putBowlerInfo( String nickName, String fullName, String email) @@ -88,21 +97,13 @@ public static void putBowlerInfo( * @return a Vector of Strings * */ - - public static Vector getBowlers() - throws IOException, FileNotFoundException { - - Vector allBowlers = new Vector(); - - BufferedReader in = new BufferedReader(new FileReader(BOWLER_DAT)); - String data; - while ((data = in.readLine()) != null) { - // File format is nick\tfname\te-mail - String[] bowler = data.split("\t"); - //"Nick: bowler[0] Full: bowler[1] email: bowler[2] - allBowlers.add(bowler[0]); - } - return allBowlers; + @Override + public List getBowlers() throws IOException { + List allBowlers = new ArrayList<>(); + for (String[] bowler : readBowlersFromFile()) { + allBowlers.add(bowler[0]); + } + return allBowlers; } } \ No newline at end of file diff --git a/ControlDesk.java b/ControlDesk.java index c01ddb6..a5538ba 100644 --- a/ControlDesk.java +++ b/ControlDesk.java @@ -44,7 +44,6 @@ import java.io.*; class ControlDesk extends Thread { - /** The collection of Lanes */ private HashSet lanes; @@ -110,7 +109,7 @@ private Bowler registerPatron(String nickName) { try { // only one patron / nick.... no dupes, no checks - patron = BowlerFile.getBowlerInfo(nickName); + patron = BowlerFile.getInstance().getBowlerInfo(nickName); } catch (FileNotFoundException e) { System.err.println("Error..." + e); diff --git a/EndGameReport.java b/EndGameReport.java index ebef2ce..8aebbff 100644 --- a/EndGameReport.java +++ b/EndGameReport.java @@ -46,7 +46,7 @@ public EndGameReport( String partyName, Party party ) { Vector myVector = new Vector(); Iterator iter = (party.getMembers()).iterator(); while (iter.hasNext()){ - myVector.add( ((Bowler)iter.next()).getNick() ); + myVector.add( ((Bowler)iter.next()).getNickName() ); } memberList = new JList(myVector); memberList.setFixedCellWidth(120); diff --git a/ballingSystem/src/FinishedAddPartyCommand.java b/FinishedAddPartyCommand.java similarity index 100% rename from ballingSystem/src/FinishedAddPartyCommand.java rename to FinishedAddPartyCommand.java diff --git a/ballingSystem/src/FinishedNewPatronCommand.java b/FinishedNewPatronCommand.java similarity index 100% rename from ballingSystem/src/FinishedNewPatronCommand.java rename to FinishedNewPatronCommand.java diff --git a/Lane.java b/Lane.java index ff9006f..a2b7265 100644 --- a/Lane.java +++ b/Lane.java @@ -216,7 +216,7 @@ public void run() { try{ Date date = new Date(); String dateString = "" + date.getHours() + ":" + date.getMinutes() + " " + date.getMonth() + "/" + date.getDay() + "/" + (date.getYear() + 1900); - ScoreHistoryFile.addScore(currentThrower.getNick(), dateString, new Integer(cumulScores[bowlIndex][9]).toString()); + ScoreHistoryFile.addScore(currentThrower.getNickName(), dateString, new Integer(cumulScores[bowlIndex][9]).toString()); } catch (Exception e) {System.err.println("Exception in addScore. "+ e );} } diff --git a/LaneView.java b/LaneView.java index 4062a61..ef93188 100644 --- a/LaneView.java +++ b/LaneView.java @@ -103,7 +103,7 @@ private JPanel makeFrame(Party party) { pins[i] = new JPanel(); pins[i].setBorder( BorderFactory.createTitledBorder( - ((Bowler) bowlers.get(i)).getNick())); + ((Bowler) bowlers.get(i)).getNickName())); pins[i].setLayout(new GridLayout(0, 10)); for (int k = 0; k != 10; k++) { scores[i][k] = new JPanel(); diff --git a/ballingSystem/src/NewPatronCommand.java b/NewPatronCommand.java similarity index 100% rename from ballingSystem/src/NewPatronCommand.java rename to NewPatronCommand.java diff --git a/NewPatronView.java b/NewPatronView.java index 2a74278..4404805 100644 --- a/NewPatronView.java +++ b/NewPatronView.java @@ -22,13 +22,14 @@ import javax.swing.border.*; import javax.swing.event.*; + import java.util.*; import java.text.*; -public class NewPatronView implements ActionListener { - +public class NewPatronView { + private static final int TEXT_FIELD_SIZE = 15; private int maxSize; - + private ButtonCommand command; private JFrame win; private JButton abort, finished; private JLabel nickLabel, fullLabel, emailLabel; @@ -57,30 +58,19 @@ public NewPatronView(AddPartyView v) { patronPanel.setLayout(new GridLayout(3, 1)); patronPanel.setBorder(new TitledBorder("Your Info")); - JPanel nickPanel = new JPanel(); - nickPanel.setLayout(new FlowLayout()); - nickLabel = new JLabel("Nick Name"); - nickField = new JTextField("", 15); - nickPanel.add(nickLabel); - nickPanel.add(nickField); - - JPanel fullPanel = new JPanel(); - fullPanel.setLayout(new FlowLayout()); - fullLabel = new JLabel("Full Name"); - fullField = new JTextField("", 15); - fullPanel.add(fullLabel); - fullPanel.add(fullField); - - JPanel emailPanel = new JPanel(); - emailPanel.setLayout(new FlowLayout()); - emailLabel = new JLabel("E-Mail"); - emailField = new JTextField("", 15); - emailPanel.add(emailLabel); - emailPanel.add(emailField); - - patronPanel.add(nickPanel); - patronPanel.add(fullPanel); - patronPanel.add(emailPanel); + nickField = new JTextField("", TEXT_FIELD_SIZE); + JPanel nickPanel = createFieldPanel("Nick Name", nickField); + + fullField = new JTextField("", TEXT_FIELD_SIZE); + JPanel fullPanel = createFieldPanel("Full Name", fullField); + + emailField = new JTextField("", TEXT_FIELD_SIZE); + JPanel emailPanel = createFieldPanel("E-Mail", emailField); + + NewPatronViewClickEvent listener = new NewPatronViewClickEvent(); + patronPanel.add(nickPanel); + patronPanel.add(fullPanel); + patronPanel.add(emailPanel); // Button Panel JPanel buttonPanel = new JPanel(); @@ -88,20 +78,11 @@ public NewPatronView(AddPartyView v) { Insets buttonMargin = new Insets(4, 4, 4, 4); - finished = new JButton("Add Patron"); - JPanel finishedPanel = new JPanel(); - finishedPanel.setLayout(new FlowLayout()); - finished.addActionListener(this); - finishedPanel.add(finished); - - abort = new JButton("Abort"); - JPanel abortPanel = new JPanel(); - abortPanel.setLayout(new FlowLayout()); - abort.addActionListener(this); - abortPanel.add(abort); + finished = createButton("Add Patron", new JPanel(), listener); + abort = createButton("Abort", new JPanel(), listener); - buttonPanel.add(abortPanel); - buttonPanel.add(finishedPanel); + buttonPanel.add((JPanel) finished.getParent()); + buttonPanel.add((JPanel) abort.getParent()); // Clean up main panel colPanel.add(patronPanel, "Center"); @@ -116,41 +97,88 @@ public NewPatronView(AddPartyView v) { win.setLocation( ((screenSize.width) / 2) - ((win.getSize().width) / 2), ((screenSize.height) / 2) - ((win.getSize().height) / 2)); - win.show(); + win.setVisible(true); } - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(abort)) { - done = true; - win.hide(); - } - - if (e.getSource().equals(finished)) { - nick = nickField.getText(); - full = fullField.getText(); - email = emailField.getText(); - done = true; - addParty.updateNewPatron( this ); - win.hide(); - } - + private JPanel createFieldPanel(String labelText, JTextField textField) { + JPanel panel = new JPanel(); + panel.setLayout(new FlowLayout()); + JLabel label = new JLabel(labelText); + panel.add(label); + panel.add(textField); + return panel; + } + private JButton createButton(String buttonText, JPanel panel, NewPatronViewClickEvent listener) { // 버튼 객체 생성 + JButton button = new JButton(buttonText); + button.addActionListener(listener); + panel.setLayout(new FlowLayout()); + panel.add(button); + return button; } - + public void setCommand(ButtonCommand command) { + this.command = command; + } + public void buttonPressed() { + command.execute(); + } public boolean done() { return done; } - + public void setDone(boolean done) { + this.done = done; + } public String getNick() { return nick; } - + public void setNick(String nick) { + this.nick = nick; + } public String getFull() { return full; } - + public void setFull(String full) { + this.full = full; + } public String getEmail() { return email; } - + public void setEmail(String email) { + this.email = email; + } + public JFrame getWindow() { + return win; + } + public JTextField getNickField() { + return nickField; + } + public JTextField getFullField() { + return fullField; + } + public JTextField getEmailField() { + return emailField; + } + public AddPartyView getAddParty() { + return addParty; + } + public class NewPatronViewClickEvent implements ActionListener { + public void actionPerformed(ActionEvent e) { + if (e.getSource().equals(abort)) { + setCommand(new AbortNewPatronCommand(NewPatronView.this)); + } + + if (e.getSource().equals(finished)) { + nick = nickField.getText(); + full = fullField.getText(); + email = emailField.getText(); + done = true; + if (nick.isEmpty() || full.isEmpty() || email.isEmpty()) { + // 예외 상황(아무 정보도 입력 안 한 상태)에 대해 사용자에게 메시지를 보여주는 코드 추가 + JOptionPane.showMessageDialog(win, "All fields must be filled out.", "Error", JOptionPane.ERROR_MESSAGE); + } else { + setCommand(new FinishedNewPatronCommand(NewPatronView.this)); + } + } + buttonPressed(); + } + } } diff --git a/Party.java b/Party.java index ffee79e..ac083d3 100644 --- a/Party.java +++ b/Party.java @@ -27,7 +27,7 @@ public class Party { /** Vector of bowlers in this party */ - private Vector myBowlers; + private Vector myBowlers; /** * Constructor for a Party @@ -35,8 +35,8 @@ public class Party { * @param bowlers Vector of bowlers that are in this party */ - public Party( Vector bowlers ) { - myBowlers = new Vector(bowlers); + public Party( Vector bowlers ) { + myBowlers = new Vector(bowlers); } /** @@ -45,7 +45,7 @@ public Party( Vector bowlers ) { * @return A vector of the bowlers in this party */ - public Vector getMembers() { + public Vector getMembers() { return myBowlers; } diff --git a/ballingSystem/src/RemovePatronCommand.java b/RemovePatronCommand.java similarity index 100% rename from ballingSystem/src/RemovePatronCommand.java rename to RemovePatronCommand.java diff --git a/ScoreHistoryFile.java b/ScoreHistoryFile.java index d765354..c257b9f 100644 --- a/ScoreHistoryFile.java +++ b/ScoreHistoryFile.java @@ -11,7 +11,7 @@ public class ScoreHistoryFile { - private static String SCOREHISTORY_DAT = "SCOREHISTORY.DAT"; + private static String SCOREHISTORY_DAT = "/Users/yeonjoo/Desktop/pattern_team/src/SCOREHISTORY.DAT"; public static void addScore(String nick, String date, String score) throws IOException, FileNotFoundException { diff --git a/ScoreReport.java b/ScoreReport.java index 00f135a..50b1cd4 100644 --- a/ScoreReport.java +++ b/ScoreReport.java @@ -1,6 +1,6 @@ /** * - * SMTP implementation based on code by Ral Gagnon mailto:real@rgagnon.com + * SMTP implementation based on code by R�al Gagnon mailto:real@rgagnon.com * */ @@ -17,7 +17,7 @@ public class ScoreReport { private String content; public ScoreReport( Bowler bowler, int[] scores, int games ) { - String nick = bowler.getNick(); + String nick = bowler.getNickName(); String full = bowler.getFullName(); Vector v = null; try{ diff --git a/ballingSystem/.classpath b/ballingSystem/.classpath deleted file mode 100644 index 51a8bba..0000000 --- a/ballingSystem/.classpath +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/ballingSystem/.gitignore b/ballingSystem/.gitignore deleted file mode 100644 index ae3c172..0000000 --- a/ballingSystem/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/ballingSystem/.project b/ballingSystem/.project deleted file mode 100644 index adc719b..0000000 --- a/ballingSystem/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - ballingSystem - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/ballingSystem/.settings/org.eclipse.core.resources.prefs b/ballingSystem/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c0..0000000 --- a/ballingSystem/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/=UTF-8 diff --git a/ballingSystem/.settings/org.eclipse.jdt.core.prefs b/ballingSystem/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index af07d5f..0000000 --- a/ballingSystem/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.release=enabled -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/ballingSystem/src/AddPartyView.java b/ballingSystem/src/AddPartyView.java deleted file mode 100644 index 6c11e87..0000000 --- a/ballingSystem/src/AddPartyView.java +++ /dev/null @@ -1,245 +0,0 @@ -/* AddPartyView.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: AddPartyView.java,v $ - * Revision 1.7 2003/02/20 02:05:53 ??? - * Fixed addPatron so that duplicates won't be created. - * - * Revision 1.6 2003/02/09 20:52:46 ??? - * Added comments. - * - * Revision 1.5 2003/02/02 17:42:09 ??? - * Made updates to migrate to observer model. - * - * Revision 1.4 2003/02/02 16:29:52 ??? - * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. - * - * - */ - -/** - * Class for GUI components need to add a party - * - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - -import java.util.*; -import java.text.*; - -/** - * Constructor for GUI used to Add Parties to the waiting party queue. - * - */ - -public class AddPartyView { - - private int maxSize; - private ButtonCommand command; - private JFrame win; - private JButton addPatron, newPatron, remPatron, finished; - private JList partyList, allBowlers; - private Vector party, bowlerdb; - private Integer lock; - - private ControlDeskView controlDesk; - - private String selectedNick, selectedMember; - - public AddPartyView(ControlDeskView controlDesk, int max) { - - this.controlDesk = controlDesk; - maxSize = max; - - win = new JFrame("Add Party"); - win.getContentPane().setLayout(new BorderLayout()); - ((JPanel) win.getContentPane()).setOpaque(false); - - JPanel colPanel = new JPanel(); - colPanel.setLayout(new GridLayout(1, 3)); - - // Party Panel - JPanel partyPanel = new JPanel(); - partyPanel.setLayout(new FlowLayout()); - partyPanel.setBorder(new TitledBorder("Your Party")); - - party = new Vector(); - Vector empty = new Vector(); - empty.add("(Empty)"); - - AddPartyViewClickEvent listener = new AddPartyViewClickEvent(); - partyList = new JList(empty); - partyList.setFixedCellWidth(120); - partyList.setVisibleRowCount(5); - partyList.addListSelectionListener(listener); - JScrollPane partyPane = new JScrollPane(partyList); - // partyPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - partyPanel.add(partyPane); - - // Bowler Database - JPanel bowlerPanel = new JPanel(); - bowlerPanel.setLayout(new FlowLayout()); - bowlerPanel.setBorder(new TitledBorder("Bowler Database")); - - try { - bowlerdb = new Vector(BowlerFile.getInstance().getBowlers()); - } catch (Exception e) { - System.err.println("File Error"); - bowlerdb = new Vector(); - } - allBowlers = new JList(bowlerdb); - allBowlers.setVisibleRowCount(8); - allBowlers.setFixedCellWidth(120); - JScrollPane bowlerPane = new JScrollPane(allBowlers); - bowlerPane.setVerticalScrollBarPolicy( - JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - allBowlers.addListSelectionListener(listener); - bowlerPanel.add(bowlerPane); - - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new GridLayout(4, 1)); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - addPatron = createButton("Add to Party", new JPanel(), listener); - remPatron = createButton("Remove Member", new JPanel(), listener); - newPatron = createButton("New Patron", new JPanel(), listener); - finished = createButton("Finished", new JPanel(), listener); - - buttonPanel.add((JPanel) addPatron.getParent()); - buttonPanel.add((JPanel) remPatron.getParent()); - buttonPanel.add((JPanel) newPatron.getParent()); - buttonPanel.add((JPanel) finished.getParent()); - - // Clean up main panel - colPanel.add(partyPanel); - colPanel.add(bowlerPanel); - colPanel.add(buttonPanel); - - win.getContentPane().add("Center", colPanel); - - win.pack(); - - // Center Window on Screen - Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); - win.setLocation( - ((screenSize.width) / 2) - ((win.getSize().width) / 2), - ((screenSize.height) / 2) - ((win.getSize().height) / 2)); - win.setVisible(true); - - } - private JButton createButton(String buttonText, JPanel panel, AddPartyViewClickEvent listener) { // 버튼 객체 생성 - JButton button = new JButton(buttonText); - button.addActionListener(listener); - panel.setLayout(new FlowLayout()); - panel.add(button); - return button; - } - public void setCommand(ButtonCommand command) { - this.command = command; - } - public void buttonPressed() { - command.execute(); - } - public String getSelectedNick() { - return selectedNick; - } - public String getSelectedMember() { - return selectedMember; - } - public int getMaxSize() { - return maxSize; - } - public JList getPartyList() { - return partyList; - } - public JFrame getWindow() { - return win; - } - public ControlDeskView getControlDesk() { - return controlDesk; - } - /** - * Accessor for Party - */ - - public Vector getParty() { - return party; - } - /** - * Accessor for Party - */ - - public Vector getNames() { - return party; - } - public class AddPartyViewClickEvent implements ActionListener, ListSelectionListener { - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(addPatron)) { - setCommand(new AddPatronCommand(AddPartyView.this)); - } - if (e.getSource().equals(remPatron)) { - setCommand(new RemovePatronCommand(AddPartyView.this)); - } - if (e.getSource().equals(newPatron)) { - setCommand(new NewPatronCommand(AddPartyView.this)); - } - if (e.getSource().equals(finished)) { - setCommand(new FinishedAddPartyCommand(AddPartyView.this)); - } - buttonPressed(); - } - /** - * Handler for List actions - * @param e the ListActionEvent that triggered the handler - */ - - public void valueChanged(ListSelectionEvent e) { - if (e.getSource().equals(allBowlers)) { - selectedNick = - ((String) ((JList) e.getSource()).getSelectedValue()); - } - if (e.getSource().equals(partyList)) { - selectedMember = - ((String) ((JList) e.getSource()).getSelectedValue()); - } - } - - /** - * Called by NewPatronView to notify AddPartyView to update - * - * @param newPatron the NewPatronView that called this method - */ - - public void updateNewPatron(NewPatronView newPatron) { - try { - Bowler checkBowler = BowlerFile.getInstance().getBowlerInfo( newPatron.getNick() ); - if ( checkBowler == null ) { - BowlerFile.getInstance().putBowlerInfo( - newPatron.getNick(), - newPatron.getFull(), - newPatron.getEmail()); - bowlerdb = new Vector(BowlerFile.getInstance().getBowlers()); - allBowlers.setListData(bowlerdb); - party.add(newPatron.getNick()); - partyList.setListData(party); - } else { - String errMsg = "A Bowler with that name already exists."; - System.err.println(errMsg); - JOptionPane.showMessageDialog(win, errMsg, "Error", JOptionPane.ERROR_MESSAGE); - } - } catch (Exception e2) { - System.err.println("File I/O Error"); - } - } - } - -} diff --git a/ballingSystem/src/AgainGameCommand.java b/ballingSystem/src/AgainGameCommand.java deleted file mode 100644 index 5574519..0000000 --- a/ballingSystem/src/AgainGameCommand.java +++ /dev/null @@ -1,9 +0,0 @@ -public class AgainGameCommand implements ButtonCommand { - EndGamePrompt endGamePrompt; - public AgainGameCommand(EndGamePrompt endGamePrompt){ - this.endGamePrompt = endGamePrompt; - } - public void execute(){ - endGamePrompt.setResult(1); - } -} diff --git a/ballingSystem/src/Alley.java b/ballingSystem/src/Alley.java deleted file mode 100644 index 2cc1209..0000000 --- a/ballingSystem/src/Alley.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Alley.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: Alley.java,v $ - * Revision 1.4 2003/02/02 20:28:58 ??? - * fixed sleep thread bug in lane - * - * Revision 1.3 2003/01/12 22:23:32 ??? - * *** empty log message *** - * - * Revision 1.2 2003/01/12 20:44:30 ??? - * *** empty log message *** - * - * Revision 1.1 2003/01/12 19:09:12 ??? - * Adding Party, Lane, Bowler, and Alley. - * - */ - -/** - * Class that is the outer container for the bowling sim - * - */ - -public class Alley { - public ControlDesk controldesk; - - public Alley( int numLanes ) { - controldesk = new ControlDesk( numLanes ); - } - - public ControlDesk getControlDesk() { - return controldesk; - } - -} - - - diff --git a/ballingSystem/src/BOWLERS.DAT b/ballingSystem/src/BOWLERS.DAT deleted file mode 100644 index a407a51..0000000 --- a/ballingSystem/src/BOWLERS.DAT +++ /dev/null @@ -1,5 +0,0 @@ -Mike M. J. Lutz ml@nowhere.net -Jim J. R. Vallino jv@nowhere.net -Tom T. R. Reichmayr tr@nowhere.net -Lana L. R. Verschage lv@nowhere.net -TomH T. Hilburn th@nowhere.net diff --git a/ballingSystem/src/Bowler.java b/ballingSystem/src/Bowler.java deleted file mode 100644 index a3b82dd..0000000 --- a/ballingSystem/src/Bowler.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Bowler.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: Bowler.java,v $ - * Revision 1.3 2003/01/15 02:57:40 ??? - * Added accessors and and equals() method - * - * Revision 1.2 2003/01/12 22:23:32 ??? - * *** empty log message *** - * - * Revision 1.1 2003/01/12 19:09:12 ??? - * Adding Party, Lane, Bowler, and Alley. - * - */ - -/** - * Class that holds all bowler info - * - */ - -public class Bowler { - - private String fullName; - private String nickName; - private String email; - - public Bowler( String nick, String full, String mail ) { - nickName = nick; - fullName = full; - email = mail; - } - - - public String getNickName() { - - return nickName; - - } - - public String getFullName ( ) { - return fullName; - } - - public String getNick ( ) { - return nickName; - } - - public String getEmail ( ) { - return email; - } - - public boolean equals ( Bowler b) { - return nickName.equals(b.getNickName()) - && fullName.equals(b.getFullName()) - && email.equals(b.getEmail()); - } -} \ No newline at end of file diff --git a/ballingSystem/src/BowlerFile.java b/ballingSystem/src/BowlerFile.java deleted file mode 100644 index 92f82d3..0000000 --- a/ballingSystem/src/BowlerFile.java +++ /dev/null @@ -1,109 +0,0 @@ -/* BowlerFile.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: BowlerFile.java,v $ - * Revision 1.5 2003/02/02 17:36:45 ??? - * Updated comments to match javadoc format. - * - * Revision 1.4 2003/02/02 16:29:52 ??? - * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. - * - * - */ - -/** - * Class for interfacing with Bowler database - * - */ - -import java.util.*; -import java.io.*; - -class BowlerFile implements BowlerDatabase { - - /** The location of the bowelr database */ - private static String BOWLER_DAT = "/Users/yeonjoo/git/BallingManagementSystem_refactoring/BOWLERS.DAT"; - - private BowlerFile() {} - - private static class LazyHolder { - static final BowlerFile INSTANCE = new BowlerFile(); - } - - public static BowlerFile getInstance() { - return LazyHolder.INSTANCE; - } - /** - * Retrieves bowler information from the database and returns a Bowler objects with populated fields. - * - * @param nickName the nickName of the bolwer to retrieve - * - * @return a Bowler object - * - */ - private static List readBowlersFromFile() throws IOException { - List bowlers = new ArrayList<>(); - - try (BufferedReader in = new BufferedReader(new FileReader(BOWLER_DAT))) { - String data; - while ((data = in.readLine()) != null) { - // File format is nick\tfname\te-mail - String[] bowler = data.split("\t"); - bowlers.add(bowler); - } - } - - return bowlers; - } - @Override - public Bowler getBowlerInfo(String nickName) throws IOException { - for (String[] bowler : readBowlersFromFile()) { - if (nickName.equals(bowler[0])) { - return new Bowler(bowler[0], bowler[1], bowler[2]); - } - } - return null; - } - - /** - * Stores a Bowler in the database - * - * @param nickName the NickName of the Bowler - * @param fullName the FullName of the Bowler - * @param email the E-mail Address of the Bowler - * - */ - @Override - public void putBowlerInfo( - String nickName, - String fullName, - String email) - throws IOException, FileNotFoundException { - - String data = nickName + "\t" + fullName + "\t" + email + "\n"; - - RandomAccessFile out = new RandomAccessFile(BOWLER_DAT, "rw"); - out.skipBytes((int) out.length()); - out.writeBytes(data); - out.close(); - } - - /** - * Retrieves a list of nicknames in the bowler database - * - * @return a Vector of Strings - * - */ - @Override - public List getBowlers() throws IOException { - List allBowlers = new ArrayList<>(); - for (String[] bowler : readBowlersFromFile()) { - allBowlers.add(bowler[0]); - } - return allBowlers; - } - -} \ No newline at end of file diff --git a/ballingSystem/src/ButtonCommand.java b/ballingSystem/src/ButtonCommand.java deleted file mode 100644 index 8193cdd..0000000 --- a/ballingSystem/src/ButtonCommand.java +++ /dev/null @@ -1,3 +0,0 @@ -public interface ButtonCommand { - public void execute(); -} diff --git a/ballingSystem/src/ControlDesk.java b/ballingSystem/src/ControlDesk.java deleted file mode 100644 index a5538ba..0000000 --- a/ballingSystem/src/ControlDesk.java +++ /dev/null @@ -1,236 +0,0 @@ -/* ControlDesk.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: ControlDesk.java,v $ - * Revision 1.13 2003/02/02 23:26:32 ??? - * ControlDesk now runs its own thread and polls for free lanes to assign queue members to - * - * Revision 1.12 2003/02/02 20:46:13 ??? - * Added " 's Party" to party names. - * - * Revision 1.11 2003/02/02 20:43:25 ??? - * misc cleanup - * - * Revision 1.10 2003/02/02 17:49:10 ??? - * Fixed problem in getPartyQueue that was returning the first element as every element. - * - * Revision 1.9 2003/02/02 17:39:48 ??? - * Added accessor for lanes. - * - * Revision 1.8 2003/02/02 16:53:59 ??? - * Updated comments to match javadoc format. - * - * Revision 1.7 2003/02/02 16:29:52 ??? - * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. - * - * Revision 1.6 2003/02/02 06:09:39 ??? - * Updated many classes to support the ControlDeskView. - * - * Revision 1.5 2003/01/26 23:16:10 ??? - * Improved thread handeling in lane/controldesk - * - * - */ - -/** - * Class that represents control desk - * - */ - -import java.util.*; -import java.io.*; - -class ControlDesk extends Thread { - /** The collection of Lanes */ - private HashSet lanes; - - /** The party wait queue */ - private Queue partyQueue; - - /** The number of lanes represented */ - private int numLanes; - - /** The collection of subscribers */ - private Vector subscribers; - - /** - * Constructor for the ControlDesk class - * - * @param numlanes the numbler of lanes to be represented - * - */ - - public ControlDesk(int numLanes) { - this.numLanes = numLanes; - lanes = new HashSet(numLanes); - partyQueue = new Queue(); - - subscribers = new Vector(); - - for (int i = 0; i < numLanes; i++) { - lanes.add(new Lane()); - } - - this.start(); - - } - - /** - * Main loop for ControlDesk's thread - * - */ - public void run() { - while (true) { - - assignLane(); - - try { - sleep(250); - } catch (Exception e) {} - } - } - - - /** - * Retrieves a matching Bowler from the bowler database. - * - * @param nickName The NickName of the Bowler - * - * @return a Bowler object. - * - */ - - private Bowler registerPatron(String nickName) { - Bowler patron = null; - - try { - // only one patron / nick.... no dupes, no checks - - patron = BowlerFile.getInstance().getBowlerInfo(nickName); - - } catch (FileNotFoundException e) { - System.err.println("Error..." + e); - } catch (IOException e) { - System.err.println("Error..." + e); - } - - return patron; - } - - /** - * Iterate through the available lanes and assign the paties in the wait queue if lanes are available. - * - */ - - public void assignLane() { - Iterator it = lanes.iterator(); - - while (it.hasNext() && partyQueue.hasMoreElements()) { - Lane curLane = (Lane) it.next(); - - if (curLane.isPartyAssigned() == false) { - System.out.println("ok... assigning this party"); - curLane.assignParty(((Party) partyQueue.next())); - } - } - publish(new ControlDeskEvent(getPartyQueue())); - } - - /** - */ - - public void viewScores(Lane ln) { - // TODO: attach a LaneScoreView object to that lane - } - - /** - * Creates a party from a Vector of nickNAmes and adds them to the wait queue. - * - * @param partyNicks A Vector of NickNames - * - */ - - public void addPartyQueue(Vector partyNicks) { - Vector partyBowlers = new Vector(); - for (int i = 0; i < partyNicks.size(); i++) { - Bowler newBowler = registerPatron(((String) partyNicks.get(i))); - partyBowlers.add(newBowler); - } - Party newParty = new Party(partyBowlers); - partyQueue.add(newParty); - publish(new ControlDeskEvent(getPartyQueue())); - } - - /** - * Returns a Vector of party names to be displayed in the GUI representation of the wait queue. - * - * @return a Vecotr of Strings - * - */ - - public Vector getPartyQueue() { - Vector displayPartyQueue = new Vector(); - for ( int i=0; i < ( (Vector)partyQueue.asVector()).size(); i++ ) { - String nextParty = - ((Bowler) ((Vector) ((Party) partyQueue.asVector().get( i ) ).getMembers()) - .get(0)) - .getNickName() + "'s Party"; - displayPartyQueue.addElement(nextParty); - } - return displayPartyQueue; - } - - /** - * Accessor for the number of lanes represented by the ControlDesk - * - * @return an int containing the number of lanes represented - * - */ - - public int getNumLanes() { - return numLanes; - } - - /** - * Allows objects to subscribe as observers - * - * @param adding the ControlDeskObserver that will be subscribed - * - */ - - public void subscribe(ControlDeskObserver adding) { - subscribers.add(adding); - } - - /** - * Broadcast an event to subscribing objects. - * - * @param event the ControlDeskEvent to broadcast - * - */ - - public void publish(ControlDeskEvent event) { - Iterator eventIterator = subscribers.iterator(); - while (eventIterator.hasNext()) { - ( - (ControlDeskObserver) eventIterator - .next()) - .receiveControlDeskEvent( - event); - } - } - - /** - * Accessor method for lanes - * - * @return a HashSet of Lanes - * - */ - - public HashSet getLanes() { - return lanes; - } -} diff --git a/ballingSystem/src/ControlDeskEvent.java b/ballingSystem/src/ControlDeskEvent.java deleted file mode 100644 index fe74ca3..0000000 --- a/ballingSystem/src/ControlDeskEvent.java +++ /dev/null @@ -1,46 +0,0 @@ -/* ControlDeskEvent.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log$ - * - */ - -/** - * Class that represents control desk event - * - */ - -import java.util.*; - -public class ControlDeskEvent { - - /** A representation of the wait queue, containing party names */ - private Vector partyQueue; - - /** - * Contstructor for the ControlDeskEvent - * - * @param partyQueue a Vector of Strings containing the names of the parties in the wait queue - * - */ - - public ControlDeskEvent( Vector partyQueue ) { - this.partyQueue = partyQueue; - } - - /** - * Accessor for partyQueue - * @param key the key of the vertex being looked for. - * - * @return a Vector of Strings representing the names of the parties in the wait queue - * - */ - - public Vector getPartyQueue() { - return partyQueue; - } - -} diff --git a/ballingSystem/src/ControlDeskObserver.java b/ballingSystem/src/ControlDeskObserver.java deleted file mode 100644 index 2fe1781..0000000 --- a/ballingSystem/src/ControlDeskObserver.java +++ /dev/null @@ -1,20 +0,0 @@ -/* ControlDeskObserver.java - * - * Version - * $Id$ - * - * Revisions: - * $Log$ - * - */ - -/** - * Interface for classes that observe control desk events - * - */ - -public interface ControlDeskObserver { - - public void receiveControlDeskEvent(ControlDeskEvent ce); - -} diff --git a/ballingSystem/src/ControlDeskView.java b/ballingSystem/src/ControlDeskView.java deleted file mode 100644 index c66fe40..0000000 --- a/ballingSystem/src/ControlDeskView.java +++ /dev/null @@ -1,180 +0,0 @@ -/* ControlDeskView.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log$ - * - */ - -/** - * Class for representation of the control desk - * - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - -import java.util.*; - -public class ControlDeskView implements ActionListener, ControlDeskObserver { - - private JButton addParty, finished, assign; - private JFrame win; - private JList partyList; - - /** The maximum number of members in a party */ - private int maxMembers; - - private ControlDesk controlDesk; - - /** - * Displays a GUI representation of the ControlDesk - * - */ - - public ControlDeskView(ControlDesk controlDesk, int maxMembers) { - - this.controlDesk = controlDesk; - this.maxMembers = maxMembers; - int numLanes = controlDesk.getNumLanes(); - - win = new JFrame("Control Desk"); - win.getContentPane().setLayout(new BorderLayout()); - ((JPanel) win.getContentPane()).setOpaque(false); - - JPanel colPanel = new JPanel(); - colPanel.setLayout(new BorderLayout()); - - // Controls Panel - JPanel controlsPanel = new JPanel(); - controlsPanel.setLayout(new GridLayout(3, 1)); - controlsPanel.setBorder(new TitledBorder("Controls")); - - addParty = new JButton("Add Party"); - JPanel addPartyPanel = new JPanel(); - addPartyPanel.setLayout(new FlowLayout()); - addParty.addActionListener(this); - addPartyPanel.add(addParty); - controlsPanel.add(addPartyPanel); - - assign = new JButton("Assign Lanes"); - JPanel assignPanel = new JPanel(); - assignPanel.setLayout(new FlowLayout()); - assign.addActionListener(this); - assignPanel.add(assign); -// controlsPanel.add(assignPanel); - - finished = new JButton("Finished"); - JPanel finishedPanel = new JPanel(); - finishedPanel.setLayout(new FlowLayout()); - finished.addActionListener(this); - finishedPanel.add(finished); - controlsPanel.add(finishedPanel); - - // Lane Status Panel - JPanel laneStatusPanel = new JPanel(); - laneStatusPanel.setLayout(new GridLayout(numLanes, 1)); - laneStatusPanel.setBorder(new TitledBorder("Lane Status")); - - HashSet lanes=controlDesk.getLanes(); - Iterator it = lanes.iterator(); - int laneCount=0; - while (it.hasNext()) { - Lane curLane = (Lane) it.next(); - LaneStatusView laneStat = new LaneStatusView(curLane,(laneCount+1)); - curLane.subscribe(laneStat); - ((Pinsetter)curLane.getPinsetter()).subscribe(laneStat); - JPanel lanePanel = laneStat.showLane(); - lanePanel.setBorder(new TitledBorder("Lane" + ++laneCount )); - laneStatusPanel.add(lanePanel); - } - - // Party Queue Panel - JPanel partyPanel = new JPanel(); - partyPanel.setLayout(new FlowLayout()); - partyPanel.setBorder(new TitledBorder("Party Queue")); - - Vector empty = new Vector(); - empty.add("(Empty)"); - - partyList = new JList(empty); - partyList.setFixedCellWidth(120); - partyList.setVisibleRowCount(10); - JScrollPane partyPane = new JScrollPane(partyList); - partyPane.setVerticalScrollBarPolicy( - JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - partyPanel.add(partyPane); - // partyPanel.add(partyList); - - // Clean up main panel - colPanel.add(controlsPanel, "East"); - colPanel.add(laneStatusPanel, "Center"); - colPanel.add(partyPanel, "West"); - - win.getContentPane().add("Center", colPanel); - - win.pack(); - - /* Close program when this window closes */ - win.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - System.exit(0); - } - }); - - // Center Window on Screen - Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); - win.setLocation( - ((screenSize.width) / 2) - ((win.getSize().width) / 2), - ((screenSize.height) / 2) - ((win.getSize().height) / 2)); - win.show(); - - } - - /** - * Handler for actionEvents - * - * @param e the ActionEvent that triggered the handler - * - */ - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(addParty)) { - AddPartyView addPartyWin = new AddPartyView(this, maxMembers); - } - if (e.getSource().equals(assign)) { - controlDesk.assignLane(); - } - if (e.getSource().equals(finished)) { - win.hide(); - System.exit(0); - } - } - - /** - * Receive a new party from andPartyView. - * - * @param addPartyView the AddPartyView that is providing a new party - * - */ - - public void updateAddParty(AddPartyView addPartyView) { - controlDesk.addPartyQueue(addPartyView.getParty()); - } - - /** - * Receive a broadcast from a ControlDesk - * - * @param ce the ControlDeskEvent that triggered the handler - * - */ - - public void receiveControlDeskEvent(ControlDeskEvent ce) { - partyList.setListData(((Vector) ce.getPartyQueue())); - } -} diff --git a/ballingSystem/src/EndGameCommand.java b/ballingSystem/src/EndGameCommand.java deleted file mode 100644 index 9ea67f2..0000000 --- a/ballingSystem/src/EndGameCommand.java +++ /dev/null @@ -1,9 +0,0 @@ -public class EndGameCommand implements ButtonCommand { - EndGamePrompt endGamePrompt; - public EndGameCommand(EndGamePrompt endGamePrompt){ - this.endGamePrompt = endGamePrompt; - } - public void execute(){ - endGamePrompt.setResult(2); - } -} diff --git a/ballingSystem/src/EndGamePrompt.java b/ballingSystem/src/EndGamePrompt.java deleted file mode 100644 index 2246ff3..0000000 --- a/ballingSystem/src/EndGamePrompt.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ - -import java.awt.*; -import javax.swing.*; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; - -public class EndGamePrompt { - private ButtonCommand command; - private JFrame win; - private JButton yesButton, noButton; - private JFrame endGameFrame; - private int result; - - public EndGamePrompt( String partyName ) { - - result = 0; - - endGameFrame = new JFrame("Another Game for " + partyName + "?"); - endGameFrame.getContentPane().setLayout(new BorderLayout()); - ((JPanel) endGameFrame.getContentPane()).setOpaque(false); - - JPanel colPanel = new JPanel(); - colPanel.setLayout(new GridLayout(2, 1)); - - // Label Panel - JPanel labelPanel = new JPanel(); - labelPanel.setLayout(new FlowLayout()); - - JLabel message = new JLabel("Party " + partyName + " has finished bowling.\nWould they like to bowl another game?"); - labelPanel.add(message); - - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new GridLayout(1, 2)); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - EndGamePromptClickEvent listener = new EndGamePromptClickEvent(); - - yesButton = createButton("Yes", listener); - noButton = createButton("No", listener); - - buttonPanel.setLayout(new GridLayout(1, 2)); - buttonPanel.add(yesButton); - buttonPanel.add(noButton); - - // Clean up main panel - colPanel.add(labelPanel); - colPanel.add(buttonPanel); - - endGameFrame.getContentPane().add("Center", colPanel); - - endGameFrame.pack(); - - // Center Window on Screen - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - endGameFrame.setLocation((screenSize.width / 2) - (endGameFrame.getSize().width / 2), - (screenSize.height / 2) - (endGameFrame.getSize().height / 2)); - endGameFrame.setVisible(true); - - } - private JButton createButton(String text, EndGamePromptClickEvent listener) { - JButton button = new JButton(text); - button.addActionListener(listener); - return button; - } - - public int getResult() { - while ( result == 0 ) { - try { - Thread.sleep(10); - } catch ( InterruptedException e ) { - System.err.println( "Interrupted" ); - } - } - return result; - } - public void setResult(int i) { - result = i; - } - public void distroy() { - endGameFrame.setVisible(false); - } - - public void setCommand(ButtonCommand command) { - this.command = command; - } - public void buttonPressed() { - command.execute(); - } - public class EndGamePromptClickEvent implements ActionListener { - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(yesButton)) { - setCommand(new AgainGameCommand(EndGamePrompt.this)); - } - if (e.getSource().equals(noButton)) { - setCommand(new EndGameCommand(EndGamePrompt.this)); - } - buttonPressed(); - } - } - -} - diff --git a/ballingSystem/src/EndGameReport.java b/ballingSystem/src/EndGameReport.java deleted file mode 100644 index 8aebbff..0000000 --- a/ballingSystem/src/EndGameReport.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - -import java.util.*; -import java.text.*; - -public class EndGameReport implements ActionListener, ListSelectionListener { - - private JFrame win; - private JButton printButton, finished; - private JList memberList; - private Vector myVector; - private Vector retVal; - - private int result; - - private String selectedMember; - - public EndGameReport( String partyName, Party party ) { - - result =0; - retVal = new Vector(); - win = new JFrame("End Game Report for " + partyName + "?" ); - win.getContentPane().setLayout(new BorderLayout()); - ((JPanel) win.getContentPane()).setOpaque(false); - - JPanel colPanel = new JPanel(); - colPanel.setLayout(new GridLayout( 1, 2 )); - - // Member Panel - JPanel partyPanel = new JPanel(); - partyPanel.setLayout(new FlowLayout()); - partyPanel.setBorder(new TitledBorder("Party Members")); - - Vector myVector = new Vector(); - Iterator iter = (party.getMembers()).iterator(); - while (iter.hasNext()){ - myVector.add( ((Bowler)iter.next()).getNickName() ); - } - memberList = new JList(myVector); - memberList.setFixedCellWidth(120); - memberList.setVisibleRowCount(5); - memberList.addListSelectionListener(this); - JScrollPane partyPane = new JScrollPane(memberList); - // partyPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - partyPanel.add(partyPane); - - partyPanel.add( memberList ); - - // Button Panel - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new GridLayout(2, 1)); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - printButton = new JButton("Print Report"); - JPanel printButtonPanel = new JPanel(); - printButtonPanel.setLayout(new FlowLayout()); - printButton.addActionListener(this); - printButtonPanel.add(printButton); - - finished = new JButton("Finished"); - JPanel finishedPanel = new JPanel(); - finishedPanel.setLayout(new FlowLayout()); - finished.addActionListener(this); - finishedPanel.add(finished); - - buttonPanel.add(printButton); - buttonPanel.add(finished); - - // Clean up main panel - colPanel.add(partyPanel); - colPanel.add(buttonPanel); - - win.getContentPane().add("Center", colPanel); - - win.pack(); - - // Center Window on Screen - Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); - win.setLocation( - ((screenSize.width) / 2) - ((win.getSize().width) / 2), - ((screenSize.height) / 2) - ((win.getSize().height) / 2)); - win.show(); - - } - - 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 Vector getResult() { - while ( result == 0 ) { - try { - Thread.sleep(10); - } catch ( InterruptedException e ) { - System.err.println( "Interrupted" ); - } - } - return retVal; - } - - public void destroy() { - win.hide(); - } - - public static void main( String args[] ) { - Vector bowlers = new Vector(); - for ( int i=0; i<4; i++ ) { - bowlers.add( new Bowler( "aaaaa", "aaaaa", "aaaaa" ) ); - } - Party party = new Party( bowlers ); - String partyName="wank"; - EndGameReport e = new EndGameReport( partyName, party ); - } - -} - diff --git a/ballingSystem/src/EndGameReportClickEvent.java b/ballingSystem/src/EndGameReportClickEvent.java deleted file mode 100644 index ba52186..0000000 --- a/ballingSystem/src/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/ballingSystem/src/Lane.java b/ballingSystem/src/Lane.java deleted file mode 100644 index a2b7265..0000000 --- a/ballingSystem/src/Lane.java +++ /dev/null @@ -1,621 +0,0 @@ - -/* $Id$ - * - * Revisions: - * $Log: Lane.java,v $ - * Revision 1.52 2003/02/20 20:27:45 ??? - * Fouls disables. - * - * Revision 1.51 2003/02/20 20:01:32 ??? - * Added things. - * - * Revision 1.50 2003/02/20 19:53:52 ??? - * Added foul support. Still need to update laneview and test this. - * - * Revision 1.49 2003/02/20 11:18:22 ??? - * Works beautifully. - * - * Revision 1.48 2003/02/20 04:10:58 ??? - * Score reporting code should be good. - * - * Revision 1.47 2003/02/17 00:25:28 ??? - * Added disbale controls for View objects. - * - * Revision 1.46 2003/02/17 00:20:47 ??? - * fix for event when game ends - * - * Revision 1.43 2003/02/17 00:09:42 ??? - * fix for event when game ends - * - * Revision 1.42 2003/02/17 00:03:34 ??? - * Bug fixed - * - * Revision 1.41 2003/02/16 23:59:49 ??? - * Reporting of sorts. - * - * Revision 1.40 2003/02/16 23:44:33 ??? - * added mechnanical problem flag - * - * Revision 1.39 2003/02/16 23:43:08 ??? - * added mechnanical problem flag - * - * Revision 1.38 2003/02/16 23:41:05 ??? - * added mechnanical problem flag - * - * Revision 1.37 2003/02/16 23:00:26 ??? - * added mechnanical problem flag - * - * Revision 1.36 2003/02/16 21:31:04 ??? - * Score logging. - * - * Revision 1.35 2003/02/09 21:38:00 ??? - * Added lots of comments - * - * Revision 1.34 2003/02/06 00:27:46 ??? - * Fixed a race condition - * - * Revision 1.33 2003/02/05 11:16:34 ??? - * Boom-Shacka-Lacka!!! - * - * Revision 1.32 2003/02/05 01:15:19 ??? - * Real close now. Honest. - * - * Revision 1.31 2003/02/04 22:02:04 ??? - * Still not quite working... - * - * Revision 1.30 2003/02/04 13:33:04 ??? - * Lane may very well work now. - * - * Revision 1.29 2003/02/02 23:57:27 ??? - * fix on pinsetter hack - * - * Revision 1.28 2003/02/02 23:49:48 ??? - * Pinsetter generates an event when all pins are reset - * - * Revision 1.27 2003/02/02 23:26:32 ??? - * ControlDesk now runs its own thread and polls for free lanes to assign queue members to - * - * Revision 1.26 2003/02/02 23:11:42 ??? - * parties can now play more than 1 game on a lane, and lanes are properly released after games - * - * Revision 1.25 2003/02/02 22:52:19 ??? - * Lane compiles - * - * Revision 1.24 2003/02/02 22:50:10 ??? - * Lane compiles - * - * Revision 1.23 2003/02/02 22:47:34 ??? - * More observering. - * - * Revision 1.22 2003/02/02 22:15:40 ??? - * Add accessor for pinsetter. - * - * Revision 1.21 2003/02/02 21:59:20 ??? - * added conditions for the party choosing to play another game - * - * Revision 1.20 2003/02/02 21:51:54 ??? - * LaneEvent may very well be observer method. - * - * Revision 1.19 2003/02/02 20:28:59 ??? - * fixed sleep thread bug in lane - * - * Revision 1.18 2003/02/02 18:18:51 ??? - * more changes. just need to fix scoring. - * - * Revision 1.17 2003/02/02 17:47:02 ??? - * Things are pretty close to working now... - * - * Revision 1.16 2003/01/30 22:09:32 ??? - * Worked on scoring. - * - * Revision 1.15 2003/01/30 21:45:08 ??? - * Fixed speling of received in Lane. - * - * Revision 1.14 2003/01/30 21:29:30 ??? - * Fixed some MVC stuff - * - * Revision 1.13 2003/01/30 03:45:26 ??? - * *** empty log message *** - * - * Revision 1.12 2003/01/26 23:16:10 ??? - * Improved thread handeling in lane/controldesk - * - * Revision 1.11 2003/01/26 22:34:44 ??? - * Total rewrite of lane and pinsetter for R2's observer model - * Added Lane/Pinsetter Observer - * Rewrite of scoring algorythm in lane - * - * Revision 1.10 2003/01/26 20:44:05 ??? - * small changes - * - * - */ - -import java.util.Vector; -import java.util.Iterator; -import java.util.HashMap; -import java.util.Date; - -public class Lane extends Thread implements PinsetterObserver { - private Party party; - private Pinsetter setter; - private HashMap scores; - private Vector subscribers; - - private boolean gameIsHalted; - - private boolean partyAssigned; - private boolean gameFinished; - private Iterator bowlerIterator; - private int ball; - private int bowlIndex; - private int frameNumber; - private boolean tenthFrameStrike; - - private int[] curScores; - private int[][] cumulScores; - private boolean canThrowAgain; - - private int[][] finalScores; - private int gameNumber; - - private Bowler currentThrower; // = the thrower who just took a throw - - /** Lane() - * - * Constructs a new lane and starts its thread - * - * @pre none - * @post a new lane has been created and its thered is executing - */ - public Lane() { - setter = new Pinsetter(); - scores = new HashMap(); - subscribers = new Vector(); - - gameIsHalted = false; - partyAssigned = false; - - gameNumber = 0; - - setter.subscribe( this ); - - this.start(); - } - - /** run() - * - * entry point for execution of this lane - */ - public void run() { - - while (true) { - if (partyAssigned && !gameFinished) { // we have a party on this lane, - // so next bower can take a throw - - while (gameIsHalted) { - try { - sleep(10); - } catch (Exception e) {} - } - - - if (bowlerIterator.hasNext()) { - currentThrower = (Bowler)bowlerIterator.next(); - - canThrowAgain = true; - tenthFrameStrike = false; - ball = 0; - while (canThrowAgain) { - setter.ballThrown(); // simulate the thrower's ball hiting - ball++; - } - - if (frameNumber == 9){ - finalScores[bowlIndex][gameNumber] = cumulScores[bowlIndex][9]; - try{ - Date date = new Date(); - String dateString = "" + date.getHours() + ":" + date.getMinutes() + " " + date.getMonth() + "/" + date.getDay() + "/" + (date.getYear() + 1900); - ScoreHistoryFile.addScore(currentThrower.getNickName(), dateString, new Integer(cumulScores[bowlIndex][9]).toString()); - } catch (Exception e) {System.err.println("Exception in addScore. "+ e );} - } - - - setter.reset(); - bowlIndex++; - - } else { - frameNumber++; - resetBowlerIterator(); - bowlIndex = 0; - if (frameNumber > 9) { - gameFinished = true; - gameNumber++; - } - } - } else if (partyAssigned && gameFinished) { - EndGamePrompt egp = new EndGamePrompt( ((Bowler) party.getMembers().get(0)).getNickName() + "'s Party" ); - int result = egp.getResult(); - egp.distroy(); - egp = null; - - - System.out.println("result was: " + result); - - // TODO: send record of scores to control desk - if (result == 1) { // yes, want to play again - resetScores(); - resetBowlerIterator(); - - } else if (result == 2) {// no, dont want to play another game - Vector printVector; - EndGameReport egr = new EndGameReport( ((Bowler)party.getMembers().get(0)).getNickName() + "'s Party", party); - printVector = egr.getResult(); - partyAssigned = false; - Iterator scoreIt = party.getMembers().iterator(); - party = null; - partyAssigned = false; - - publish(lanePublish()); - - int myIndex = 0; - while (scoreIt.hasNext()){ - Bowler thisBowler = (Bowler)scoreIt.next(); - ScoreReport sr = new ScoreReport( thisBowler, finalScores[myIndex++], gameNumber ); - sr.sendEmail(thisBowler.getEmail()); - Iterator printIt = printVector.iterator(); - while (printIt.hasNext()){ - if (thisBowler.getNick() == (String)printIt.next()){ - System.out.println("Printing " + thisBowler.getNick()); - sr.sendPrintout(); - } - } - - } - } - } - - - try { - sleep(10); - } catch (Exception e) {} - } - } - - /** recievePinsetterEvent() - * - * recieves the thrown event from the pinsetter - * - * @pre none - * @post the event has been acted upon if desiered - * - * @param pe The pinsetter event that has been received. - */ - public void receivePinsetterEvent(PinsetterEvent pe) { - - if (pe.pinsDownOnThisThrow() >= 0) { // this is a real throw - markScore(currentThrower, frameNumber + 1, pe.getThrowNumber(), pe.pinsDownOnThisThrow()); - - // next logic handles the ?: what conditions dont allow them another throw? - // handle the case of 10th frame first - if (frameNumber == 9) { - if (pe.totalPinsDown() == 10) { - setter.resetPins(); - if(pe.getThrowNumber() == 1) { - tenthFrameStrike = true; - } - } - - if ((pe.totalPinsDown() != 10) && (pe.getThrowNumber() == 2 && tenthFrameStrike == false)) { - canThrowAgain = false; - //publish( lanePublish() ); - } - - if (pe.getThrowNumber() == 3) { - canThrowAgain = false; - //publish( lanePublish() ); - } - } else { // its not the 10th frame - - if (pe.pinsDownOnThisThrow() == 10) { // threw a strike - canThrowAgain = false; - //publish( lanePublish() ); - } else if (pe.getThrowNumber() == 2) { - canThrowAgain = false; - //publish( lanePublish() ); - } else if (pe.getThrowNumber() == 3) - System.out.println("I'm here..."); - } - } else { // this is not a real throw, probably a reset - } - } - - /** resetBowlerIterator() - * - * sets the current bower iterator back to the first bowler - * - * @pre the party as been assigned - * @post the iterator points to the first bowler in the party - */ - private void resetBowlerIterator() { - bowlerIterator = (party.getMembers()).iterator(); - } - - /** resetScores() - * - * resets the scoring mechanism, must be called before scoring starts - * - * @pre the party has been assigned - * @post scoring system is initialized - */ - private void resetScores() { - Iterator bowlIt = (party.getMembers()).iterator(); - - while ( bowlIt.hasNext() ) { - int[] toPut = new int[25]; - for ( int i = 0; i != 25; i++){ - toPut[i] = -1; - } - scores.put( bowlIt.next(), toPut ); - } - - - - gameFinished = false; - frameNumber = 0; - } - - /** assignParty() - * - * assigns a party to this lane - * - * @pre none - * @post the party has been assigned to the lane - * - * @param theParty Party to be assigned - */ - public void assignParty( Party theParty ) { - party = theParty; - resetBowlerIterator(); - partyAssigned = true; - - curScores = new int[party.getMembers().size()]; - cumulScores = new int[party.getMembers().size()][10]; - finalScores = new int[party.getMembers().size()][128]; //Hardcoding a max of 128 games, bite me. - gameNumber = 0; - - resetScores(); - } - - /** markScore() - * - * Method that marks a bowlers score on the board. - * - * @param Cur The current bowler - * @param frame The frame that bowler is on - * @param ball The ball the bowler is on - * @param score The bowler's score - */ - private void markScore( Bowler Cur, int frame, int ball, int score ){ - int[] curScore; - int index = ( (frame - 1) * 2 + ball); - - curScore = (int[]) scores.get(Cur); - - - curScore[ index - 1] = score; - scores.put(Cur, curScore); - getScore( Cur, frame ); - publish( lanePublish() ); - } - - /** lanePublish() - * - * Method that creates and returns a newly created laneEvent - * - * @return The new lane event - */ - private LaneEvent lanePublish( ) { - LaneEvent laneEvent = new LaneEvent(party, bowlIndex, currentThrower, cumulScores, scores, frameNumber+1, curScores, ball, gameIsHalted); - return laneEvent; - } - - /** getScore() - * - * Method that calculates a bowlers score - * - * @param Cur The bowler that is currently up - * @param frame The frame the current bowler is on - * - * @return The bowlers total score - */ - private int getScore( Bowler Cur, int frame) { - int[] curScore; - int strikeballs = 0; - int totalScore = 0; - curScore = (int[]) scores.get(Cur); - for (int i = 0; i != 10; i++){ - cumulScores[bowlIndex][i] = 0; - } - int current = 2*(frame - 1)+ball-1; - //Iterate through each ball until the current one. - for (int i = 0; i != current+2; i++){ - //Spare: - if( i%2 == 1 && curScore[i - 1] + curScore[i] == 10 && i < current - 1 && i < 19){ - //This ball was a the second of a spare. - //Also, we're not on the current ball. - //Add the next ball to the ith one in cumul. - cumulScores[bowlIndex][(i/2)] += curScore[i+1] + curScore[i]; - if (i > 1) { - //cumulScores[bowlIndex][i/2] += cumulScores[bowlIndex][i/2 -1]; - } - } else if( i < current && i%2 == 0 && curScore[i] == 10 && i < 18){ - strikeballs = 0; - //This ball is the first ball, and was a strike. - //If we can get 2 balls after it, good add them to cumul. - if (curScore[i+2] != -1) { - strikeballs = 1; - if(curScore[i+3] != -1) { - //Still got em. - strikeballs = 2; - } else if(curScore[i+4] != -1) { - //Ok, got it. - strikeballs = 2; - } - } - if (strikeballs == 2){ - //Add up the strike. - //Add the next two balls to the current cumulscore. - cumulScores[bowlIndex][i/2] += 10; - if(curScore[i+1] != -1) { - cumulScores[bowlIndex][i/2] += curScore[i+1] + cumulScores[bowlIndex][(i/2)-1]; - if (curScore[i+2] != -1){ - if( curScore[i+2] != -2){ - cumulScores[bowlIndex][(i/2)] += curScore[i+2]; - } - } else { - if( curScore[i+3] != -2){ - cumulScores[bowlIndex][(i/2)] += curScore[i+3]; - } - } - } else { - if ( i/2 > 0 ){ - cumulScores[bowlIndex][i/2] += curScore[i+2] + cumulScores[bowlIndex][(i/2)-1]; - } else { - cumulScores[bowlIndex][i/2] += curScore[i+2]; - } - if (curScore[i+3] != -1){ - if( curScore[i+3] != -2){ - cumulScores[bowlIndex][(i/2)] += curScore[i+3]; - } - } else { - cumulScores[bowlIndex][(i/2)] += curScore[i+4]; - } - } - } else { - break; - } - }else { - //We're dealing with a normal throw, add it and be on our way. - if( i%2 == 0 && i < 18){ - if ( i/2 == 0 ) { - //First frame, first ball. Set his cumul score to the first ball - if(curScore[i] != -2){ - cumulScores[bowlIndex][i/2] += curScore[i]; - } - } else if (i/2 != 9){ - //add his last frame's cumul to this ball, make it this frame's cumul. - if(curScore[i] != -2){ - cumulScores[bowlIndex][i/2] += cumulScores[bowlIndex][i/2 - 1] + curScore[i]; - } else { - cumulScores[bowlIndex][i/2] += cumulScores[bowlIndex][i/2 - 1]; - } - } - } else if (i < 18){ - if(curScore[i] != -1 && i > 2){ - if(curScore[i] != -2){ - cumulScores[bowlIndex][i/2] += curScore[i]; - } - } - } - if (i/2 == 9){ - if (i == 18){ - cumulScores[bowlIndex][9] += cumulScores[bowlIndex][8]; - } - if(curScore[i] != -2){ - cumulScores[bowlIndex][9] += curScore[i]; - } - } else if (i/2 == 10) { - if(curScore[i] != -2){ - cumulScores[bowlIndex][9] += curScore[i]; - } - } - } - } - return totalScore; - } - - /** isPartyAssigned() - * - * checks if a party is assigned to this lane - * - * @return true if party assigned, false otherwise - */ - public boolean isPartyAssigned() { - return partyAssigned; - } - - /** isGameFinished - * - * @return true if the game is done, false otherwise - */ - public boolean isGameFinished() { - return gameFinished; - } - - /** subscribe - * - * Method that will add a subscriber - * - * @param subscribe Observer that is to be added - */ - - public void subscribe( LaneObserver adding ) { - subscribers.add( adding ); - } - - /** unsubscribe - * - * Method that unsubscribes an observer from this object - * - * @param removing The observer to be removed - */ - - public void unsubscribe( LaneObserver removing ) { - subscribers.remove( removing ); - } - - /** publish - * - * Method that publishes an event to subscribers - * - * @param event Event that is to be published - */ - - public void publish( LaneEvent event ) { - if( subscribers.size() > 0 ) { - Iterator eventIterator = subscribers.iterator(); - - while ( eventIterator.hasNext() ) { - ( (LaneObserver) eventIterator.next()).receiveLaneEvent( event ); - } - } - } - - /** - * Accessor to get this Lane's pinsetter - * - * @return A reference to this lane's pinsetter - */ - - public Pinsetter getPinsetter() { - return setter; - } - - /** - * Pause the execution of this game - */ - public void pauseGame() { - gameIsHalted = true; - publish(lanePublish()); - } - - /** - * Resume the execution of this game - */ - public void unPauseGame() { - gameIsHalted = false; - publish(lanePublish()); - } - -} diff --git a/ballingSystem/src/LaneEvent.java b/ballingSystem/src/LaneEvent.java deleted file mode 100644 index c7430c6..0000000 --- a/ballingSystem/src/LaneEvent.java +++ /dev/null @@ -1,95 +0,0 @@ -/* $Id$ - * - * Revisions: - * $Log: LaneEvent.java,v $ - * Revision 1.6 2003/02/16 22:59:34 ??? - * added mechnanical problem flag - * - * Revision 1.5 2003/02/02 23:55:31 ??? - * Many many changes. - * - * Revision 1.4 2003/02/02 22:44:26 ??? - * More data. - * - * Revision 1.3 2003/02/02 17:49:31 ??? - * Modified. - * - * Revision 1.2 2003/01/30 21:21:07 ??? - * *** empty log message *** - * - * Revision 1.1 2003/01/19 22:12:40 ??? - * created laneevent and laneobserver - * - * - */ - -import java.util.HashMap; - -public class LaneEvent { - - private Party p; - int frame; - int ball; - Bowler bowler; - int[][] cumulScore; - HashMap score; - int index; - int frameNum; - int[] curScores; - boolean mechProb; - - public LaneEvent( Party pty, int theIndex, Bowler theBowler, int[][] theCumulScore, HashMap theScore, int theFrameNum, int[] theCurScores, int theBall, boolean mechProblem) { - p = pty; - index = theIndex; - bowler = theBowler; - cumulScore = theCumulScore; - score = theScore; - curScores = theCurScores; - frameNum = theFrameNum; - ball = theBall; - mechProb = mechProblem; - } - - public boolean isMechanicalProblem() { - return mechProb; - } - - public int getFrameNum() { - return frameNum; - } - - public HashMap getScore( ) { - return score; - } - - - public int[] getCurScores(){ - return curScores; - } - - public int getIndex() { - return index; - } - - public int getFrame( ) { - return frame; - } - - public int getBall( ) { - return ball; - } - - public int[][] getCumulScore(){ - return cumulScore; - } - - public Party getParty() { - return p; - } - - public Bowler getBowler() { - return bowler; - } - -}; - diff --git a/ballingSystem/src/LaneEventInterface.java b/ballingSystem/src/LaneEventInterface.java deleted file mode 100644 index 0f3802e..0000000 --- a/ballingSystem/src/LaneEventInterface.java +++ /dev/null @@ -1,15 +0,0 @@ -import java.util.HashMap; - -public interface LaneEventInterface extends java.rmi.Remote { - public int getFrameNum( ) throws java.rmi.RemoteException; - public HashMap getScore( ) throws java.rmi.RemoteException; - public int[] getCurScores( ) throws java.rmi.RemoteException; - public int getIndex() throws java.rmi.RemoteException; - public int getFrame() throws java.rmi.RemoteException; - public int getBall() throws java.rmi.RemoteException; - public int[][] getCumulScore() throws java.rmi.RemoteException; - public Party getParty() throws java.rmi.RemoteException; - public Bowler getBowler() throws java.rmi.RemoteException; - -} - diff --git a/ballingSystem/src/LaneObserver.java b/ballingSystem/src/LaneObserver.java deleted file mode 100644 index 648b556..0000000 --- a/ballingSystem/src/LaneObserver.java +++ /dev/null @@ -1,17 +0,0 @@ -/* $Id$ - * - * Revisions: - * $Log: LaneObserver.java,v $ - * Revision 1.2 2003/01/30 21:44:25 ??? - * Fixed speling of received in may places. - * - * Revision 1.1 2003/01/19 22:12:40 ??? - * created laneevent and laneobserver - * - * - */ - -public interface LaneObserver { - public void receiveLaneEvent(LaneEvent le); -}; - diff --git a/ballingSystem/src/LaneServer.java b/ballingSystem/src/LaneServer.java deleted file mode 100644 index bb83369..0000000 --- a/ballingSystem/src/LaneServer.java +++ /dev/null @@ -1,4 +0,0 @@ -public interface LaneServer extends java.rmi.Remote { - public void subscribe(LaneObserver toAdd) throws java.rmi.RemoteException; -}; - diff --git a/ballingSystem/src/LaneStatusView.java b/ballingSystem/src/LaneStatusView.java deleted file mode 100644 index d8febab..0000000 --- a/ballingSystem/src/LaneStatusView.java +++ /dev/null @@ -1,155 +0,0 @@ -/** - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - -public class LaneStatusView implements ActionListener, LaneObserver, PinsetterObserver { - - private JPanel jp; - - private JLabel curBowler, foul, pinsDown; - private JButton viewLane; - private JButton viewPinSetter, maintenance; - - private PinSetterView psv; - private LaneView lv; - private Lane lane; - int laneNum; - - boolean laneShowing; - boolean psShowing; - - public LaneStatusView(Lane lane, int laneNum ) { - - this.lane = lane; - this.laneNum = laneNum; - - laneShowing=false; - psShowing=false; - - psv = new PinSetterView( laneNum ); - Pinsetter ps = lane.getPinsetter(); - ps.subscribe(psv); - - lv = new LaneView( lane, laneNum ); - lane.subscribe(lv); - - - jp = new JPanel(); - jp.setLayout(new FlowLayout()); - JLabel cLabel = new JLabel( "Now Bowling: " ); - curBowler = new JLabel( "(no one)" ); - JLabel fLabel = new JLabel( "Foul: " ); - foul = new JLabel( " " ); - JLabel pdLabel = new JLabel( "Pins Down: " ); - pinsDown = new JLabel( "0" ); - - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new FlowLayout()); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - viewLane = new JButton("View Lane"); - JPanel viewLanePanel = new JPanel(); - viewLanePanel.setLayout(new FlowLayout()); - viewLane.addActionListener(this); - viewLanePanel.add(viewLane); - - viewPinSetter = new JButton("Pinsetter"); - JPanel viewPinSetterPanel = new JPanel(); - viewPinSetterPanel.setLayout(new FlowLayout()); - viewPinSetter.addActionListener(this); - viewPinSetterPanel.add(viewPinSetter); - - maintenance = new JButton(" "); - maintenance.setBackground( Color.GREEN ); - JPanel maintenancePanel = new JPanel(); - maintenancePanel.setLayout(new FlowLayout()); - maintenance.addActionListener(this); - maintenancePanel.add(maintenance); - - viewLane.setEnabled( false ); - viewPinSetter.setEnabled( false ); - - - buttonPanel.add(viewLanePanel); - buttonPanel.add(viewPinSetterPanel); - buttonPanel.add(maintenancePanel); - - jp.add( cLabel ); - jp.add( curBowler ); -// jp.add( fLabel ); -// jp.add( foul ); - jp.add( pdLabel ); - jp.add( pinsDown ); - - jp.add(buttonPanel); - - } - - public JPanel showLane() { - return jp; - } - - public void actionPerformed( ActionEvent e ) { - if ( lane.isPartyAssigned() ) { - if (e.getSource().equals(viewPinSetter)) { - if ( psShowing == false ) { - psv.show(); - psShowing=true; - } else if ( psShowing == true ) { - psv.hide(); - psShowing=false; - } - } - } - if (e.getSource().equals(viewLane)) { - if ( lane.isPartyAssigned() ) { - if ( laneShowing == false ) { - lv.show(); - laneShowing=true; - } else if ( laneShowing == true ) { - lv.hide(); - laneShowing=false; - } - } - } - if (e.getSource().equals(maintenance)) { - if ( lane.isPartyAssigned() ) { - lane.unPauseGame(); - maintenance.setBackground( Color.GREEN ); - } - } - } - - public void receiveLaneEvent(LaneEvent le) { - curBowler.setText( ( (Bowler)le.getBowler()).getNickName() ); - if ( le.isMechanicalProblem() ) { - maintenance.setBackground( Color.RED ); - } - if ( lane.isPartyAssigned() == false ) { - viewLane.setEnabled( false ); - viewPinSetter.setEnabled( false ); - } else { - viewLane.setEnabled( true ); - viewPinSetter.setEnabled( true ); - } - } - - public void receivePinsetterEvent(PinsetterEvent pe) { - pinsDown.setText( ( new Integer(pe.totalPinsDown()) ).toString() ); -// foul.setText( ( new Boolean(pe.isFoulCommited()) ).toString() ); - - } - -} diff --git a/ballingSystem/src/LaneView.java b/ballingSystem/src/LaneView.java deleted file mode 100644 index ef93188..0000000 --- a/ballingSystem/src/LaneView.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * constructs a prototype Lane View - * - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.util.*; - -public class LaneView implements LaneObserver, ActionListener { - - private int roll; - private boolean initDone = true; - - JFrame frame; - Container cpanel; - Vector bowlers; - int cur; - Iterator bowlIt; - - JPanel[][] balls; - JLabel[][] ballLabel; - JPanel[][] scores; - JLabel[][] scoreLabel; - JPanel[][] ballGrid; - JPanel[] pins; - - JButton maintenance; - Lane lane; - - public LaneView(Lane lane, int laneNum) { - - this.lane = lane; - - initDone = true; - frame = new JFrame("Lane " + laneNum + ":"); - cpanel = frame.getContentPane(); - cpanel.setLayout(new BorderLayout()); - - frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - frame.hide(); - } - }); - - cpanel.add(new JPanel()); - - } - - public void show() { - frame.show(); - } - - public void hide() { - frame.hide(); - } - - private JPanel makeFrame(Party party) { - - initDone = false; - bowlers = party.getMembers(); - int numBowlers = bowlers.size(); - - JPanel panel = new JPanel(); - - panel.setLayout(new GridLayout(0, 1)); - - balls = new JPanel[numBowlers][23]; - ballLabel = new JLabel[numBowlers][23]; - scores = new JPanel[numBowlers][10]; - scoreLabel = new JLabel[numBowlers][10]; - ballGrid = new JPanel[numBowlers][10]; - pins = new JPanel[numBowlers]; - - for (int i = 0; i != numBowlers; i++) { - for (int j = 0; j != 23; j++) { - ballLabel[i][j] = new JLabel(" "); - balls[i][j] = new JPanel(); - balls[i][j].setBorder( - BorderFactory.createLineBorder(Color.BLACK)); - balls[i][j].add(ballLabel[i][j]); - } - } - - for (int i = 0; i != numBowlers; i++) { - for (int j = 0; j != 9; j++) { - ballGrid[i][j] = new JPanel(); - ballGrid[i][j].setLayout(new GridLayout(0, 3)); - ballGrid[i][j].add(new JLabel(" "), BorderLayout.EAST); - ballGrid[i][j].add(balls[i][2 * j], BorderLayout.EAST); - ballGrid[i][j].add(balls[i][2 * j + 1], BorderLayout.EAST); - } - int j = 9; - ballGrid[i][j] = new JPanel(); - ballGrid[i][j].setLayout(new GridLayout(0, 3)); - ballGrid[i][j].add(balls[i][2 * j]); - ballGrid[i][j].add(balls[i][2 * j + 1]); - ballGrid[i][j].add(balls[i][2 * j + 2]); - } - - for (int i = 0; i != numBowlers; i++) { - pins[i] = new JPanel(); - pins[i].setBorder( - BorderFactory.createTitledBorder( - ((Bowler) bowlers.get(i)).getNickName())); - pins[i].setLayout(new GridLayout(0, 10)); - for (int k = 0; k != 10; k++) { - scores[i][k] = new JPanel(); - scoreLabel[i][k] = new JLabel(" ", SwingConstants.CENTER); - scores[i][k].setBorder( - BorderFactory.createLineBorder(Color.BLACK)); - scores[i][k].setLayout(new GridLayout(0, 1)); - scores[i][k].add(ballGrid[i][k], BorderLayout.EAST); - scores[i][k].add(scoreLabel[i][k], BorderLayout.SOUTH); - pins[i].add(scores[i][k], BorderLayout.EAST); - } - panel.add(pins[i]); - } - - initDone = true; - return panel; - } - - public void receiveLaneEvent(LaneEvent le) { - if (lane.isPartyAssigned()) { - int numBowlers = le.getParty().getMembers().size(); - while (!initDone) { - //System.out.println("chillin' here."); - try { - Thread.sleep(1); - } catch (Exception e) { - } - } - - if (le.getFrameNum() == 1 - && le.getBall() == 0 - && le.getIndex() == 0) { - System.out.println("Making the frame."); - cpanel.removeAll(); - cpanel.add(makeFrame(le.getParty()), "Center"); - - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new FlowLayout()); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - maintenance = new JButton("Maintenance Call"); - JPanel maintenancePanel = new JPanel(); - maintenancePanel.setLayout(new FlowLayout()); - maintenance.addActionListener(this); - maintenancePanel.add(maintenance); - - buttonPanel.add(maintenancePanel); - - cpanel.add(buttonPanel, "South"); - - frame.pack(); - - } - - int[][] lescores = le.getCumulScore(); - for (int k = 0; k < numBowlers; k++) { - for (int i = 0; i <= le.getFrameNum() - 1; i++) { - if (lescores[k][i] != 0) - scoreLabel[k][i].setText( - (new Integer(lescores[k][i])).toString()); - } - for (int i = 0; i < 21; i++) { - if (((int[]) ((HashMap) le.getScore()) - .get(bowlers.get(k)))[i] - != -1) - if (((int[]) ((HashMap) le.getScore()) - .get(bowlers.get(k)))[i] - == 10 - && (i % 2 == 0 || i == 19)) - ballLabel[k][i].setText("X"); - else if ( - i > 0 - && ((int[]) ((HashMap) le.getScore()) - .get(bowlers.get(k)))[i] - + ((int[]) ((HashMap) le.getScore()) - .get(bowlers.get(k)))[i - - 1] - == 10 - && i % 2 == 1) - ballLabel[k][i].setText("/"); - else if ( ((int[])((HashMap) le.getScore()).get(bowlers.get(k)))[i] == -2 ){ - - ballLabel[k][i].setText("F"); - } else - ballLabel[k][i].setText( - (new Integer(((int[]) ((HashMap) le.getScore()) - .get(bowlers.get(k)))[i])) - .toString()); - } - } - - } - } - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(maintenance)) { - lane.pauseGame(); - } - } - -} diff --git a/ballingSystem/src/NewPatronView.java b/ballingSystem/src/NewPatronView.java deleted file mode 100644 index 4404805..0000000 --- a/ballingSystem/src/NewPatronView.java +++ /dev/null @@ -1,184 +0,0 @@ -/* AddPartyView.java - * - * Version - * $Id$ - * - * Revisions: - * $Log: NewPatronView.java,v $ - * Revision 1.3 2003/02/02 16:29:52 ??? - * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. - * - * - */ - -/** - * Class for GUI components need to add a patron - * - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - - -import java.util.*; -import java.text.*; - -public class NewPatronView { - private static final int TEXT_FIELD_SIZE = 15; - private int maxSize; - private ButtonCommand command; - private JFrame win; - private JButton abort, finished; - private JLabel nickLabel, fullLabel, emailLabel; - private JTextField nickField, fullField, emailField; - private String nick, full, email; - - private boolean done; - - private String selectedNick, selectedMember; - private AddPartyView addParty; - - public NewPatronView(AddPartyView v) { - - addParty=v; - done = false; - - win = new JFrame("Add Patron"); - win.getContentPane().setLayout(new BorderLayout()); - ((JPanel) win.getContentPane()).setOpaque(false); - - JPanel colPanel = new JPanel(); - colPanel.setLayout(new BorderLayout()); - - // Patron Panel - JPanel patronPanel = new JPanel(); - patronPanel.setLayout(new GridLayout(3, 1)); - patronPanel.setBorder(new TitledBorder("Your Info")); - - nickField = new JTextField("", TEXT_FIELD_SIZE); - JPanel nickPanel = createFieldPanel("Nick Name", nickField); - - fullField = new JTextField("", TEXT_FIELD_SIZE); - JPanel fullPanel = createFieldPanel("Full Name", fullField); - - emailField = new JTextField("", TEXT_FIELD_SIZE); - JPanel emailPanel = createFieldPanel("E-Mail", emailField); - - NewPatronViewClickEvent listener = new NewPatronViewClickEvent(); - patronPanel.add(nickPanel); - patronPanel.add(fullPanel); - patronPanel.add(emailPanel); - - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new GridLayout(4, 1)); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - finished = createButton("Add Patron", new JPanel(), listener); - abort = createButton("Abort", new JPanel(), listener); - - buttonPanel.add((JPanel) finished.getParent()); - buttonPanel.add((JPanel) abort.getParent()); - - // Clean up main panel - colPanel.add(patronPanel, "Center"); - colPanel.add(buttonPanel, "East"); - - win.getContentPane().add("Center", colPanel); - - win.pack(); - - // Center Window on Screen - Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); - win.setLocation( - ((screenSize.width) / 2) - ((win.getSize().width) / 2), - ((screenSize.height) / 2) - ((win.getSize().height) / 2)); - win.setVisible(true); - - } - private JPanel createFieldPanel(String labelText, JTextField textField) { - JPanel panel = new JPanel(); - panel.setLayout(new FlowLayout()); - JLabel label = new JLabel(labelText); - panel.add(label); - panel.add(textField); - return panel; - } - private JButton createButton(String buttonText, JPanel panel, NewPatronViewClickEvent listener) { // 버튼 객체 생성 - JButton button = new JButton(buttonText); - button.addActionListener(listener); - panel.setLayout(new FlowLayout()); - panel.add(button); - return button; - } - public void setCommand(ButtonCommand command) { - this.command = command; - } - public void buttonPressed() { - command.execute(); - } - public boolean done() { - return done; - } - public void setDone(boolean done) { - this.done = done; - } - public String getNick() { - return nick; - } - public void setNick(String nick) { - this.nick = nick; - } - public String getFull() { - return full; - } - public void setFull(String full) { - this.full = full; - } - public String getEmail() { - return email; - } - public void setEmail(String email) { - this.email = email; - } - public JFrame getWindow() { - return win; - } - public JTextField getNickField() { - return nickField; - } - public JTextField getFullField() { - return fullField; - } - public JTextField getEmailField() { - return emailField; - } - public AddPartyView getAddParty() { - return addParty; - } - public class NewPatronViewClickEvent implements ActionListener { - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(abort)) { - setCommand(new AbortNewPatronCommand(NewPatronView.this)); - } - - if (e.getSource().equals(finished)) { - nick = nickField.getText(); - full = fullField.getText(); - email = emailField.getText(); - done = true; - if (nick.isEmpty() || full.isEmpty() || email.isEmpty()) { - // 예외 상황(아무 정보도 입력 안 한 상태)에 대해 사용자에게 메시지를 보여주는 코드 추가 - JOptionPane.showMessageDialog(win, "All fields must be filled out.", "Error", JOptionPane.ERROR_MESSAGE); - } else { - setCommand(new FinishedNewPatronCommand(NewPatronView.this)); - } - } - buttonPressed(); - } - } -} diff --git a/ballingSystem/src/Party.java b/ballingSystem/src/Party.java deleted file mode 100644 index ac083d3..0000000 --- a/ballingSystem/src/Party.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Party.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: Party.java,v $ - * Revision 1.3 2003/02/09 21:21:31 ??? - * Added lots of comments - * - * Revision 1.2 2003/01/12 22:23:32 ??? - * *** empty log message *** - * - * Revision 1.1 2003/01/12 19:09:12 ??? - * Adding Party, Lane, Bowler, and Alley. - * - */ - -/** - * Container that holds bowlers - * - */ - -import java.util.*; - -public class Party { - - /** Vector of bowlers in this party */ - private Vector myBowlers; - - /** - * Constructor for a Party - * - * @param bowlers Vector of bowlers that are in this party - */ - - public Party( Vector bowlers ) { - myBowlers = new Vector(bowlers); - } - - /** - * Accessor for members in this party - * - * @return A vector of the bowlers in this party - */ - - public Vector getMembers() { - return myBowlers; - } - -} diff --git a/ballingSystem/src/PinSetterView.java b/ballingSystem/src/PinSetterView.java deleted file mode 100644 index cd66b20..0000000 --- a/ballingSystem/src/PinSetterView.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * PinSetterView/.java - * - * Version: - * $Id$ - * - * Revision: - * $Log$ - */ - -/** - * constructs a prototype PinSetter GUI - * - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.util.Vector; - - -public class PinSetterView implements PinsetterObserver { - - - private Vector pinVect = new Vector ( ); - private JPanel firstRoll; - private JPanel secondRoll; - - /** - * Constructs a Pin Setter GUI displaying which roll it is with - * yellow boxes along the top (1 box for first roll, 2 boxes for second) - * and displays the pins as numbers in this format: - * - * 7 8 9 10 - * 4 5 6 - * 2 3 - * 1 - * - */ - - - private JFrame frame; - - public PinSetterView ( int laneNum ) { - - frame = new JFrame ( "Lane " + laneNum + ":" ); - - Container cpanel = frame.getContentPane ( ); - - JPanel pins = new JPanel ( ); - - pins.setLayout ( new GridLayout ( 4, 7 ) ); - - //********************Top of GUI indicates first or second roll - - JPanel top = new JPanel ( ); - - firstRoll = new JPanel ( ); - firstRoll.setBackground( Color.yellow ); - - secondRoll = new JPanel ( ); - secondRoll.setBackground ( Color.black ); - - top.add ( firstRoll, BorderLayout.WEST ); - - top.add ( secondRoll, BorderLayout.EAST ); - - //****************************************************************** - - //**********************Grid of the pins************************** - - - JPanel one = new JPanel (); - JLabel oneL = new JLabel ( "1" ); - one.add (oneL); - JPanel two = new JPanel (); - JLabel twoL = new JLabel ( "2" ); - two.add (twoL); - JPanel three = new JPanel (); - JLabel threeL = new JLabel ( "3" ); - three.add (threeL); - JPanel four = new JPanel (); - JLabel fourL = new JLabel ( "4" ); - four.add (fourL); - JPanel five = new JPanel (); - JLabel fiveL = new JLabel ( "5" ); - five.add (fiveL); - JPanel six = new JPanel (); - JLabel sixL = new JLabel ( "6" ); - six.add (sixL); - JPanel seven = new JPanel (); - JLabel sevenL = new JLabel ( "7" ); - seven.add (sevenL); - JPanel eight = new JPanel (); - JLabel eightL = new JLabel ( "8" ); - eight.add (eightL); - JPanel nine = new JPanel (); - JLabel nineL = new JLabel ( "9" ); - nine.add (nineL); - JPanel ten = new JPanel (); - JLabel tenL = new JLabel ( "10" ); - ten.add (tenL); - - //This Vector will keep references to the pin labels to show - //which ones have fallen. - - pinVect.add ( oneL ); - pinVect.add ( twoL ); - pinVect.add ( threeL ); - pinVect.add ( fourL ); - pinVect.add ( fiveL ); - pinVect.add ( sixL ); - pinVect.add ( sevenL ); - pinVect.add ( eightL ); - pinVect.add ( nineL ); - pinVect.add ( tenL ); - - - //******************************Fourth Row************** - - pins.add ( seven ); - pins.add ( new JPanel ( ) ); - pins.add ( eight ); - pins.add ( new JPanel ( ) ); - pins.add ( nine ); - pins.add ( new JPanel ( ) ); - pins.add ( ten ); - - //*****************************Third Row*********** - - pins.add ( new JPanel ( ) ); - pins.add ( four ); - pins.add ( new JPanel ( ) ); - pins.add ( five ); - pins.add ( new JPanel ( ) ); - pins.add ( six ); - - //*****************************Second Row************** - - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - pins.add ( two ); - pins.add ( new JPanel ( ) ); - pins.add ( three ); - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - - //******************************First Row***************** - - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - pins.add ( one ); - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - //********************************************************* - - top.setBackground ( Color.black ); - - cpanel.add ( top, BorderLayout.NORTH ); - - pins.setBackground ( Color.black ); - pins.setForeground ( Color.yellow ); - - cpanel.add ( pins, BorderLayout.CENTER ); - - frame.pack(); - - -// frame.show(); - } - - - /** - * This method receives a pinsetter event. The event is the current - * state of the PinSetter and the method changes how the GUI looks - * accordingly. When pins are "knocked down" the corresponding label - * is grayed out. When it is the second roll, it is indicated by the - * appearance of a second yellow box at the top. - * - * @param e The state of the pinsetter is sent in this event. - */ - - - public void receivePinsetterEvent(PinsetterEvent pe){ - if ( !(pe.isFoulCommited()) ) { - JLabel tempPin = new JLabel ( ); - for ( int c = 0; c < 10; c++ ) { - boolean pin = pe.pinKnockedDown ( c ); - tempPin = (JLabel)pinVect.get ( c ); - if ( pin ) { - tempPin.setForeground ( Color.lightGray ); - } - } - } - if ( pe.getThrowNumber() == 1 ) { - secondRoll.setBackground ( Color.yellow ); - } - if ( pe.pinsDownOnThisThrow() == -1) { - for ( int i = 0; i != 10; i++){ - ((JLabel)pinVect.get(i)).setForeground(Color.black); - } - secondRoll.setBackground( Color.black); - } - } - - public void show() { - frame.show(); - } - - public void hide() { - frame.hide(); - } - - public static void main ( String args [ ] ) { - PinSetterView pg = new PinSetterView ( 1 ); - } - -} diff --git a/ballingSystem/src/Pinsetter.java b/ballingSystem/src/Pinsetter.java deleted file mode 100644 index 0ffeeae..0000000 --- a/ballingSystem/src/Pinsetter.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Pinsetter.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: Pinsetter.java,v $ - * Revision 1.21 2003/02/20 20:27:45 ??? - * Fouls disables. - * - * Revision 1.20 2003/02/20 19:53:52 ??? - * Added foul support. Still need to update laneview and test this. - * - * Revision 1.19 2003/02/06 22:28:51 ??? - * added delay - * - * Revision 1.18 2003/02/06 00:27:46 ??? - * Fixed a race condition - * - * Revision 1.17 2003/02/05 23:56:07 ??? - * *** empty log message *** - * - * Revision 1.16 2003/02/05 23:51:09 ??? - * Better random numbers. - * - * Revision 1.15 2003/02/02 23:49:48 ??? - * Pinsetter generates an event when all pins are reset - * - * Revision 1.14 2003/02/02 23:26:32 ??? - * ControlDesk now runs its own thread and polls for free lanes to assign queue members to - * - * Revision 1.13 2003/02/02 23:21:30 ??? - * pinsetter should give better results - * - * Revision 1.12 2003/02/02 23:20:28 ??? - * pinsetter should give better results - * - * Revision 1.11 2003/02/02 23:11:41 ??? - * parties can now play more than 1 game on a lane, and lanes are properly released after games - * - * Revision 1.10 2003/02/01 19:14:42 ??? - * Will now set the pins back up at times other than the 10th frame. - * - * Revision 1.9 2003/01/30 21:44:25 ??? - * Fixed speling of received in may places. - * - * Revision 1.8 2003/01/26 22:34:44 ??? - * Total rewrite of lane and pinsetter for R2's observer model - * Added Lane/Pinsetter Observer - * Rewrite of scoring algorythm in lane - * - * Revision 1.7 2003/01/19 21:55:24 ??? - * updated pinsetter to new spec - * - * Revision 1.6 2003/01/16 04:59:59 ??? - * misc fixes across the board - * - * Revision 1.5 2003/01/13 22:35:21 ??? - * Scoring works. - * - * Revision 1.3 2003/01/12 22:37:20 ??? - * Wrote a better algorythm for knocking down pins - * - * - */ - -/** - * Class to represent the pinsetter - * - */ - -import java.util.*; -import java.lang.Boolean; - -public class Pinsetter { - - private Random rnd; - private Vector subscribers; - - private boolean[] pins; - /* 0-9 of state of pine, true for standing, - false for knocked down - - 6 7 8 9 - 3 4 5 - 2 1 - 0 - - */ - private boolean foul; - private int throwNumber; - - /** sendEvent() - * - * Sends pinsetter events to all subscribers - * - * @pre none - * @post all subscribers have recieved pinsetter event with updated state - * */ - private void sendEvent(int jdpins) { // send events when our state is changd - for (int i=0; i < subscribers.size(); i++) { - ((PinsetterObserver)subscribers.get(i)).receivePinsetterEvent( - new PinsetterEvent(pins, foul, throwNumber, jdpins)); - } - } - - /** Pinsetter() - * - * Constructs a new pinsetter - * - * @pre none - * @post a new pinsetter is created - * @return Pinsetter object - */ - public Pinsetter() { - pins = new boolean[10]; - rnd = new Random(); - subscribers = new Vector(); - foul = false; - reset(); - } - - /** ballThrown() - * - * Called to simulate a ball thrown comming in contact with the pinsetter - * - * @pre none - * @post pins may have been knocked down and the thrownumber has been incremented - */ - public void ballThrown() { // simulated event of ball hits sensor - int count = 0; - foul = false; - double skill = rnd.nextDouble(); - for (int i=0; i <= 9; i++) { - if (pins[i]) { - double pinluck = rnd.nextDouble(); - if (pinluck <= .04){ - foul = true; - } - if ( ((skill + pinluck)/2.0 * 1.2) > .5 ){ - pins[i] = false; - } - if (!pins[i]) { // this pin just knocked down - count++; - } - } - } - - try { - Thread.sleep(500); // pinsetter is where delay will be in a real game - } catch (Exception e) {} - - sendEvent(count); - - throwNumber++; - } - - /** reset() - * - * Reset the pinsetter to its complete state - * - * @pre none - * @post pinsetters state is reset - */ - public void reset() { - foul = false; - throwNumber = 1; - resetPins(); - - try { - Thread.sleep(1000); - } catch (Exception e) {} - - sendEvent(-1); - } - - /** resetPins() - * - * Reset the pins on the pinsetter - * - * @pre none - * @post pins array is reset to all pins up - */ - public void resetPins() { - for (int i=0; i <= 9; i++) { - pins[i] = true; - } - } - - /** subscribe() - * - * subscribe objects to send events to - * - * @pre none - * @post the subscriber object will recieve events when their generated - */ - public void subscribe(PinsetterObserver subscriber) { - subscribers.add(subscriber); - } - -}; - diff --git a/ballingSystem/src/PinsetterEvent.java b/ballingSystem/src/PinsetterEvent.java deleted file mode 100644 index 0608bc2..0000000 --- a/ballingSystem/src/PinsetterEvent.java +++ /dev/null @@ -1,91 +0,0 @@ -/* $Id$ - * - * Revisions: - * $Log: PinsetterEvent.java,v $ - * Revision 1.2 2003/01/26 22:34:44 ??? - * Total rewrite of lane and pinsetter for R2's observer model - * Added Lane/Pinsetter Observer - * Rewrite of scoring algorythm in lane - * - * Revision 1.1 2003/01/19 21:04:24 ??? - * created pinsetterevent and pinsetterobserver - * - */ - -public class PinsetterEvent { - - private boolean[] pinsStillStanding; - private boolean foulCommited; - private int throwNumber; - private int pinsDownThisThrow; - - /** PinsetterEvent() - * - * creates a new pinsetter event - * - * @pre none - * @post the object has been initialized - */ - public PinsetterEvent(boolean[] ps, boolean foul, int tn, int pinsDownThisThrow) { - pinsStillStanding = new boolean[10]; - - for (int i=0; i <= 9; i++) { - pinsStillStanding[i] = ps[i]; - } - - foulCommited = foul; - throwNumber = tn; - this.pinsDownThisThrow = pinsDownThisThrow; - } - - /** pinKnockedDown() - * - * check if a pin has been knocked down - * - * @return true if pin [i] has been knocked down - */ - public boolean pinKnockedDown(int i) { - return !pinsStillStanding[i]; - } - - /** pinsDownOnThisThrow() - * - * @return the number of pins knocked down assosicated with this event - */ - public int pinsDownOnThisThrow() { - return pinsDownThisThrow; - } - - /** totalPinsDown() - * - * @return the total number of pins down for pinsetter that generated the event - */ - public int totalPinsDown() { - int count = 0; - - for (int i=0; i <= 9; i++) { - if (pinKnockedDown(i)) { - count++; - } - } - - return count; - } - - /** isFoulCommited() - * - * @return true if a foul was commited on the lane, false otherwise - */ - public boolean isFoulCommited() { - return foulCommited; - } - - /** getThrowNumber() - * - * @return current number of throws taken on this lane after last reset - */ - public int getThrowNumber() { - return throwNumber; - } -}; - diff --git a/ballingSystem/src/PinsetterObserver.java b/ballingSystem/src/PinsetterObserver.java deleted file mode 100644 index 666ae04..0000000 --- a/ballingSystem/src/PinsetterObserver.java +++ /dev/null @@ -1,28 +0,0 @@ -/* $Id$ - * - * Revisions: - * $Log: PinsetterObserver.java,v $ - * Revision 1.3 2003/01/30 21:44:25 ??? - * Fixed speling of received in may places. - * - * Revision 1.2 2003/01/26 22:34:44 ??? - * Total rewrite of lane and pinsetter for R2's observer model - * Added Lane/Pinsetter Observer - * Rewrite of scoring algorythm in lane - * - * Revision 1.1 2003/01/19 21:04:24 ??? - * created pinsetterevent and pinsetterobserver - * - * - */ - - -public interface PinsetterObserver { - - /** recievePinsetterEvent() - * - * defines the method for an object torecieve a pinsetter event - */ - public void receivePinsetterEvent(PinsetterEvent pe); -}; - diff --git a/ballingSystem/src/PrintableText.java b/ballingSystem/src/PrintableText.java deleted file mode 100644 index 9505048..0000000 --- a/ballingSystem/src/PrintableText.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * - */ - -import java.awt.*; -import java.awt.print.*; -import java.awt.geom.*; -import java.awt.font.*; -import java.text.*; - -public class PrintableText implements Printable { - String text; - int POINTS_PER_INCH; - - public PrintableText(String t) { - POINTS_PER_INCH = 72; - text = t; - } - - public int print(Graphics g, PageFormat pageFormat, int pageIndex) { - if (pageIndex > 0) { - return NO_SUCH_PAGE; - } - - Graphics2D g2d = (Graphics2D) g; // Allow use of Java 2 graphics on - - g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); - g2d.setPaint(Color.black); - - Point2D.Double pen = new Point2D.Double(0.25 * POINTS_PER_INCH, 0.25 * POINTS_PER_INCH); - - Font font = new Font ("courier", Font.PLAIN, 12); - FontRenderContext frc = g2d.getFontRenderContext(); - - String lines[] = text.split("\n"); - - for (int i=0; i < lines.length; i++) { - if (lines[i].length() > 0) { - TextLayout layout = new TextLayout(lines[i], font, frc); - layout.draw(g2d, (float) pen.x, (float) (pen.y + i*14)); - } - } - - return PAGE_EXISTS; - } - -} diff --git a/ballingSystem/src/Queue.java b/ballingSystem/src/Queue.java deleted file mode 100644 index 418ca96..0000000 --- a/ballingSystem/src/Queue.java +++ /dev/null @@ -1,40 +0,0 @@ -/* Queue.java - * - * Version - * $Id$ - * - * Revisions: - * $Log$ - * - */ - -import java.util.Vector; - -public class Queue { - private Vector v; - - /** Queue() - * - * creates a new queue - */ - public Queue() { - v = new Vector(); - } - - public Object next() { - return v.remove(0); - } - - public void add(Object o) { - v.addElement(o); - } - - public boolean hasMoreElements() { - return v.size() != 0; - } - - public Vector asVector() { - return v; - } - -} diff --git a/ballingSystem/src/README.md b/ballingSystem/src/README.md deleted file mode 100644 index 738ee2a..0000000 --- a/ballingSystem/src/README.md +++ /dev/null @@ -1 +0,0 @@ -# BallingManagementSystem_refactoring \ No newline at end of file diff --git a/ballingSystem/src/SCOREHISTORY.DAT b/ballingSystem/src/SCOREHISTORY.DAT deleted file mode 100644 index be3911d..0000000 --- a/ballingSystem/src/SCOREHISTORY.DAT +++ /dev/null @@ -1,15 +0,0 @@ -Mike 22:25 3/6/2004 130 -Jim 22:25 3/6/2004 113 -Tom 22:25 3/6/2004 105 -Lana 22:25 3/6/2004 130 -TomH 22:25 3/6/2004 125 -Mike 22:26 3/6/2004 153 -TomH 22:26 3/6/2004 174 -Mike 15:52 4/2/2023 162 -Jim 15:52 4/2/2023 139 -Tom 15:54 4/2/2023 124 -Jim 15:54 4/2/2023 134 -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 diff --git a/ballingSystem/src/Score.java b/ballingSystem/src/Score.java deleted file mode 100644 index f1b976d..0000000 --- a/ballingSystem/src/Score.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ - -public class Score { - - private String nick; - private String date; - private String score; - - public Score( String nick, String date, String score ) { - this.nick=nick; - this.date=date; - this.score=score; - } - - public String getNickName() { - return nick; - } - - public String getDate() { - return date; - } - - public String getScore() { - return score; - } - - public String toString() { - return nick + "\t" + date + "\t" + score; - } - -} diff --git a/ballingSystem/src/ScoreHistoryFile.java b/ballingSystem/src/ScoreHistoryFile.java deleted file mode 100644 index 4b1d2bf..0000000 --- a/ballingSystem/src/ScoreHistoryFile.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ - -import java.util.*; -import java.io.*; - -public class ScoreHistoryFile { - - private static String SCOREHISTORY_DAT = "/Users/yeonjoo/git/BallingManagementSystem_refactoring/SCOREHISTORY.DAT"; - - public static void addScore(String nick, String date, String score) - throws IOException, FileNotFoundException { - - String data = nick + "\t" + date + "\t" + score + "\n"; - - RandomAccessFile out = new RandomAccessFile(SCOREHISTORY_DAT, "rw"); - out.skipBytes((int) out.length()); - out.writeBytes(data); - out.close(); - } - - public static Vector getScores(String nick) - throws IOException, FileNotFoundException { - Vector scores = new Vector(); - - BufferedReader in = - new BufferedReader(new FileReader(SCOREHISTORY_DAT)); - String data; - while ((data = in.readLine()) != null) { - // File format is nick\tfname\te-mail - String[] scoredata = data.split("\t"); - //"Nick: scoredata[0] Date: scoredata[1] Score: scoredata[2] - if (nick.equals(scoredata[0])) { - scores.add(new Score(scoredata[0], scoredata[1], scoredata[2])); - } - } - return scores; - } - -} diff --git a/ballingSystem/src/ScoreReport.java b/ballingSystem/src/ScoreReport.java deleted file mode 100644 index 50b1cd4..0000000 --- a/ballingSystem/src/ScoreReport.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * - * SMTP implementation based on code by R�al Gagnon mailto:real@rgagnon.com - * - */ - - -import java.io.*; -import java.util.Vector; -import java.util.Iterator; -import java.net.*; -import java.awt.*; -import java.awt.print.*; - -public class ScoreReport { - - private String content; - - public ScoreReport( Bowler bowler, int[] scores, int games ) { - String nick = bowler.getNickName(); - String full = bowler.getFullName(); - Vector v = null; - try{ - v = ScoreHistoryFile.getScores(nick); - } catch (Exception e){System.err.println("Error: " + e);} - - Iterator scoreIt = v.iterator(); - - content = ""; - content += "--Lucky Strike Bowling Alley Score Report--\n"; - content += "\n"; - content += "Report for " + full + ", aka \"" + nick + "\":\n"; - content += "\n"; - content += "Final scores for this session: "; - content += scores[0]; - for (int i = 1; i < games; i++){ - content += ", " + scores[i]; - } - content += ".\n"; - content += "\n"; - content += "\n"; - content += "Previous scores by date: \n"; - while (scoreIt.hasNext()){ - Score score = (Score) scoreIt.next(); - content += " " + score.getDate() + " - " + score.getScore(); - content += "\n"; - } - content += "\n\n"; - content += "Thank you for your continuing patronage."; - - } - - public void sendEmail(String recipient) { - try { - Socket s = new Socket("osfmail.rit.edu", 25); - BufferedReader in = - new BufferedReader( - new InputStreamReader(s.getInputStream(), "8859_1")); - BufferedWriter out = - new BufferedWriter( - new OutputStreamWriter(s.getOutputStream(), "8859_1")); - - String boundary = "DataSeparatorString"; - - // here you are supposed to send your username - sendln(in, out, "HELO world"); - sendln(in, out, "MAIL FROM: "); - sendln(in, out, "RCPT TO: <" + recipient + ">"); - sendln(in, out, "DATA"); - sendln(out, "Subject: Bowling Score Report "); - sendln(out, "From: "); - - sendln(out, "Content-Type: text/plain; charset=\"us-ascii\"\r\n"); - sendln(out, content + "\n\n"); - sendln(out, "\r\n"); - - sendln(in, out, "."); - sendln(in, out, "QUIT"); - s.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void sendPrintout() { - PrinterJob job = PrinterJob.getPrinterJob(); - - PrintableText printobj = new PrintableText(content); - - job.setPrintable(printobj); - - if (job.printDialog()) { - try { - job.print(); - } catch (PrinterException e) { - System.out.println(e); - } - } - - } - - public void sendln(BufferedReader in, BufferedWriter out, String s) { - try { - out.write(s + "\r\n"); - out.flush(); - // System.out.println(s); - s = in.readLine(); - // System.out.println(s); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void sendln(BufferedWriter out, String s) { - try { - out.write(s + "\r\n"); - out.flush(); - System.out.println(s); - } catch (Exception e) { - e.printStackTrace(); - } - } - - -} diff --git a/ballingSystem/src/drive.java b/ballingSystem/src/drive.java deleted file mode 100644 index b8c0207..0000000 --- a/ballingSystem/src/drive.java +++ /dev/null @@ -1,18 +0,0 @@ -import java.util.Vector; -import java.io.*; - -public class drive { - - public static void main(String[] args) { - - int numLanes = 3; - int maxPatronsPerParty=5; - - Alley a = new Alley( numLanes ); - ControlDesk controlDesk = a.getControlDesk(); - - ControlDeskView cdv = new ControlDeskView( controlDesk, maxPatronsPerParty); - controlDesk.subscribe( cdv ); - - } -}