设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10521|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
2 k: i3 L$ q# zsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行6 ~  o0 h% j) O& \

; _* d5 M8 g% l$ U, |# e似乎缺少了一个SwarmUtils的类,不知道怎么回事
0 c1 s. R/ g  U& {8 U9 X+ r& n7 S/ y3 d
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
) P& ?& K7 s3 l# G6 h) W8 B0 c
/ E, e0 b% Q! j* gpublic class SwarmUtils {
+ C4 Q% s/ M" X  s7 `  public static Selector getSelector(String name, String method) {0 E1 \( s- a  F* m$ v) A/ k/ P& H
    Selector sel;0 m, u9 c9 x- Z& D. u0 ~+ X
    try {
. ?4 P3 @$ Q- u% d3 P  V8 U      sel = new Selector(Class.forName(name), method, false);
. l$ g1 w& w" N' x$ {: S* z! e0 |. a    } catch (Exception e) {$ Z9 N' `6 H  G
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");/ t9 S$ F, n5 l; l  H5 P% F, U! A; U) M$ Q, |
      System.err.println(name + "." + method + " returns " + e.getMessage());$ u8 M8 {6 b5 F1 B
      System.err.println("The process will be terminated.");
7 C; s$ Q0 m7 L6 z8 L      System.exit(1);
3 D6 B5 H+ \0 v4 O3 k) X  j2 A5 t      return null;0 I7 T: |' B7 K
    }
+ X: w* L1 v3 Z1 N# y8 w% K: ^: F    return sel;
: o, ?, y, Y( q) Y& H2 z3 |$ R  }
, J! R+ M1 g- |% s* P1 O
$ b( R: N6 G; B  h6 W; N4 d  public static Selector getSelector(Object obj, String method) {# Q- ], t# o9 d( u$ s
    Selector sel;, f/ O# D( u# D- F" c' O
    try {0 ?% G* J' a* c8 _
      sel = new Selector(obj.getClass(), method, false);" j9 d5 H9 Z* f& I2 K9 w
    } catch (Exception e) {2 G% L8 C2 h8 X% {
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# Y$ }" k% F- e- g4 I          + (obj.getClass()).getName() + ".");  p$ y/ H% d6 j3 Z
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- _( M& ?  ~* e8 e+ I) e      System.err.println("The process will be terminated.");( D6 n3 N5 r% @8 \$ [, _: p
      System.exit(1);
( x, M8 l6 w' A5 }0 g( |      return null;
7 e) o, \& H* C0 M( I' L' g  u    }( O  o+ B3 q# ^8 F6 }/ W. w
    return sel;2 S% o# }2 x$ `% U+ V
  }
. L. \* r" O" u' L1 I}

评分

参与人数 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-29 02:36 , Processed in 0.015516 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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