???????Java??ó???????
???????????? ???????[ 2012/8/24 9:48:12 ] ????????
????????????????????С???????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();
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11