设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9826|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行( m* G# U) B! f' x+ ^4 U3 Y. D1 C5 h
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
' c/ U5 r: i. {- x# W' j/ m1 w( ]5 o
9 _% \4 l) o9 s! t7 x/ U似乎缺少了一个SwarmUtils的类,不知道怎么回事
% H) v9 E" c3 u  ?" [
8 d! K: l$ O& Y* K  ?9 W9 O/ r$ u朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
& p; k$ E. `8 R) c
- m8 ~4 m# D1 `$ O3 G$ Upublic class SwarmUtils {
# M; @) J2 K- p6 h* m+ e  public static Selector getSelector(String name, String method) {3 B" s& Y9 x' w8 j( \$ n
    Selector sel;
# Z4 S3 R8 Y- n" Z& z' I# t7 u    try {
! F; ]4 S9 X, f& i: J7 l      sel = new Selector(Class.forName(name), method, false);
" ]: ?$ q' \& I! p8 z& t    } catch (Exception e) {
$ K3 v2 U1 y0 t# ]! P. x      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* V. L8 X( l; P0 l
      System.err.println(name + "." + method + " returns " + e.getMessage());) M0 I3 c. o5 P( R4 z
      System.err.println("The process will be terminated.");1 B# c. R) k2 o
      System.exit(1);
) ]. ]5 b1 ~8 z, y      return null;$ d' v* G2 J0 V8 W8 W2 y* B$ g
    }
" L) B: W. f) X9 a5 d    return sel;
9 Z& P+ D+ h7 a# H1 U3 u  }* u3 S3 `/ k: z( y; ], @  }/ s

# X/ [9 q, ]. p) m8 Z+ }  public static Selector getSelector(Object obj, String method) {
; m) W4 ]5 t4 {6 H8 U3 Z' d    Selector sel;
+ m7 G) `1 e: a, H+ b. x    try {( S! M; `7 K% d. m7 v/ o
      sel = new Selector(obj.getClass(), method, false);
& Y3 t0 b' g9 n5 J  a" b+ M! I( l" y    } catch (Exception e) {9 y: |* B" X; U; h
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& _/ t; f3 [8 r* W          + (obj.getClass()).getName() + ".");! J6 f( z: ~! J- y0 k5 Z1 b4 T
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ T5 [0 I9 ~( U      System.err.println("The process will be terminated.");
4 m  r8 k/ i0 }( h' A0 \. v7 t6 b& T      System.exit(1);' l2 S. S5 n+ O
      return null;4 B" G. L7 B' S$ H* I5 J1 E
    }
, R: U! l. o5 H7 [$ f% ]/ Q    return sel;% a, T8 r6 O, t. ]0 O) w% i
  }
: ?# n3 s" |4 r. }) l+ 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-6-12 18:32 , Processed in 0.024477 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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