设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9007|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行) A$ _8 r# y% d9 [
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
* Y9 v3 ?( z$ U, u, f% U- T" F% S" S+ n
似乎缺少了一个SwarmUtils的类,不知道怎么回事
; A3 }' ]1 ?& \9 m6 W' E% Y8 o1 i- \
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;+ N% V3 {4 O- g! O$ @: e. I

% a1 x7 F1 m  X1 gpublic class SwarmUtils {7 z; W% j& K) [. e( ]
  public static Selector getSelector(String name, String method) {7 f6 O/ E5 F# }/ c5 V
    Selector sel;
  A1 o/ z3 p1 O0 v0 L  ]  e7 t    try {5 E, z: ?% C% h
      sel = new Selector(Class.forName(name), method, false);
# V) `4 V  |: [5 [, t/ U    } catch (Exception e) {
+ `3 g; Z# t3 h, }" X      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ e0 c6 q7 F; M0 v      System.err.println(name + "." + method + " returns " + e.getMessage());
+ z% a8 A, m( _      System.err.println("The process will be terminated.");5 L) e* Z* H: Z0 c' C
      System.exit(1);
5 z  E* p9 a3 u$ ?' G      return null;0 f/ B- ?' L9 b3 u+ s5 g8 ~4 R8 x
    }
8 E8 C1 Q6 y( ^& ^4 W7 i+ \! N    return sel;& ?" A' Y$ S' O
  }
- R% s6 N1 G- C; P7 H+ Y% _# t" h
# a7 O# k( X; T% C  public static Selector getSelector(Object obj, String method) {! v  v4 |* P% ?1 Q
    Selector sel;) [* r8 P* `' y- U# U
    try {8 C) z" v6 j: N$ P8 l8 c& {5 x# H2 w  g
      sel = new Selector(obj.getClass(), method, false);
; k0 X; _# r# @5 Z7 c3 s2 K    } catch (Exception e) {
$ t+ v( f: c" t8 P/ I6 b      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ n3 T2 ^5 |8 t2 ]# B( w
          + (obj.getClass()).getName() + ".");$ b$ f2 C4 Z( f+ W, O+ v
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
; K7 D9 G% Q4 U! x' C, J      System.err.println("The process will be terminated.");) G. e+ h: b0 F4 @/ W3 k) B
      System.exit(1);
5 F, q- n/ J; ?- G% t" M  T$ l      return null;
. d/ B7 c4 b# K" ~  R    }1 @! C+ ?. z1 a6 f$ \( _; [9 z
    return sel;( s) q" ]1 y# B' H; D
  }6 \/ v( `( V3 B6 s# J  G5 t
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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