设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7624|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
5 t2 o# e" c. \6 f3 Bsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行, a4 y" V4 j# f& ^, a
. X: B$ w3 D$ d4 P1 N. Y
似乎缺少了一个SwarmUtils的类,不知道怎么回事 ' Q9 `0 ?9 L( Z$ Y

  G! \% \& Y" l- Y% r+ R1 f: U: u; O朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
; t0 U$ f0 f( ]* g
9 J( I# J1 `, ^3 w3 T: ppublic class SwarmUtils {; y5 s3 E* N0 `' X$ E0 t" k/ {
  public static Selector getSelector(String name, String method) {/ G1 Y/ r" d! o2 v( C
    Selector sel;( [. U# u% m6 X4 U4 I; ]1 C
    try {  v0 g( g, m, {' H. C
      sel = new Selector(Class.forName(name), method, false);
1 a$ f3 g, ], W" t    } catch (Exception e) {$ Q2 F. b: X8 Z2 }& y  v
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
5 a# `! Q& j: M! y  p! _      System.err.println(name + "." + method + " returns " + e.getMessage());
# l( s. N& T; x1 v$ d      System.err.println("The process will be terminated.");
  @9 _8 q7 G; }. A      System.exit(1);
0 F; P& E. K4 w& ~1 C  r      return null;' k0 l' @# g' H4 W0 c
    }2 ~& b6 |6 A" b8 x0 L' T6 K" S+ e! O! X
    return sel;
& z0 ]- F2 D0 W: `1 Z% k+ A  }' F5 t! R% w* o% K. P" ^

) {! B* ?# a. D. r. B8 J+ t  public static Selector getSelector(Object obj, String method) {
* n- v1 i( \% c" B4 }    Selector sel;. b/ U3 U3 l3 e! t: c: t* ?5 j. s
    try {
, r% `- t  n/ t8 k      sel = new Selector(obj.getClass(), method, false);
+ }7 i! l$ w8 v$ Q- o$ v    } catch (Exception e) {
7 @$ [, T1 V& F* q. T      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 \" U9 C, \! m. x) r, m9 L          + (obj.getClass()).getName() + ".");
0 U1 r6 A3 @3 ~; T      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 G+ b6 Q2 C5 B8 X' L' w+ Z4 X
      System.err.println("The process will be terminated.");9 v5 m& r) z( c* p* m3 F
      System.exit(1);* |9 M- ~/ V" C' e) [
      return null;" l6 b$ e: t6 \7 X4 `3 j
    }1 ^5 V" u) d# }- e# y7 K3 t
    return sel;
- @: m. \# e5 C  }
  J4 w% d. h% K5 {6 F" G% w" c( k}

评分

参与人数 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, 2025-7-3 12:11 , Processed in 0.017917 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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