设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7991|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
5 J: W6 }) m. D4 y7 t; w8 y* rsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行& S* [- o$ I, [0 W9 Z
% ^( T6 j5 D0 M4 H
似乎缺少了一个SwarmUtils的类,不知道怎么回事 # L% {/ c  a1 i+ Q" V3 @/ s
4 J9 ]& j7 e5 U# ^1 v# z& o' m0 K. y
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
  b( U9 S) u( y9 E! m/ \. B
3 l8 i# k9 j9 V  J- V: C& gpublic class SwarmUtils {
4 _$ K, B- p* g  [' l2 x$ {' @  public static Selector getSelector(String name, String method) {# F& T+ V0 d  _; x3 |8 D4 N9 q" u
    Selector sel;- W5 K$ s9 |5 m% e
    try {
  n8 _; O  d, e! @* j      sel = new Selector(Class.forName(name), method, false);
% E  K; ^# E. R. X% ]" x. N9 P    } catch (Exception e) {
$ b4 u  y3 g! B      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: B/ z0 t5 y, W( U$ J      System.err.println(name + "." + method + " returns " + e.getMessage());
% H2 U$ A* I1 ~1 c      System.err.println("The process will be terminated.");
, m/ V1 w. j! m2 f( P$ b      System.exit(1);
3 O( `5 b7 R5 j& d4 X      return null;6 G# f; {( K& w/ ^$ z
    }0 p) ^8 R% i6 M& ]% g5 x9 ]
    return sel;8 P$ ^4 a$ ^+ E4 G. \# A
  }5 |, F  y$ N* |3 j8 N$ ~

5 q4 p# j' y6 z, @1 A) U( w, ]  public static Selector getSelector(Object obj, String method) {9 V& k6 i7 O- u$ T. W
    Selector sel;
" A' k3 u5 a" i/ i    try {
8 y' |, A' Y6 j: e      sel = new Selector(obj.getClass(), method, false);
0 L0 p1 O  ~( K$ k    } catch (Exception e) {
9 n% @5 i. e4 \! P3 h" H      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# {& Y& w! A  @' X* h          + (obj.getClass()).getName() + ".");1 d  y3 H# C6 b, b% r
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
) f! c9 S7 U# Y      System.err.println("The process will be terminated.");
1 t6 r( j( ~8 r6 y      System.exit(1);- J3 T3 _& d" j# N
      return null;0 d2 U( ~$ V( n* f
    }( P; i# T2 H) _/ w2 r9 X
    return sel;
8 \  P5 x% `" m  d% m& ?2 ~  }) ^+ \0 T* ]7 d5 T2 G% `
}

评分

参与人数 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, 2025-9-5 04:27 , Processed in 0.015642 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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