设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9406|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行2 m6 e$ j$ g- X+ d9 X, c2 c3 D
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
1 [; R' B4 u( X) C) U7 @% v4 ~. J) c
似乎缺少了一个SwarmUtils的类,不知道怎么回事
( }% w) q. ]% `2 I: e) W$ u4 ]7 X7 z/ p& R# x. b
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
  |0 o1 N$ x. J! P6 W- W1 T9 P6 S. Y- O* `
public class SwarmUtils {9 z  z. l! {: F% ~  u. i* b, J6 V) ]
  public static Selector getSelector(String name, String method) {% K3 |  Q- r/ \: t! v& ^
    Selector sel;. R+ Z( \1 p7 o) L; {+ x+ R9 \
    try {
. t8 K; f8 h) W3 X# U- u* L7 q; _      sel = new Selector(Class.forName(name), method, false);
3 W7 e8 A2 j( \0 X4 Z# x    } catch (Exception e) {
! q+ O* \( d  x5 ?5 \2 D0 h" A      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* a; C2 U5 B8 v2 @9 Q
      System.err.println(name + "." + method + " returns " + e.getMessage());8 _: n! W" ^1 B2 V
      System.err.println("The process will be terminated.");
3 h8 P& J5 q: E      System.exit(1);
, h7 D0 T- y8 X1 {) C      return null;2 F  Q  b: |. W( U/ _- Q6 Y! n( e6 L& e
    }
) H$ @6 F; S9 j$ ?7 Q" q4 }, U    return sel;* ~9 k( j& k9 ^5 m8 x; K
  }
" i+ V8 a* `0 Z7 E$ ?4 ?. R, i( E! h8 M8 Y+ ]7 H* K0 Y+ ^! P! c: j
  public static Selector getSelector(Object obj, String method) {
, l: @, k5 V3 V3 S0 x( [& t  l% J    Selector sel;' ~0 _; f& D( x$ T
    try {
7 C; e. e8 s( \# K% Q0 h      sel = new Selector(obj.getClass(), method, false);1 V: g7 t% k6 ?' A& U# {- k
    } catch (Exception e) {
8 L- N0 d' B! ^  r1 \  G      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
% E8 }: F& R$ P          + (obj.getClass()).getName() + ".");
# _1 c7 w% Z  T( }+ C; _  k  v      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
/ ]) z9 N# o' z0 _8 v  ?" W      System.err.println("The process will be terminated.");! ]) p7 c  X3 _8 j  S- p2 M6 g
      System.exit(1);4 q+ [+ Q) U/ `& X5 W
      return null;0 s. v. i1 M3 {, I' _9 R
    }4 V" D, U4 i+ ?2 S* m
    return sel;' _$ B* p# A) L0 e! p
  }1 s  I- J: R8 s0 n# l; N2 V6 @, {( ~
}

评分

参与人数 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-4-19 08:23 , Processed in 0.018359 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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