设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10194|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行7 r; n# i0 _- h- W& W
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行  [5 J2 }) C0 Z

3 \- y4 S. c% W# y' i似乎缺少了一个SwarmUtils的类,不知道怎么回事 - P+ f( _( m" z7 R) l5 R/ O
5 A& ]" F% N7 F& x1 l3 b5 Z7 ?% b
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;$ r5 L0 w6 W! ^  g( _. r' \

7 j0 J$ o. [- i8 F! i4 T% r$ _- Mpublic class SwarmUtils {
) H9 Y  X8 N" @  public static Selector getSelector(String name, String method) {; }7 h1 e. x$ m; a$ H! l
    Selector sel;
' h0 x) w% k1 P2 |7 d    try {/ f- O# w# T! ^0 e" ^3 e* x
      sel = new Selector(Class.forName(name), method, false);
7 f/ P& j8 v% y: U    } catch (Exception e) {: k# o+ V* t& [; F4 p0 V+ l
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- n' s' _2 B# m, l1 E* J: {
      System.err.println(name + "." + method + " returns " + e.getMessage());/ y, t: S, v' C5 l
      System.err.println("The process will be terminated.");
" f$ f# w7 q! U8 ~2 j! Z      System.exit(1);8 _  y- F( j2 k: m# w$ {" S2 ~* N
      return null;: j- ]$ ^9 \. N& f. K' y
    }
, |9 q! |) Z$ u    return sel;
5 J8 L6 |, ^3 z% K9 a/ L/ f" x  }
2 y  \1 x, W2 U$ B: d, ]
- {1 y+ ?, M4 b7 S1 V" ?0 Q  public static Selector getSelector(Object obj, String method) {
' W! k0 O& _7 a" s- {! D/ Z    Selector sel;% {9 ^5 ?+ G* Y/ b4 ~- \' A. C
    try {
& M$ u5 E# ~" }4 W7 k* Q      sel = new Selector(obj.getClass(), method, false);
9 m, P+ ~, y# q9 D, G8 f( Z    } catch (Exception e) {# i% k& J% F6 i( t; @" K
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- |+ K/ u0 S) J/ N: T          + (obj.getClass()).getName() + ".");' r8 q- n0 B5 P  k1 U9 m, c
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( X* h9 x7 P3 t! E( L6 V      System.err.println("The process will be terminated.");4 T  l2 z4 {7 h) i2 \
      System.exit(1);& K& P+ b: Q; ]. w% F' H0 P
      return null;
, k$ }: m6 k" P& f    }
1 T8 Y3 _0 b8 _/ B    return sel;
- b) R9 L0 P$ o+ s6 E  }
8 n7 B- k& [0 n9 g& {; |}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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