设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10626|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行  I: R/ r$ j* e# _
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
' w1 [/ ^7 w1 N' i' V& L  w/ }! Z; e2 r4 V
似乎缺少了一个SwarmUtils的类,不知道怎么回事 1 x' g0 D. j, j  T) O# }8 C
2 L+ ]" _1 D: q+ m
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;* L9 i0 m. Y$ W2 K8 }& O

) k- z* B& w# j# U3 z0 M) g+ Zpublic class SwarmUtils {
/ D7 l, C( d) [$ G7 B  V  public static Selector getSelector(String name, String method) {
2 B) k8 j: T% T8 C    Selector sel;
8 N* Y1 [! v  z  G) `; {: m4 }7 A    try {
6 F4 _/ L7 B1 h+ g" Y* y& |      sel = new Selector(Class.forName(name), method, false);
9 S, ^; ^( i* V0 z$ j$ @* ]    } catch (Exception e) {
* B% H# r8 }9 K" N% s. y- t* A, ?      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* r7 S0 W+ T  j  j      System.err.println(name + "." + method + " returns " + e.getMessage());% K! h" ?2 G7 g. }9 v- `6 l- k
      System.err.println("The process will be terminated.");
/ W8 V) g) V1 G      System.exit(1);' V# K7 O) ]6 V$ e
      return null;
' K- e# [" D0 K5 O1 t    }( y: c4 e3 I* o# @1 V
    return sel;! i$ o# K' C) c7 L6 d7 {
  }
7 W& h" _! @! M: C* q+ m
5 J& M- f5 N& E: A. N0 _2 C  public static Selector getSelector(Object obj, String method) {# e! r* h2 t0 R. l4 r) ^* Y
    Selector sel;
) `% ]4 M$ a) M4 b    try {7 K6 d+ g9 `( _3 g) R8 d$ O
      sel = new Selector(obj.getClass(), method, false);2 u" k/ ~& G9 U# _8 O# x
    } catch (Exception e) {
8 g$ S+ }7 y8 l' \- W. D$ T( ]  T* \      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: i7 L$ G( Z: G3 D0 v3 h          + (obj.getClass()).getName() + ".");7 c% d+ A5 Q: V$ K
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
/ w4 U$ \; l$ _" k$ G* Q( B      System.err.println("The process will be terminated.");
0 L: i  P0 W. b0 b; ~+ i% y* T      System.exit(1);
; V7 A1 r* ]: ]: @7 q9 E      return null;' {! R9 n; n0 ]9 W+ O
    }0 Q0 W6 z. g$ F5 ?+ X
    return sel;  M$ ?6 \% i! _: s  W5 c9 k  i, }
  }1 h+ o$ m8 G+ ?7 R# k; P
}

评分

参与人数 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-9-11 07:17 , Processed in 0.019244 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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