设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10597|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
0 F1 t! T$ `4 z! H  K  nsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
0 r8 X. d3 }$ k, W; K
5 M! m" d" B+ l6 p似乎缺少了一个SwarmUtils的类,不知道怎么回事 7 Z" T1 m$ w+ V) e
- t9 s! A8 E( n
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
0 V8 W4 D1 n# k, U2 u
0 X$ n& Y3 v+ ?public class SwarmUtils {2 G: ~( \; j7 g1 w3 A
  public static Selector getSelector(String name, String method) {
1 }$ I" g/ e( G: a6 `    Selector sel;
% x" A! `; y' \0 Y" i    try {
" i7 U1 e! A  O4 b) m      sel = new Selector(Class.forName(name), method, false);+ f2 k# ]! b6 R1 k1 N) H
    } catch (Exception e) {0 Y: q4 q/ k1 M+ }
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 K" M8 G5 a8 v! p% F0 X      System.err.println(name + "." + method + " returns " + e.getMessage());. |/ l5 J! t2 l! L  E' T& N
      System.err.println("The process will be terminated.");! H) v$ z- @5 y& x2 C1 ]4 D
      System.exit(1);
& ^5 U: I: D: t      return null;4 s8 k2 Z: l) M' Q1 ^
    }' G( n6 f) O$ W& }
    return sel;% A) S3 E& l* b8 a
  }' D+ N5 g* O5 n" r
- y3 Z: l. t. w8 [  _% q; @0 _4 A
  public static Selector getSelector(Object obj, String method) {
9 f0 S# c+ R* F3 k! Y    Selector sel;
. s0 `# s) H# E) D" o    try {: \/ K# A1 A' y* i, J! |/ S" Y$ T: X
      sel = new Selector(obj.getClass(), method, false);
, R! f: Z) i/ B$ {, Z1 Q    } catch (Exception e) {
0 o# E5 Z# l4 s# P. s- y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
5 o) L9 e8 J6 w. \/ z          + (obj.getClass()).getName() + ".");) D7 j3 K# X( H! M* {; E  Q8 e
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, A  W* i9 H, I* m! K% f4 q' `6 l      System.err.println("The process will be terminated.");
! f9 d' d( w1 F: N+ h      System.exit(1);( _( q. b/ t: k: C% K) |& p) T: {* d
      return null;# w+ ^) L, V- F" k+ w, D1 y
    }- N/ n$ Q9 e! I; M8 W
    return sel;
' H. W- a8 K/ H1 e. H  `5 f. B, C  }
( x* Q. _& A0 J( x# S: ~( g}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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