设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8954|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行, R% x) D1 j3 N' \! W' I7 c6 @) I
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
/ Y9 T6 j* \. j8 s
+ u: f' {. n: ~' k似乎缺少了一个SwarmUtils的类,不知道怎么回事
$ t2 A" g7 {8 h% }1 w/ A0 a0 }+ w5 i4 z: Y! _5 ~
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
6 F9 x4 T0 ?# v
( m( J# r3 @, j0 Xpublic class SwarmUtils {
; ]9 I# p) ^" m! @2 a' Y  N4 E  public static Selector getSelector(String name, String method) {
" {+ j. V& |# {9 u6 e4 u5 ?    Selector sel;
/ Y6 K# D" x3 S& }! m5 g! E3 A    try {
# V+ s' [9 o* O  n+ p2 _& O) _- T, F      sel = new Selector(Class.forName(name), method, false);# ?! V' [* ^" _; f/ ]& ~( H
    } catch (Exception e) {
0 @3 A5 ?9 m* f$ C  \      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- }( C% b/ {1 l1 U& a* x: R" z
      System.err.println(name + "." + method + " returns " + e.getMessage());
3 q; i. p1 g* R% j# ?- L+ K' w      System.err.println("The process will be terminated.");
  V5 Y  L# c* _" ?      System.exit(1);, Q$ j/ r* R  [! A7 V/ Q4 J: X
      return null;% l! R1 t7 f) D  j2 W
    }
: @* u, Q+ ]/ G  Y$ [" S' ~    return sel;
' [1 A5 h% `1 z0 g$ m  }
' q8 P" C4 ^: c* a1 v, H6 }
) p  g$ H0 X6 w3 M% o+ F3 \  public static Selector getSelector(Object obj, String method) {
& ?1 ^4 H4 u$ M4 c$ \! C+ m( m    Selector sel;% U( \- r1 X9 D
    try {, x* q4 W# g. K- u# V  h' l8 u
      sel = new Selector(obj.getClass(), method, false);8 e$ E8 Y+ U) R# U0 h' K
    } catch (Exception e) {
( m# ]0 I. V# l' T0 U% s      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" L. z, o" ~) G' I" V          + (obj.getClass()).getName() + ".");
5 s$ P, g3 @" o7 ^      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( M, ^# @, G  n8 S; r4 v& r. [! D      System.err.println("The process will be terminated.");, |! v% I: Y7 V. L+ C; F* i- r, @
      System.exit(1);
' k- M) ]0 G) C9 G; r      return null;
' ?2 T9 I7 S  @- T. k5 L7 o    }+ q. |. e/ y: A2 _. Z
    return sel;: i2 q' z* m6 q' E
  }
1 I, H2 T8 P, U# g% B. Y7 Y}

评分

参与人数 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-2-16 22:55 , Processed in 0.021878 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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