设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8861|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
4 r1 t+ W8 ~( R& C& w5 psel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
" P3 d- a2 `, q- K8 a4 M. l8 p! S2 e$ }: e
似乎缺少了一个SwarmUtils的类,不知道怎么回事 3 o+ w3 ~4 m! x% M8 T

; j* @3 t: G  \# P  L朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;7 G* |* ~, L* J+ |# m, R

, i" m& P6 _. @% ~public class SwarmUtils {
+ A% G! B" B2 b" J0 p7 z2 H- b  public static Selector getSelector(String name, String method) {
, h8 r; K3 H# }; R% P    Selector sel;4 b/ J& U. p2 w
    try {
. a8 i2 w5 j  s+ L/ G! f% \8 U      sel = new Selector(Class.forName(name), method, false);5 J2 f& I2 T: C9 M
    } catch (Exception e) {
4 Y+ S3 Y4 C: C' {: g      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
& N- N' e# ?4 ^% Q- J4 s$ m- T      System.err.println(name + "." + method + " returns " + e.getMessage());
5 a! n2 x. q' ~- r) b: f& x      System.err.println("The process will be terminated.");' v/ ?; S6 m; S% c  E9 r8 T
      System.exit(1);
6 d6 A. {) a% j6 W/ n' g* r2 b      return null;
" A6 `% i& f2 n, C7 y: }3 ^! s: _! d' n    }
0 O( _, w6 E& |( r% v3 ^    return sel;5 F3 o! K1 O% d! i3 E  T+ C6 E
  }
3 f  q7 d, ]* Q4 X, l$ }( m' x( k( m5 u
  public static Selector getSelector(Object obj, String method) {( W" G- z) A0 f* X
    Selector sel;1 x# O( }* x, E- l2 t
    try {- X# ?! R. n9 E* b9 B- q
      sel = new Selector(obj.getClass(), method, false);
1 T) i. U* e3 H2 z) Q    } catch (Exception e) {
, g% d: z/ `& D+ ^      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
2 i3 c4 l; e9 L          + (obj.getClass()).getName() + ".");- w( x1 m7 w/ E: U. \* L
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
0 ?; W% w: \2 q6 _- i      System.err.println("The process will be terminated.");
& u# [. M7 C& M( T! K" X      System.exit(1);8 |# |( _) {0 ]1 j& Z6 s9 i8 `
      return null;  X( B  I, w! H1 @9 f& w& B
    }
8 H1 t. z. D3 Y1 Y6 n    return sel;
2 ]7 E, B# ]' Q1 q& g! L  }  w) R- E: j+ Y* `, n4 f# b
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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