设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9061|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行2 j' b7 u: S/ K7 m3 w" }) h: t3 K
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行4 ^. U' m2 m3 e$ N0 E. Z
! W. V4 ]6 I9 C: @; P% F
似乎缺少了一个SwarmUtils的类,不知道怎么回事
( |  q  a" d9 \0 M. S
5 \" N4 V& H6 B  n! E3 J朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
! \4 @- F8 m8 f) o. g! r* A# f2 X) }" l) G7 ?+ T
public class SwarmUtils {( |$ M$ ~, m  R
  public static Selector getSelector(String name, String method) {7 ~& s3 U; Z% @8 Z
    Selector sel;
4 [3 Q2 b' W: V5 ]* o1 |) I    try {
/ h3 O9 k! s9 {, ]      sel = new Selector(Class.forName(name), method, false);( A9 Z+ \/ a: G3 {
    } catch (Exception e) {
! O& R3 w' ^/ s0 r( m8 o      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* I: J3 G8 {% u: _9 P: P7 Q      System.err.println(name + "." + method + " returns " + e.getMessage());! N: L# x9 V- A) Y
      System.err.println("The process will be terminated.");
  c! v1 \8 n' A) D/ |. d      System.exit(1);
$ q; Q$ O- l% ]% o( d& t      return null;
: V1 W4 {6 a- r; i    }
! @6 U* Y1 m2 g5 S; K    return sel;
) }4 Z& r% ?4 m! e  }
/ t5 ], c3 o1 M6 q; D
; a' \4 w# E% k4 ]  public static Selector getSelector(Object obj, String method) {$ ~% K1 l  ^! ]- y
    Selector sel;
7 S* K' V* k& F+ K4 K7 @    try {
$ S. }3 O- N1 ^6 Q      sel = new Selector(obj.getClass(), method, false);& ^: ?3 F0 m1 c9 u' }3 k
    } catch (Exception e) {
. @1 a9 h% Y6 g* k' e9 M+ p      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ". P: v# v- W* _- x9 b7 z
          + (obj.getClass()).getName() + ".");
" a+ `" Y) H. z8 F8 c) H      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());' K( K8 Y# R! k0 c
      System.err.println("The process will be terminated.");
5 s3 V- v" u* r3 i/ q      System.exit(1);6 `# v+ x+ k: J
      return null;
+ H+ M$ u8 K- i7 l9 w$ A( A+ w! A    }3 d4 M0 e, p7 {3 X! R$ S2 C; |
    return sel;
/ {) k0 q0 k4 K4 [: J  }/ n& Z; B2 e' d  p4 l2 N
}

评分

参与人数 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-3-9 12:24 , Processed in 0.016932 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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