设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10512|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行7 b  t5 g) b) q! X1 A; [0 }: S
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行& s3 p2 _- ?9 `! I# c% C' ?
  Z* C) o( @( Q7 l% a* n# }
似乎缺少了一个SwarmUtils的类,不知道怎么回事
/ [: O% K- w* m; h# F9 b( R5 X1 e4 W0 w& T
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
, T1 M0 G( D( I& D" j2 t  C% e4 g% g, `+ E) ~( r7 t! f
public class SwarmUtils {
8 S& I! ^8 Y# P+ D; d5 b; L2 c( X  public static Selector getSelector(String name, String method) {
( H( C$ G4 a* \) s) R    Selector sel;
1 ^8 r! l2 W% d' R0 ^- K% e    try {: p( _; ^0 U. `3 m- \$ c: ^
      sel = new Selector(Class.forName(name), method, false);
* }' ]& x& V5 q: N; S    } catch (Exception e) {
( Q  d% L3 O2 y% T; [      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
  o' _8 u8 g/ u% B) r2 b# w5 ~" Q      System.err.println(name + "." + method + " returns " + e.getMessage());" Q$ Y7 f% d' b- d9 @) A$ q
      System.err.println("The process will be terminated.");0 k  G9 T% k+ P- Q
      System.exit(1);' b: g$ w% f  P3 s. c
      return null;
. R& Q: G! E: x6 w  J" }    }9 H) P& w" v: a$ w: x) j
    return sel;' G1 N1 J1 @5 \$ s
  }+ }6 W* O6 e1 V8 W5 c% v$ [- {# P$ K) J
  Q' k( a6 p8 Q8 t3 W7 C$ l! |
  public static Selector getSelector(Object obj, String method) {
& f9 K& J! [- b, v, ]    Selector sel;+ k2 W9 z- X$ a; `6 p% S
    try {
% m, F. ^% A/ O3 q( Y2 g$ p/ }) I      sel = new Selector(obj.getClass(), method, false);4 s' ~# y. h& M! p* E
    } catch (Exception e) {
' s. k, P; R9 X, P6 h, x: E      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' P- [; q# e- C' J3 ]$ M          + (obj.getClass()).getName() + ".");
  l+ W9 G! r! M/ E; @      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());8 c9 }* ~: N- }7 V& K( a& R4 B. h
      System.err.println("The process will be terminated.");
+ m# F; d( K& O2 ~0 y+ N      System.exit(1);
( y4 M1 |: V6 [      return null;* j& d  z( O; W( b4 k2 B
    }) U: \1 r1 d( a* u7 S2 W2 |7 e$ V
    return sel;
$ ?3 U% S' b* t2 ]2 i  }
( W8 x9 F! N$ m& F$ A/ k% w- g# r}

评分

参与人数 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-8-27 18:35 , Processed in 0.017748 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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