设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10074|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
3 L& W4 z" V! p. v6 |3 _0 Z, W* Dsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
9 D6 H$ \- H6 u) O( V' E' Y& \$ K7 @) y' U
似乎缺少了一个SwarmUtils的类,不知道怎么回事 + a* b. ?* z4 }5 O# E
/ l! S: I4 N" }9 X( l
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
- u& ?5 I9 e/ v' W+ ^- H
8 Y/ Y; c, d8 d* @- K# T  ypublic class SwarmUtils {1 Y+ j% @: c8 i
  public static Selector getSelector(String name, String method) {
2 |# {  j# e) v    Selector sel;; c) F* `& i( s8 f  ~4 h8 o" ]
    try {
9 O9 c* S' z$ L, J      sel = new Selector(Class.forName(name), method, false);% P/ F/ U6 z- r: r* @
    } catch (Exception e) {& s8 o# e$ X$ s" f  c7 @
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");1 P. D8 C, K5 T9 G$ ^
      System.err.println(name + "." + method + " returns " + e.getMessage());5 ~7 K2 d/ M* M6 U" U# U
      System.err.println("The process will be terminated.");
' W  f. F- v/ d$ u* ~! O; g* ^      System.exit(1);
- M* i* _+ F. y& P      return null;
% |1 K8 V/ P$ D    }
, O. n* f9 u3 ~: O    return sel;5 X8 k: l: f* c0 q" W* Q, B
  }
& M- R& q0 _: b( E0 f) {/ B( m. h% P/ g, d  Z8 M; ]
  public static Selector getSelector(Object obj, String method) {# t, |# f+ l4 p9 _/ M* i0 G5 H
    Selector sel;
$ \7 b7 o( Z; a$ j' ]9 M9 d    try {
$ ~( }* W, n* {3 O! N      sel = new Selector(obj.getClass(), method, false);
1 Y, U8 `4 C$ n3 O' J( t    } catch (Exception e) {/ Z+ I4 x/ C$ F" a0 V- B! @
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" z% l) p  x" Z, R0 m9 Q, n. j          + (obj.getClass()).getName() + ".");( H- j1 \0 D8 }4 F- S
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
. J8 J4 `/ x3 M. X7 `      System.err.println("The process will be terminated.");) G5 v7 g5 h* S; [
      System.exit(1);
- \3 z" i% p/ b4 q/ \      return null;+ }" o$ V2 Y5 Y  E; w" X
    }
; w# m7 E4 \4 p$ M, j$ k- f    return sel;, a4 ~+ l0 {8 i
  }2 T  f3 _2 b3 I& H& c4 a3 q) Y3 g' c
}

评分

参与人数 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-7-14 11:28 , Processed in 0.019246 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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