设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9961|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
5 w9 q3 v' k; F4 `4 psel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行1 q: P% e& m1 o8 |; X& a5 g
5 r; ~" c! j) |+ j) z6 y' f
似乎缺少了一个SwarmUtils的类,不知道怎么回事
8 o( L0 E0 j' m9 N1 I0 \1 J8 D8 G2 G0 r- @5 j' O' K. }
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
) D3 _2 o1 E+ H& ^, Z: }
8 N  B4 ^, B0 E0 ~  apublic class SwarmUtils {% R* n$ L" S6 @5 l# Y! {
  public static Selector getSelector(String name, String method) {6 j) l: n9 F3 s- q4 y: k
    Selector sel;
4 |; ]/ y- x* V7 o5 A$ G    try {
- d+ a1 c7 p1 `$ ]. @; h% D4 m$ o' z      sel = new Selector(Class.forName(name), method, false);
$ F; A1 P- Z/ ?$ K/ G$ U. s    } catch (Exception e) {' F* Q4 t8 S+ a/ J7 a' ~
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. d' L7 r/ b) A2 a" c* q1 ?      System.err.println(name + "." + method + " returns " + e.getMessage());2 N: @9 q/ u4 P! p" [5 U6 u
      System.err.println("The process will be terminated.");
" b' Z' {" e4 q& R! s      System.exit(1);% Q7 Q1 b; M1 H3 N5 f- l3 E! {
      return null;
1 f  J) [/ S* X# ~, J* d% j8 V    }/ S; J% s  K/ M0 p
    return sel;, N* C* _8 q1 M5 j3 [' I
  }! ~- D7 u( n# y& t& h  w
) N/ P5 W- i3 G. _8 D( u
  public static Selector getSelector(Object obj, String method) {5 x/ u; j7 d' e# \; @
    Selector sel;
! W/ E7 I1 L/ ]    try {9 @: P' t# v7 [8 {# H
      sel = new Selector(obj.getClass(), method, false);7 B8 H1 \" w) _- g
    } catch (Exception e) {
1 w" @* J' f" Q0 A' ~. U4 p      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; J. n8 Q2 F: b, S, r
          + (obj.getClass()).getName() + ".");
2 L7 b  {/ ?* u      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 Z. K; ?# t3 p      System.err.println("The process will be terminated.");
% Z' n, I: j8 W4 x0 j* {5 U      System.exit(1);
9 p% U8 @* M1 C0 n& ]% m! n1 p, @      return null;
7 M8 q. a. V0 B  A9 D  @" w8 l6 w; h    }
% j0 ?, l& P  r0 T    return sel;) Z0 u# w* ?. I/ M
  }6 k7 b8 x) z- k% ~: Z
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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