???????Java??ó???????
???????????? ???????[ 2012/8/24 9:48:12 ] ????????
?????????????????????????????????????
?????????????????????顣????????д????????????????????????????????б???????????????????????????????????????????????????б??????????????????????????????????????????????
??????????????????б?????????mediator???????????????????????????????????Mediator???????????????????????????????????????????????????????????????б?????????а????????????????б?????????е??????????????????????????????????????????Mediator??
public class Mediator{
private JawList kidList;
public Mediator(JawList klist){
kidList=klist;
}
public void loadList(Vector v){
kidList.clear();
for(int i=0;i
Swimmer sw=(Swimmer)v.elementAt(i);
kidList.add(sw.getName());
}
}
}
????????????????????????
public abstract class SexButton
extends JRadioButton implements Command{
protected Swimmers swimmers;
protected Mediator med;
public SexButton(String title??Swimmers sw??Mediator md??ActionListener al){
super(title);
swimmers=sw;
med=md;
addActionListener(al);
}
public abstract void execute();
}
??????FemalButton??????????
public class FemaleButton extends SexButton{
//use the mediator to load the list
public void execute(){
Vector v=swimmers.getList(true);
med.loadList(v);
}
}
???????????????Mediator??????????б??????????????????
??????????????????????????????????????100?е?Java????????????????????ù????(Observer)??????????????JListData??????????б?????б??л???????????LawList???JListData??仯??
public class JListData extends AbstractListModel{
private Vector data;
public JListData(){
data=new Vector();
}
public int getSize(){
return data.size();
}
public Object getElementAt(int index){
return data.elementAt(index);
}
public void addElement(String s){
data.addElement(s);
fireIntervalAdded(this??data.size()-1??data.size());
}
public void removeElement(String s){
data.removeElement(s);
fireIntervalRemoved(this??0??data.size());
}
public void clear(){
int size=data.size();
data.clear();
fireIntervalRemoved(this??0??size);
}
}
public class JawList extends JScrollPane{
private JList listwindow;
private JListData listContents;
public JawList(){
listContents=new JList
??????
???·???
??????????????????
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