设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9982|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
, H! Q& E5 R! N* Msel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
; Z7 h0 ?/ H- a$ c
7 r% ^( n5 I0 Z- V( _似乎缺少了一个SwarmUtils的类,不知道怎么回事
: m' ?$ x$ L9 r+ |
0 |$ w, B( l, a9 c朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
/ M& U% w! ~& l) j6 c
# ]- k' V8 u8 x# y% o5 W/ w$ Q: Xpublic class SwarmUtils {
/ r# s5 d9 {' m; {6 y  public static Selector getSelector(String name, String method) {& n+ e7 _& B. h! M$ n
    Selector sel;
/ v$ m2 W) ~" C  w- s    try {
2 o* x" h$ S4 ~. i6 I      sel = new Selector(Class.forName(name), method, false);
: i" X& j# j  J8 a    } catch (Exception e) {. Z! v2 N# V( o) u
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* y+ H) J$ ^# }      System.err.println(name + "." + method + " returns " + e.getMessage());
+ W' ]- |! t5 r% k4 U      System.err.println("The process will be terminated.");( n  g) r/ A5 s  ?6 g8 `* ]3 I" r
      System.exit(1);! {  O) o& a! i' N
      return null;, S* j8 D; v9 m  C4 d
    }  w( A8 C& `$ N. M, p
    return sel;! z$ B. ~5 @7 c7 k  o" C8 r
  }# Q# B1 {  g" M, ^7 B* i( o/ b' C

  R6 O, Q: E: V8 E3 I  public static Selector getSelector(Object obj, String method) {/ X; j* \  A4 e; U& ^, o
    Selector sel;6 @  T  a: D1 s7 M; _
    try {% R6 v3 t- ^7 H0 U# I
      sel = new Selector(obj.getClass(), method, false);
, t' [: O/ P" U0 ~    } catch (Exception e) {+ E+ G- H- N6 T
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "+ J; {! z5 Z) v, k
          + (obj.getClass()).getName() + ".");
1 ?; `9 t  _! c) _5 b      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());: b  d+ ]9 v) m6 M6 P( M5 q
      System.err.println("The process will be terminated.");- d8 L% a# s% p
      System.exit(1);! _& v5 B, g/ B. v+ Z4 S* t3 `( H. B
      return null;
+ {; _  Y4 j, `" k( V3 s    }8 p6 D. D) q9 D- Q
    return sel;- Y2 k* t2 @' n7 H* k9 {
  }
/ b0 m' t2 r" h( K}

评分

参与人数 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-7-3 15:40 , Processed in 0.016688 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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