设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10621|回复: 7

[交流] 科学网于同奎先生的源程序

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行4 m  `+ n' K# m5 Q9 h4 V
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行- x) p# ^" [5 `! Z- n7 O9 O

& b5 S) M+ H. K" J; o( m似乎缺少了一个SwarmUtils的类,不知道怎么回事 8 y" F  W. f( U  ^" L
, a1 g$ }8 D% T; N& H; M
朋友们给个反馈??

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1仿真币 +12 +1 收起 理由
苘苘 + 12 + 1

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;# Q1 F3 y/ d2 T5 l- w( v

1 K/ w1 t6 }! M+ K+ f+ ~7 S1 U9 ~1 N% apublic class SwarmUtils {6 a; O  ^$ `  h2 Y; \
  public static Selector getSelector(String name, String method) {/ _. U5 ]2 x9 ^. Z
    Selector sel;* S( _/ x) g; p- x+ u
    try {; l' h6 X/ i9 E& }. y
      sel = new Selector(Class.forName(name), method, false);
9 I& C: H, ^. G! S# y    } catch (Exception e) {6 q4 F- m7 C+ O' R$ ~" B
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 a9 k# Y4 L- @0 P, Z
      System.err.println(name + "." + method + " returns " + e.getMessage());
  ~  Q, t' T; J% N0 q/ H, E      System.err.println("The process will be terminated.");1 x! ~7 k) ~4 O  P8 ?8 N
      System.exit(1);+ u, I3 |: h4 g- H
      return null;4 j( N, \0 s  r
    }& S" {9 W$ y; C+ q8 x
    return sel;9 ?! \* _9 e1 J" j
  }1 V' J: a* g- J( c. \
. t. ?# J  Y2 [+ F% F
  public static Selector getSelector(Object obj, String method) {
* ?& w5 ]5 r; r7 n- v1 E1 ?    Selector sel;% r# [$ H5 a" d$ d$ ~
    try {
* ?' b% }# q% S' X      sel = new Selector(obj.getClass(), method, false);: h) n2 G9 y. y7 F5 Z6 M
    } catch (Exception e) {7 l3 u# h* C% _& G& t
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% R! {6 F$ O* T8 m2 j
          + (obj.getClass()).getName() + ".");, G: {9 h* P; ?, M2 C/ `
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 s4 h9 Q+ z) j6 R' i      System.err.println("The process will be terminated.");
$ L) T) V$ P) A      System.exit(1);
; r' z  S$ f2 k# {      return null;
& e4 v- y: O8 h5 T3 `( h    }! ?+ g7 W  H5 e& O8 ]
    return sel;
, a# X/ E  {- [. U6 M  }# K1 O0 ^; Z7 v# p% i, c6 |  t/ v
}

评分

参与人数 1仿真币 +21 +1 收起 理由
苘苘 + 21 + 1 我很赞同

查看全部评分

发表于 2008-11-20 19:49:58 | 显示全部楼层
very good.
发表于 2008-11-28 11:12:43 | 显示全部楼层
这个……在SimpleBug的代码中自带了一个SwarmUtils的类……答案如2楼所示……
发表于 2009-3-12 14:52:51 | 显示全部楼层

谢谢

学习学习
发表于 2009-12-2 20:20:58 | 显示全部楼层
请问一下代码是添加在哪里的啊?
发表于 2012-5-22 10:31:21 | 显示全部楼层
是单独建立一个新的JAVA文件,文件名为SwarmUtils.java,然后把上述代码复制进去就可以了
发表于 2013-1-25 12:27:29 | 显示全部楼层
学习。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-9-10 23:52 , Processed in 0.015147 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表