设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8947|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
/ n- X( {8 B1 D+ X- Zsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行5 H" ^" K+ q% Q: V( h: ~" H+ v

) |! r, U- r( O, b) R7 x似乎缺少了一个SwarmUtils的类,不知道怎么回事 8 F/ H& e, @7 v2 ^3 W8 G

( j" T5 s3 c+ }6 X7 S+ G6 E0 P朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
  i+ f  F9 V( A5 m( ]* n
$ b/ z# H5 P; q' H. W0 zpublic class SwarmUtils {3 N1 Z7 M% ^3 Z6 |
  public static Selector getSelector(String name, String method) {% ?1 s9 X6 t) N' @/ c
    Selector sel;
. {# Z. O% o  N  _8 d; X3 ?    try {/ L) a/ I% H# \* d7 _6 x
      sel = new Selector(Class.forName(name), method, false);
' \, V; c2 u0 o. z& x4 t; _/ O    } catch (Exception e) {
8 r8 V+ C3 D. {* c7 m. r/ u      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 Z& \2 ?* y' X" \      System.err.println(name + "." + method + " returns " + e.getMessage());
1 a# j2 k2 }1 p; {. [" i+ y& x' y9 r      System.err.println("The process will be terminated.");
0 S, g! e' ~+ h( ]7 A! U      System.exit(1);
! a3 n8 e& m8 x0 r6 R' Z9 X, b7 p      return null;
+ \' w9 S) {  C: J+ G# z' O! X    }. @5 `1 A& ]8 X' a, f# U$ ?6 X
    return sel;
' c8 J4 d8 H- n3 _" U  }
& F. J/ M1 o( X& r" J5 Y1 w2 o1 W( f
  public static Selector getSelector(Object obj, String method) {
+ m; H0 F2 Q% x# B- Y$ s0 k    Selector sel;7 r: P5 n( \1 m) j1 l% R
    try {4 H! J  p# A1 l5 r
      sel = new Selector(obj.getClass(), method, false);
+ u4 A' j, h) t  Q" }8 n8 z    } catch (Exception e) {
7 R4 H0 k9 `" f% |' N7 h. I      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ `! }1 d( _3 z  e! {8 F          + (obj.getClass()).getName() + ".");; H- C  B' A; [# R4 [: c) B$ t
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! L6 s* S0 r+ ~& a- M
      System.err.println("The process will be terminated.");6 X( |9 g/ s& v2 Y5 b  n# H
      System.exit(1);
+ l8 F/ s, s" r5 T' _      return null;: u( s6 e) {% E
    }, U8 e$ U& u# M, ~4 P5 m1 Q, G6 J. j
    return sel;( @! @2 W! ^3 b' W; J! B0 x
  }
3 @* l  L! j* S' D- ]}

评分

参与人数 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-15 01:29 , Processed in 0.017841 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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