设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8885|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
& i" h7 _' `$ V. [/ R, O, S/ Msel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行3 `9 k2 V, L& ]' }4 @

( Z) y% [) t. H! N似乎缺少了一个SwarmUtils的类,不知道怎么回事 1 J" G* E3 M; W: R
7 [# u/ W0 B$ a: a
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;3 n# Q4 H- m+ O  A8 R0 x- ]

0 x# `) S9 p7 _3 k4 H& Q6 |public class SwarmUtils {% t& f, H& [3 L2 d
  public static Selector getSelector(String name, String method) {; a9 ^5 S. k( |
    Selector sel;
  o& K1 K" b; u8 o1 d2 j    try {" o5 F" x0 {7 _8 H" L* U# G
      sel = new Selector(Class.forName(name), method, false);  G0 l. Q+ g; `" z
    } catch (Exception e) {
+ A& C* h) \1 y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; Z8 e( `( ?9 e+ c  o! n
      System.err.println(name + "." + method + " returns " + e.getMessage());3 K; ^0 M. ?  w' j8 a- @
      System.err.println("The process will be terminated.");
+ Q1 A8 m& j: U& a" F7 E2 Y      System.exit(1);
: o0 A5 ~* |( C5 A( h* s. z, `      return null;
1 G0 x# o/ _; G2 g: _2 D    }4 x" K0 F! |- I8 V) h
    return sel;
) a& Z6 `7 N# s, w( w) h. u- E$ g6 D  }
3 r3 f' r; X. F; w# |7 [1 z+ i4 t! l' L6 Y* p) S- X1 |7 J7 a
  public static Selector getSelector(Object obj, String method) {' x! o, ^% |& r. U: u
    Selector sel;
- m1 \% J! F6 V# ~/ k) A% U+ f0 [. w    try {
8 B% @' \& h# ?      sel = new Selector(obj.getClass(), method, false);% _! P; H# C. ?/ g' X
    } catch (Exception e) {
2 i: f8 N9 Z1 L. \( p3 z+ N      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; @, x4 L- D. {0 U
          + (obj.getClass()).getName() + ".");' c/ |' n+ Y$ `0 J2 Q
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
* E# ?6 O7 |* I8 }) C      System.err.println("The process will be terminated.");
& h0 l: N9 @: M" U& R* `      System.exit(1);
; h- n# h" Y/ ^5 }8 i' J      return null;
: J% |6 o. ?& q1 {0 @5 F    }
" y4 Q$ Z& ^8 S/ m" {0 V. D    return sel;0 w1 z, ?$ o/ ?
  }! \  g. |( ]8 ]6 X! ~
}

评分

参与人数 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-7 17:39 , Processed in 0.015544 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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