0
public class AthleteManager {
private static Icon anIcon = new ImageIcon();
private static int currentSize = 0, maxSize = 10;
private Athlete[] AthleteList = new Athlete[maxSize];
///////////////////////////////////////////////////
public AthleteManager(){
Runner aRunner = new Runner("Bolt","Jamica",101);
AthleteList[currentSize]=aRunner;
currentSize++;
DuAthlete aDuAthlete = new DuAthlete("Benny", "Belgian", 102);
AthleteList[currentSize]=aDuAthlete;
currentSize++;
TriAthlete aTriAthlete = new TriAthlete("Alexander", "Irish", 103);
AthleteList[currentSize]=aTriAthlete;
currentSize++;
Coach aCoach = new Coach("Wolmer", "Britan", 104);
AthleteList[currentSize] = aCoach;
currentSize++;
}
/////////////////////////////////////////////////////////////////////////
public int mainMenu()
{
int option =0;
String opt1 = new String("1. Add an Athlete :");
String opt2 = new String("2. Register an Athlete with a Coach :");
String opt3 = new String("3. List All members of Team DS 2012 :");
String opt4 = new String("4. List all Athletes of Coach (based on ID):");
String opt5 = new String("5. Display Leader Board:");
String opt6 = new String("6. Search for an Athlete (based on a Name) :");
String opt7 = new String("7. Remove an Athlete (based on ID):");
String opt8 = new String("8. Log finishing Distances:");
String opt9 = new String("9. Exit System");
String msg = new String("Enter Option:");
JTextField opt = new JTextField("");
Object message[] = new Object[12];
message[0] = myIcon;
message[1] = opt1;
message[2] = opt2;
message[3] = opt3;
message[4] = opt4;
message[5] = opt5;
message[6] = opt6;
message[7] = opt7;
message[8] = opt8;
message[9] = opt9;
message[10] = msg;
message[11] = opt;
int response = JOptionPane.showConfirmDialog(null,message,"Athlete Data Entry",JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE ,anIcon);
if(response == JOptionPane.CANCEL_OPTION)
;
else
{
try {
option = Integer.parseInt(opt.getText());
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,"Data Input Error" + e + "\nPlease Try Again");
}
}
return option;
}
////////////////////////////////////////////////////////////////////////
public void addAthleteMenu(){
choseAthleteMenu();
}
////////////////////////////////////////////////////////////////////////
public int choseAthleteMenu(){
int option =0;
String inform = new String("Please Select the type of athlete");
String opt1 = new String("1. Runner:");
String opt2 = new String("2. DuAtlete :");
String opt3 = new String("3. TriAthlete :");
String opt4 = new String("4. Coach");
String msg = new String("Enter Option:");
JTextField opt = new JTextField("");
Object message[] = new Object[8];
message[0] = myIcon;
message[1] =inform;
message[2] = opt1;
message[3] = opt2;
message[4] = opt3;
message[5] = opt4;
message[6] = msg;
message[7] = opt;
int response = JOptionPane.showConfirmDialog(null,message,"Athlete Data Entry",JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE ,anIcon);
if(response == JOptionPane.CANCEL_OPTION)
;
else
{
try {
addRunner(); }
catch (Exception e)
{
JOptionPane.showMessageDialog(null,"Data Input Error" + e + "\nPlease Try Again");
}
}
return option;
}
/////////////////////////////////////
public void addRunner(){
String msgName = new String("Athlete Name :");
String msgClubName= new String("Club Name :");
Integer msgID = new Integer("Athlete ID :");
String msgDistance = new String("Athlete Distance :");
JTextField name = new JTextField("");
JTextField club = new JTextField("");
JTextField id = new JTextField();
JTextField distance = new JTextField("");
Object message[] = new Object[9];
message[0] = myIcon;
message[1] = msgName;
message[2] = name;
message[3] = msgClubName;
message[4] = club;
message[5] = msgID;
message[6] = id;
message[7] = msgDistance;
message[8] = distance;
int response = JOptionPane.showConfirmDialog(null,message,"Athlete Data Entry",JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE ,anIcon);
if(response == JOptionPane.CANCEL_OPTION)
;
else
{
try{
Runner nRunner = new Runner();
nRunner.setName(name.getText());
nRunner.setClub(club.getText());
nRunner.setId(Integer.parseInt(id.getText()));
addRunnerToList(nRunner);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Data Input Error" + e + "\nPlease Try Again");
}
}
}
///////////////////////////////////////////////////////////////////////////////
private void addRunnerToList(Runner nRunner){
try{
AthleteList[currentSize]=nRunner;
currentSize++;
}catch(Exception sqle){
JOptionPane.showMessageDialog(null, "Can Not Add to List" +sqle);
}
}
///////////////////////////////////////////////////////////////////////////
public void menuListAthletes(){
JOptionPane.showMessageDialog(null, AthleteList);
}
////////////////////////////////////////////////
public void regAnAthleteWithCoachMenu(){
}
//////////////////////////////////////////
public void listAthletesOfCoach(){
}
///////////////////////////////////
public void leaderBoard(){
}
//////////////////////////////////////////
public void searchAthlete(){
}
//////////////////////////////////////
public void removeAthlete(){
}
//////////////////////////////////
public void logDistances(){
}
//////////////////////////////////
}
제가하려는 것은 JTextfield
을 사용하여 다른 유형의 운동 선수를 추가하는 것입니다. 위의 코드에서 각 유형의 운동 선수를 추가하는 대신 별도의 방법을 쓰는 대신 옵션을 선택하면 어떤 종류의 수표 선수를 사용하는 메뉴 방법은 관련 장소에 추가 할 수 있습니까? 조언이 있으십니까?아래 코드와 함께 선수를 추가하는 방법은 무엇입니까?
그들은 모두 진정한 인터페이스를 가지고 있습니다. RunnerInterface DuAthleteinterface etc. .... ?? – user1220007
for 루프를 사용하여 운동 선수를위한 변수 설정을 시도하십시오. 현재의 방법은 읽기가 매우 어렵습니다. – Jimmt