设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9707|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
/ L' A& r$ Z) x2 C7 nsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行' O7 G+ a0 o( m2 `1 f4 z, y
" A, i7 K3 S" ]4 V( ]
似乎缺少了一个SwarmUtils的类,不知道怎么回事
2 q! T0 E& R2 [4 A
/ j( q% M4 |- j0 b! `  J, o朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;6 ~$ J3 g- @5 A/ I; Q# r

* r& g3 c! v2 g" O1 G) Z! l+ Npublic class SwarmUtils {7 t7 p2 e6 _( `) m6 l
  public static Selector getSelector(String name, String method) {) M$ h( ~3 ?. @2 e4 k0 I1 `
    Selector sel;# `: {3 Y" l' l2 A
    try {
& {- {* @7 x9 T0 h* t: {; |      sel = new Selector(Class.forName(name), method, false);
- B( a. b# b( j    } catch (Exception e) {% \- ?+ v, R7 ^7 i/ Z9 r5 t
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");3 r1 ~/ A' x5 T# A/ r
      System.err.println(name + "." + method + " returns " + e.getMessage());# X! w( A: G: p
      System.err.println("The process will be terminated.");
  ], ?3 M9 }) x5 s      System.exit(1);3 e8 C0 v* z. Q9 e5 e) S) ]+ t
      return null;
$ C: |5 z6 ~5 }" d5 X5 u    }+ \! j9 A/ _# k+ d/ o' I9 L
    return sel;
2 n& ~0 i7 ^; l8 x9 {  }2 ?! V# h3 v  V1 _3 R0 ?
( K% k$ e, i* _1 X" [! q5 H2 K
  public static Selector getSelector(Object obj, String method) {
1 B4 `+ S7 Q6 I, l. ^6 |0 V3 j    Selector sel;
2 d; [. g9 N+ h7 X; y! {    try {+ X; e$ }$ L  F. d; @
      sel = new Selector(obj.getClass(), method, false);* n9 `8 b& \$ L
    } catch (Exception e) {
) }7 y) |/ h& R5 X      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
2 w: k; S# O) k) _          + (obj.getClass()).getName() + ".");9 m# f# ~# W( q  M! v) C* N
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());( Y- O( M" u$ k1 l+ b6 u
      System.err.println("The process will be terminated.");
7 D. U1 R$ V( W6 j3 r      System.exit(1);
5 |; D# w% I( d" D0 ~/ r      return null;
$ _9 \  H  `/ N. X' r    }) X5 B: ?5 V. m8 k% n
    return sel;$ n6 j8 w8 J% v+ E4 u
  }
  s& C  k; T; q. m$ e}

评分

参与人数 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-5-28 10:01 , Processed in 0.019281 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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