Skip to content

Commit

Permalink
Fix: error
Browse files Browse the repository at this point in the history
  • Loading branch information
lightorange0v0 committed May 31, 2023
1 parent 2f63125 commit 33d1aa0
Show file tree
Hide file tree
Showing 61 changed files with 239 additions and 3,710 deletions.
Binary file added .DS_Store
Binary file not shown.
File renamed without changes.
181 changes: 93 additions & 88 deletions AddPartyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
*
*/

public class AddPartyView implements ActionListener, ListSelectionListener {

public class AddPartyView {
private int maxSize;
private ButtonCommand command;
private JFrame win;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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
Expand All @@ -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());
Expand All @@ -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;
Expand All @@ -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");
}
}
}

}
File renamed without changes.
1 change: 0 additions & 1 deletion BOWLERS.DAT
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ Jim J. R. Vallino [email protected]
Tom T. R. Reichmayr [email protected]
Lana L. R. Verschage [email protected]
TomH T. Hilburn [email protected]
yeonjoo yeonjoo [email protected]
14 changes: 3 additions & 11 deletions Bowler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
File renamed without changes.
83 changes: 42 additions & 41 deletions BowlerFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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<String[]> readBowlersFromFile() throws IOException {
List<String[]> 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;
}

/**
Expand All @@ -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)
Expand All @@ -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<String> getBowlers() throws IOException {
List<String> allBowlers = new ArrayList<>();
for (String[] bowler : readBowlersFromFile()) {
allBowlers.add(bowler[0]);
}
return allBowlers;
}

}
Loading

0 comments on commit 33d1aa0

Please sign in to comment.