Skip to content

Commit

Permalink
feat : init 코드
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim-minseok123 committed May 30, 2023
1 parent c9897aa commit 8bd3fb3
Show file tree
Hide file tree
Showing 31 changed files with 3,392 additions and 0 deletions.
245 changes: 245 additions & 0 deletions AddPartyView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
/* 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 implements ActionListener, ListSelectionListener {

private int maxSize;

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)");

partyList = new JList(empty);
partyList.setFixedCellWidth(120);
partyList.setVisibleRowCount(5);
partyList.addListSelectionListener(this);
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.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(this);
bowlerPanel.add(bowlerPane);

// Button Panel
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(4, 1));

Insets buttonMargin = new Insets(4, 4, 4, 4);

addPatron = new JButton("Add to Party");
JPanel addPatronPanel = new JPanel();
addPatronPanel.setLayout(new FlowLayout());
addPatron.addActionListener(this);
addPatronPanel.add(addPatron);

remPatron = new JButton("Remove Member");
JPanel remPatronPanel = new JPanel();
remPatronPanel.setLayout(new FlowLayout());
remPatron.addActionListener(this);
remPatronPanel.add(remPatron);

newPatron = new JButton("New Patron");
JPanel newPatronPanel = new JPanel();
newPatronPanel.setLayout(new FlowLayout());
newPatron.addActionListener(this);
newPatronPanel.add(newPatron);

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

buttonPanel.add(addPatronPanel);
buttonPanel.add(remPatronPanel);
buttonPanel.add(newPatronPanel);
buttonPanel.add(finishedPanel);

// 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.show();

}

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.hide();
}

}

/**
* 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());
}
}

/**
* 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." );
}
} catch (Exception e2) {
System.err.println("File I/O Error");
}
}

/**
* Accessor for Party
*/

public Vector getParty() {
return party;
}

}
42 changes: 42 additions & 0 deletions Alley.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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;
}

}



5 changes: 5 additions & 0 deletions BOWLERS.DAT
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Mike M. J. Lutz [email protected]
Jim J. R. Vallino [email protected]
Tom T. R. Reichmayr [email protected]
Lana L. R. Verschage [email protected]
TomH T. Hilburn [email protected]
69 changes: 69 additions & 0 deletions Bowler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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) {
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;
}
}
Loading

0 comments on commit 8bd3fb3

Please sign in to comment.