设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9878|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行% h% }' h/ ^5 {& Y, G7 ]" R
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行+ Z7 t- s# x( z

. g, Q/ C# f& R- m4 X& r似乎缺少了一个SwarmUtils的类,不知道怎么回事
, _5 {6 S9 S9 v% i, l% R
  Q: z% {* `5 A5 v% N朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;9 |2 k, n0 Q3 ?( U: H
8 w  |2 u. j. f) f) ]; \
public class SwarmUtils {
9 o2 v7 l% ?% ~) t% n+ Y  public static Selector getSelector(String name, String method) {
; H2 n  y* C2 d4 U7 `. S$ S    Selector sel;
1 n. o2 J- O+ s5 B    try {
9 F; `% e' Q& l( h! c$ ?      sel = new Selector(Class.forName(name), method, false);, T$ w' G* w% L3 R; I8 J% _
    } catch (Exception e) {0 e2 R6 m" ^7 j% W' P
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
1 s7 N- s# v8 w* g  ~" E0 L      System.err.println(name + "." + method + " returns " + e.getMessage());+ j) R! k# ]' e+ Y0 v
      System.err.println("The process will be terminated.");, s  R% G( k: R
      System.exit(1);  Q8 K& n, {. n6 z' X. |/ Q
      return null;
. {* K- X0 h0 Y' h) L/ e    }: g; c! {1 _6 ?) \
    return sel;
8 b( M. |8 R& B" S0 m* z* D9 o$ o  }: z+ T7 e6 c9 l0 ~

0 {$ |% w9 ^# C+ D0 a* i/ A: K  public static Selector getSelector(Object obj, String method) {
; z! ~  X7 P& s# I9 |2 ]& E    Selector sel;
1 E9 X" h- N' Q6 l7 m+ }% u    try {2 R: p2 W5 V, x  |
      sel = new Selector(obj.getClass(), method, false);
* y! o6 Q  U; `6 o) e    } catch (Exception e) {& U6 w% X) D! K( h* m; m/ {) n# {9 ~
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
4 _* l6 J/ h% S( s, M- T          + (obj.getClass()).getName() + ".");* J7 l# i* x; L# w. Z' l! }9 e
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
8 x9 x5 U# s/ C  g2 {      System.err.println("The process will be terminated.");' y& V" K- j; s! m: s0 z/ N
      System.exit(1);, @* s3 d6 Y" a2 }5 Q+ Z# C- m
      return null;! V3 @  L7 G! }- {& W8 D
    }
9 }; M7 X" h) r' L  o/ |+ i" C0 m    return sel;
7 f) ?7 h3 \( F7 D  }
6 ~, [" _7 T. r) S5 @' M9 n}

评分

参与人数 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-6-19 11:33 , Processed in 0.016359 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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