设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9959|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行3 D; q4 ^% i2 l% M2 \
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行( s8 ?: v; Q! i6 L6 I* \
. s9 s' p& }0 r
似乎缺少了一个SwarmUtils的类,不知道怎么回事 # U0 F( b- ]# f6 b' I

8 K1 }* i5 q+ W3 g7 Q, F0 T朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
# N- ~" ^, O% ^& A% a5 i- F
0 C9 C" ]" A7 Vpublic class SwarmUtils {
, @9 E( e% O6 h0 n  public static Selector getSelector(String name, String method) {
% p& I6 q" S4 \# }! B    Selector sel;
  X: p, r3 B- c. F+ z    try {
# t- |8 T, b& O/ D% U) ~! f      sel = new Selector(Class.forName(name), method, false);" R! e/ ]+ W) _* n1 F7 q
    } catch (Exception e) {1 k: U0 m" {4 T, t& [
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; k- w% |3 }, t
      System.err.println(name + "." + method + " returns " + e.getMessage());
( Y6 U. A4 w' C. n0 A      System.err.println("The process will be terminated.");
/ r* O; W5 e6 q  A      System.exit(1);2 j  ]; j4 A" B$ j; @
      return null;1 {  y9 ]4 ~% C- a: j4 v: w: V1 u
    }" M$ G6 v9 [8 e2 s( |; `
    return sel;/ f* O5 H2 W$ O0 x: P
  }: y# F1 V) b1 G3 L" z
/ N- x+ I/ a5 y$ ~
  public static Selector getSelector(Object obj, String method) {
! J( a4 C% Q5 i/ a! w: b    Selector sel;2 k* F- m# U9 k1 z. R, I  K
    try {
8 J2 U% b& r) m" [+ \      sel = new Selector(obj.getClass(), method, false);
! I! z4 n$ P. F& E5 q    } catch (Exception e) {+ N$ r7 z$ L% e1 L  i
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "+ L3 O# T0 x* z8 J
          + (obj.getClass()).getName() + ".");
9 c6 l! q! j! [' y' z& y1 ?# R' I4 V: J& y      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());( y  C2 r4 r1 Y1 @- L
      System.err.println("The process will be terminated.");
# C) ~" Z6 V, y$ R      System.exit(1);! ~" N3 t  ~/ k8 x
      return null;
1 b7 T# q$ N8 i6 T' J    }
5 Z) |0 O+ H, A4 n) c" `& l    return sel;
  ]0 D- U6 n. T% Y) U  }
2 o" Q9 c1 @5 _}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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