设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8412|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行$ n. I5 T8 h5 S1 [# j
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
* A- |; T3 s7 a2 O. b* U) G1 R+ C6 B  Y5 k$ g+ B
似乎缺少了一个SwarmUtils的类,不知道怎么回事 & {) j. E8 B# c, ?
" w! y, y+ m. X* S
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
: G: c, R; n! a
7 w; _" ?3 m8 Dpublic class SwarmUtils {  |1 R1 H" ^7 L
  public static Selector getSelector(String name, String method) {3 m# J6 x* n2 n7 j1 |
    Selector sel;
$ c% `! @1 N, B# Q+ f" H3 _    try {
; i8 b% g) ^) T      sel = new Selector(Class.forName(name), method, false);, g1 c9 Y7 y1 I; q" k
    } catch (Exception e) {
" H) V3 @6 J: ]# R1 H# F      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) q* G6 q& M) v0 V0 U$ J      System.err.println(name + "." + method + " returns " + e.getMessage());5 o" n" z. q$ z  ]+ x
      System.err.println("The process will be terminated.");
% c- {; k2 ?% E' q- O      System.exit(1);
( w" f! Z) w4 c  |      return null;
1 K7 Z0 F# R2 ^/ X    }$ P3 y. `% ^& L# F5 h
    return sel;
/ Z  W6 I8 R/ @) F  }
  p; y/ p9 T1 t& a
5 L. x9 d8 b0 D- m* U" w# i' |2 r  public static Selector getSelector(Object obj, String method) {8 e3 |) _& L5 J( `9 v- W
    Selector sel;& u2 h. U- R7 p  X: e# e5 T1 B" P
    try {4 d" f- V* }% f2 L$ \0 ]! k$ Q
      sel = new Selector(obj.getClass(), method, false);- y. [; M/ Z/ L/ w  f. {) D# O4 b
    } catch (Exception e) {
. v* G$ R* v+ l. v  ~      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 e* ]& s: h2 Z6 l. M" m6 `5 O          + (obj.getClass()).getName() + ".");
' D/ g. F1 Y( B* j: d      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! I' j/ }: g% i5 D+ L( [
      System.err.println("The process will be terminated.");
+ C+ O9 D3 @" N: y! K$ q      System.exit(1);
& l' y) p. K- r, C# y      return null;1 y! ^& N1 k  W' g
    }
/ O% s/ G+ z. {# w. h2 H  X    return sel;
+ W& q! M4 `$ X1 t6 r  }
- h& K4 Q& k8 I3 U}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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