设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10627|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
$ ?# V0 H8 }2 x+ Q0 g# Zsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
& C' _$ t* ?. \: }4 S% Y: N+ }( j1 b  J( _3 S7 [/ [) T- t
似乎缺少了一个SwarmUtils的类,不知道怎么回事 * X! c. y/ H7 u8 E9 u/ }9 I+ n. y
" h# k7 Q0 ]# _6 w2 X
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;# l/ k8 M! w$ e! }6 v9 K
( ?' w9 k7 @; v
public class SwarmUtils {
* f% q' y3 W7 l) m2 j% y9 ^  public static Selector getSelector(String name, String method) {
3 l2 `, q6 Q3 [2 `6 G( N    Selector sel;# _3 ?, [5 z1 ?& i% g  Z* J
    try {0 G6 ]2 N8 R# h" I" d1 o
      sel = new Selector(Class.forName(name), method, false);
# R& Q4 i  E# ]& ?, q$ ^. j    } catch (Exception e) {
  I( f/ |0 ]" a1 F# m# B1 z      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 D+ K; O+ W& q4 B7 U3 Q
      System.err.println(name + "." + method + " returns " + e.getMessage());
  [4 b9 ^4 O- h$ A      System.err.println("The process will be terminated.");
9 s# @2 R5 m; b5 b% }      System.exit(1);$ h( B( _4 c: E# ~0 z$ I
      return null;2 s2 X3 C) s" d$ Y9 O
    }) B2 W* p1 }: J* [! ~! d* x6 R
    return sel;
0 [7 j. a6 @/ M  A  }
5 G9 Y  ?7 T4 l# z/ x% [5 \: B/ ~2 k, k% ~$ ^  E- k# x
  public static Selector getSelector(Object obj, String method) {. B0 o3 v2 J, X2 o( }
    Selector sel;6 t1 y$ n. o# S: p+ o9 @2 [- @
    try {
7 j! }6 h! K! z2 ]( X% q      sel = new Selector(obj.getClass(), method, false);
2 _# i0 Y# G8 H" a# A( v/ K    } catch (Exception e) {$ {* z# n- j2 s6 E5 ]
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# f& \% U1 m& [+ C          + (obj.getClass()).getName() + ".");
( Z3 H  k# a+ Z; c7 a/ f. E" ]      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
9 e( z: m. [6 q8 E7 ^. O+ M      System.err.println("The process will be terminated.");  S& ~& I+ B: R2 ~  N  O8 x/ M
      System.exit(1);) F* `0 ~" Q& c. ^) f% r8 C& @
      return null;# A7 X9 {/ K! C- r" {2 ~  b, K: V
    }
/ w" \/ M6 C5 v$ D* l6 F0 A    return sel;% C* C8 L6 i7 {& Y
  }
0 I! U! b! [* s& P* X4 X+ k}

评分

参与人数 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-9-11 09:07 , Processed in 0.017577 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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