设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10042|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行: G9 n8 V5 c& a7 e
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
: N8 i3 R7 w% U( q
) E$ Z" g) z( l8 h似乎缺少了一个SwarmUtils的类,不知道怎么回事 3 c( c0 \+ k5 H5 v7 f/ ~3 H

0 Y+ N1 C4 U7 \. r" X. Q. [朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
! w4 E$ d1 Z5 J5 I1 x2 f1 K
8 J. s4 i0 G) O2 |. [- upublic class SwarmUtils {
: j5 n+ [% X+ L8 D! E& B  public static Selector getSelector(String name, String method) {! W: e: Z% r" I3 M# ]! K
    Selector sel;
7 L8 m  K, k+ i" \8 o. r+ @    try {7 s" H( |1 v8 n9 P$ E' j7 l
      sel = new Selector(Class.forName(name), method, false);: ~8 j& n( a$ X/ R& J# N5 n
    } catch (Exception e) {1 T* [' F) }' y& z0 g# N/ C  A1 \
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");+ z/ B8 y9 J* f0 E- ?& s* d0 ?0 p
      System.err.println(name + "." + method + " returns " + e.getMessage());5 A7 _9 A/ E+ T7 _: j
      System.err.println("The process will be terminated.");! o+ j  z8 I  Q; @% b8 K! B* N
      System.exit(1);
6 W" ]. u0 x$ N8 t# C      return null;% A) m& z7 ~/ Y7 N
    }
# `$ C2 D; I4 [% L- O0 m    return sel;9 ?& S! U' c4 @* J2 |+ Q
  }/ L3 Z% G5 ?3 [+ [9 Y* w1 _+ m9 t
/ W. ~9 W# |5 Z, ]; Y0 ^: M6 V
  public static Selector getSelector(Object obj, String method) {- U" {2 E5 h" h( G
    Selector sel;) F: ^$ c. V" _$ m, |3 m7 P+ ?. N9 r
    try {
  \. P( b/ |# ]/ }& I      sel = new Selector(obj.getClass(), method, false);
5 _# b& g5 b  M    } catch (Exception e) {& v; \6 v. V1 k. R9 M
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" L( Z3 |, P  F8 O1 b8 r; Q          + (obj.getClass()).getName() + ".");
4 i2 N' t2 g5 a% G5 U; @      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. |+ \) Y% l8 o. F- K6 @, v
      System.err.println("The process will be terminated.");
6 l3 z( M2 W+ P/ |8 j      System.exit(1);
/ E$ N. [( Y9 Q      return null;
3 F  V( W/ b/ n; @; F1 a( ~    }; j. E: M' P/ }. E" ~
    return sel;6 |% p8 B0 p7 \
  }
, a* T- q: Y2 v: I}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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