设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10408|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行3 l3 l4 f% c5 l  I5 F
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行# ]) \+ {0 p2 `/ A
- }- X2 a' w, U3 y6 D
似乎缺少了一个SwarmUtils的类,不知道怎么回事
1 p! t7 q- c5 a# A  c  A7 ]- ]9 L4 U' g5 G4 K: B! F
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;# Z( l9 F$ I- M$ c5 q6 i. [2 s

) E' g6 Q7 [8 W: _% }+ Qpublic class SwarmUtils {
) a: q; s4 v& v; K4 B& @  public static Selector getSelector(String name, String method) {$ ^/ I  N9 V0 i8 A( i* X3 a
    Selector sel;
- l0 l$ P, D4 y' n* e4 }3 S    try {
& G6 v' V' M- j      sel = new Selector(Class.forName(name), method, false);  Y6 [& M, i6 M% x1 m: h
    } catch (Exception e) {: u7 X9 z- A  }+ N1 @2 \" M
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ @/ n- L) W( P5 A: y      System.err.println(name + "." + method + " returns " + e.getMessage());( N& @1 p$ [+ e) K( B+ c+ r! ?
      System.err.println("The process will be terminated.");
7 @$ ~* v, K: G) U$ H- t& H      System.exit(1);, d( V& e) T+ y3 S
      return null;- x) d2 ]9 P/ j5 _
    }
1 T) r5 j. R- W: R8 h    return sel;
. J# [# Y8 Y5 l! L( J# @4 R0 D$ G  }
: x( N, q) K8 i# h5 z7 z/ Q* o& w0 z$ |. @$ j$ Z% @1 o
  public static Selector getSelector(Object obj, String method) {: D. \6 X2 f0 N7 f: p0 _& M
    Selector sel;% Q' x$ i0 Y; q9 {
    try {
/ ~' s& a* R) b' D  M; c0 n      sel = new Selector(obj.getClass(), method, false);# b# f; u! y8 m3 h7 |, t* ]; B1 J4 \
    } catch (Exception e) {
( R2 s& D) C$ G" r$ h7 F! R      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
, Z& a  k/ H; r; C, D          + (obj.getClass()).getName() + ".");" S, E: @0 L+ b& h1 s6 x
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 A1 j9 }1 k* F  t# D' c4 r
      System.err.println("The process will be terminated.");% P& W! y" U" q1 J0 O
      System.exit(1);
# }3 v; H5 n9 k, O( x! N3 N1 s1 v      return null;- a! l+ D* b" c/ j3 e3 g
    }
! ~1 Y. G+ z6 B1 V. A    return sel;6 H2 r1 X, e  I# G; S* q! e
  }
7 t* Y! N' g8 J: F# |5 k: w}

评分

参与人数 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-8-12 15:19 , Processed in 2.429789 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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