????????????????????С???????1????ú???????????????????????????????10??????????actionPerformed()??????????????????????Щ?????????????????????????????????????????????????????е??ж???

???????????????????????Command????????????????????????????????????Command????

//the Command interface
public interface Command{
public void execute();
}


????????????????????????????????Command??????????????????????д?JFrame??????????????????????????????????SexButton?????????ActionListener????????????У?????????????????????????????????????

//abstract radio button class
public abstract class SexButton
extends JRadioButton implements Command{
protected Swimmers simmers;
//JawList is a subclass of JScrollPane contained a JList;
protected JawList kidList;
public SexButton(String title??Swimmers sw??
JawList klist??ActionListener al){
super(title);
swimmers=sw;
kidList=klist;
addActionListener(al);
}
//abstract execute method
public abstract void execute();
}


???????????????????????????????????????о??廯execute()??????????????????????????????е????????????????壬????????????????????????????

//radio button to select female swimmers
public class FemaleButton extends SexButton{
public execute(){
Vector v=swimmers.getList(true);
loadList(v);
}
private void loadList(Vector v){
kidList.clear();
for(int i=0;i
Swimmer swm=(Swimmer)v.elementAt(i);
kidList.add(swm.getName());
}
}
}


????????????????????????????????е??????????Command??????actionPerformed()??????????????????????????

public void actionPerformed(ActionEvent e){
Command cmd=(Command)e.getSource();
cmd.execute();
}