设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9929|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行4 e6 V5 \9 y! I/ y0 O
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行  r& X( E  I! k+ D/ c. g
5 g+ U; l6 {+ H9 U4 g* b* G0 ]
似乎缺少了一个SwarmUtils的类,不知道怎么回事
- L' A0 v3 V5 p5 M! W( v" I8 l2 o5 J: X- }: h( e
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;2 C( t8 \) ~5 H

( y+ b' F4 R$ l  opublic class SwarmUtils {1 p' L; \, L' c# v1 B$ z
  public static Selector getSelector(String name, String method) {, A/ z2 [# h. \& a9 t
    Selector sel;
2 N5 y: i" P; V2 H- _    try {
' _$ a- f) V% z$ Y      sel = new Selector(Class.forName(name), method, false);
8 y- L/ q3 V& _- _    } catch (Exception e) {
- s% w$ h# A6 M* L, R      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");6 P9 X% m( w! ?
      System.err.println(name + "." + method + " returns " + e.getMessage());" G/ B" b8 s+ Z0 S8 P: V/ s
      System.err.println("The process will be terminated.");
' n- U6 e! u$ S& S& l      System.exit(1);
! ^9 C$ [: _3 G/ i# |2 c  _      return null;3 n. i7 D3 V- _8 s% Q9 x/ w
    }% N* ]% Y3 A* T5 o( ?
    return sel;! X; P) S2 l. B8 ^
  }2 I: Q6 |+ R2 r( N5 a1 x* \
. R9 W0 j* c, R
  public static Selector getSelector(Object obj, String method) {
( H, @- t1 w) c% l( p7 S- ?1 }& b    Selector sel;
$ n% |* u; s! i- J. H0 V( `9 w    try {
2 Y: ~! E% q6 H, }      sel = new Selector(obj.getClass(), method, false);0 }. C7 p2 K2 Q. `
    } catch (Exception e) {& r" n, g* U% d0 y2 `
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "2 H2 r! j1 u: @$ N& J0 ]
          + (obj.getClass()).getName() + ".");
; L1 S! t; X) l% L2 x/ B      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
; |" {  O$ Z) n/ @      System.err.println("The process will be terminated.");. f1 ^% S, `" X, ]3 |! U4 o
      System.exit(1);
/ I+ F  q7 [1 ?      return null;0 f  Z- p( h* p# T; m4 b
    }
& j7 n+ R8 b2 c, O    return sel;0 |( V, n: X7 q
  }3 B8 a! w7 g6 ~
}

评分

参与人数 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-6-27 04:29 , Processed in 0.021689 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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