设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10456|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
2 t7 ?, I- l  g: |* Ssel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行) n3 K7 U6 R. K/ ~* N2 D! k
0 w: F% U3 Z" E5 I5 R
似乎缺少了一个SwarmUtils的类,不知道怎么回事
2 \4 ^4 |& i* S6 p) F' y2 f; J& \# c: k% z; d3 r1 z8 ~  V
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;  W  |2 E  X0 Z4 b# ~+ a! T
4 \( b2 [. ^' E" G) k
public class SwarmUtils {
5 A7 E) A' L" `( l7 H$ Y( G) d  public static Selector getSelector(String name, String method) {
- E$ Z9 D5 V: r$ S/ X* [8 ~, D* S, }    Selector sel;; H4 [3 f$ \( Q, z( D
    try {
$ a2 y" G! _( {4 W8 q- ~' }      sel = new Selector(Class.forName(name), method, false);* V) B7 a8 f1 ?6 m; C
    } catch (Exception e) {: l4 F# F$ i+ O9 n( O' v5 b
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 W: k/ a) `- r0 h. ], s8 O! M
      System.err.println(name + "." + method + " returns " + e.getMessage());
* d% p* b2 r9 T! L( S. X# f! q      System.err.println("The process will be terminated.");
2 v9 ^% j! ~$ C2 \      System.exit(1);' H9 ~) D. G' z% I; d) u% Y
      return null;! m- p5 y9 }0 ~0 {( d- V4 X4 R2 g0 H
    }
" Y- n8 a; W; w4 I4 q+ u    return sel;
. y/ r2 N/ j9 m) q  }
( _0 q* R  V1 i2 I
. c  |9 x7 o7 P* c  public static Selector getSelector(Object obj, String method) {
5 K, x5 z* b6 y    Selector sel;
; d1 A, Z* t! U0 j/ _3 T7 @8 j    try {( E1 X% e5 F& Y/ N( F
      sel = new Selector(obj.getClass(), method, false);
4 {% o6 h; ]: y+ h% a& R2 F    } catch (Exception e) {
' O2 Y7 b3 R: S. W% V+ s7 S4 f      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
/ r( P3 ]" ~. x          + (obj.getClass()).getName() + ".");6 H5 a" d+ _% B0 @7 w4 w
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ g( [2 F$ s7 g1 f$ Q      System.err.println("The process will be terminated.");7 [1 z# z; B- j1 ^7 N
      System.exit(1);- w+ C: x( l0 |# P& p! g; E& V
      return null;3 R8 o3 z; g) l) t
    }
: a" J0 e+ H: T) A, m4 i+ d5 x    return sel;7 M) a5 h; h" f+ ?' N. v
  }7 h/ v. V6 Q) j4 f
}

评分

参与人数 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-20 19:40 , Processed in 0.024140 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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