设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8561|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行( s% @/ V) P8 I9 j$ n) {
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
8 F1 X" R# a2 Y" j# d
2 \" T' M; I! Z0 u似乎缺少了一个SwarmUtils的类,不知道怎么回事 . F0 ^) i" y: C! E' X; K0 V
$ P5 k9 O- d9 @6 L  H0 X
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
1 o5 f: a- J7 }, ?' t
4 P& F. E2 y6 @" gpublic class SwarmUtils {; y. C1 c, @% l. r3 K( w# ?) S0 e
  public static Selector getSelector(String name, String method) {
8 i: g- o: U( L, P) r! i    Selector sel;
' S, a3 ^5 t* o( `9 Q4 _    try {+ |8 Z+ c  }$ c( R' ]
      sel = new Selector(Class.forName(name), method, false);
: @/ a: M0 S1 c: a- k3 r    } catch (Exception e) {8 ]% s2 W3 h$ h4 g( f! o8 g
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
+ z! S" w$ y5 R      System.err.println(name + "." + method + " returns " + e.getMessage());
% e3 g2 A" Q$ D# y2 s9 Z. _. M. Q      System.err.println("The process will be terminated.");  z8 b: T0 p0 a1 Q
      System.exit(1);
6 p) T3 {# h8 F3 P' Q  L2 g      return null;9 R/ J2 B, y3 _" ^! h7 X. p
    }
: z7 @4 p& a6 y% S& K$ R    return sel;
( b: k1 S2 [! Z6 K0 Y1 z# V  }+ Y: p- ~: W6 |: z! N( n

4 B3 G- F0 A0 Z0 }6 n  public static Selector getSelector(Object obj, String method) {/ m- R; x) N, Z( G, m; P
    Selector sel;! Q$ ^. ^6 d  M& G4 P3 }* F4 Y
    try {
, e8 `5 d- o( P5 w. d" g2 L      sel = new Selector(obj.getClass(), method, false);
( e7 G$ p; v# Q& k    } catch (Exception e) {; |/ T& h, u- _6 t7 t. l
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) Z. v7 q; f9 p          + (obj.getClass()).getName() + ".");3 c0 z3 {4 z3 o  m7 J. s+ @
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
4 N; j) E! q" n/ j$ E, i( H8 m      System.err.println("The process will be terminated.");* f7 ^2 q& p) Z+ M
      System.exit(1);
0 \: l9 Z2 N/ w4 ^      return null;
' S& b: }# R- H6 n- U    }, W* \8 A3 ?: i: m+ l
    return sel;& E+ H; ^6 @, _' L+ Y7 N3 [) }
  }2 I- R/ l% W4 q7 k2 L. a% E( u
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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