设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9723|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
! h0 q- q: H# e3 b8 |& P4 gsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
# E' z6 R) T5 }" @. ~* H) g1 C  b
; a# K4 j: c0 k似乎缺少了一个SwarmUtils的类,不知道怎么回事
, w: ~3 z2 Q4 L- e$ I9 J! R! N  W% _! |% I7 D( A* ^  Z/ J
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;- A7 n' J0 Q: s8 c1 t  A4 u

  O# o, f! _2 _9 Cpublic class SwarmUtils {6 {5 X# V- I' f- }3 Z* n2 O/ q
  public static Selector getSelector(String name, String method) {! K2 H+ n  o: j8 t. a
    Selector sel;
" {: Z6 _) h+ x0 k9 a" ]    try {
3 ~  Y5 y1 x3 @% A# K3 Q      sel = new Selector(Class.forName(name), method, false);( \/ q0 P) U1 h) O3 G8 @
    } catch (Exception e) {
( Y, q, ?* r8 B8 b! b: E      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 J4 y( v( Q' R! ?
      System.err.println(name + "." + method + " returns " + e.getMessage());( ?# N3 E) ], j' V
      System.err.println("The process will be terminated.");, d- b# c6 W) J5 y) k; ]
      System.exit(1);8 [8 M: I# U# x1 X+ |- v
      return null;2 s; b* c: v8 o6 |
    }
' x9 j; h( w( Y    return sel;
, e9 c  h5 U; I% P  }
- L5 W! o9 K% M' n) u$ [7 U
4 h4 \0 w/ C( G" j$ Z2 p  |& ^1 F  public static Selector getSelector(Object obj, String method) {1 @" _) c. {3 `+ F
    Selector sel;
: D) q/ ^0 o* e# l2 R( J3 u4 \" C    try {0 q& W6 @8 P  Q. T0 i4 ?  Q7 g! Y' u
      sel = new Selector(obj.getClass(), method, false);4 `- g3 f1 w) d/ u
    } catch (Exception e) {# E+ S$ ]1 r# e) u9 H! p# ~
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "" p7 }" T2 l- H) V
          + (obj.getClass()).getName() + ".");- J  d! s- ?/ v" T5 V" T
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());8 ]# d5 U& h2 T; W
      System.err.println("The process will be terminated.");0 X0 K1 A4 q. O+ C
      System.exit(1);- b4 ?  b4 L0 V& w% N
      return null;$ Z( {  j1 N4 M8 m/ `3 t
    }3 ?+ O' ]2 _; |  L! z! [8 ]5 n+ Z( J
    return sel;
0 U1 t, J7 J: H% b: q/ N% S  }
. S" h, ^2 K+ W( Q}

评分

参与人数 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-5-31 09:42 , Processed in 0.013580 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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