设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7940|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
' l$ J% {* b8 C/ A. C2 p3 Z+ {# |& vsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行# ]/ P* l0 @# f( t! d- k

  v3 V# \8 e! }似乎缺少了一个SwarmUtils的类,不知道怎么回事
) e$ q& L& _2 Y/ K" H+ t5 Z( {) e/ {1 k& I5 D
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
4 d4 l) b+ c" h0 @. G2 q6 L  \' U* j5 ~
public class SwarmUtils {+ X. p9 [. f1 c% K; p# u
  public static Selector getSelector(String name, String method) {5 ^, J& j0 b; A6 W6 W# c
    Selector sel;
, {, f- _% d6 _$ [( f1 J' _8 U# r    try {4 S. T, y3 q; I3 a6 C
      sel = new Selector(Class.forName(name), method, false);7 v% }1 X  z* _8 Z
    } catch (Exception e) {
% J7 l' V& `# v6 Z) Z9 l  c* X      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 f1 A9 i; b2 c* n5 \$ ~
      System.err.println(name + "." + method + " returns " + e.getMessage());7 }6 p* x: S% _1 ~9 d; t
      System.err.println("The process will be terminated.");
* \9 N: U9 h* w$ r! ]' Z8 l: _, d      System.exit(1);% y, J% _- Y$ r& p- ]9 T' Z
      return null;
1 E% j0 }. h2 u& c& f    }" Q) Q& A- c+ A
    return sel;, v3 c) x) I. r/ k. q
  }4 o) |& ?9 p* B

. t7 J3 C4 X  n9 z, p* J  public static Selector getSelector(Object obj, String method) {
1 P# N8 o" ?* e+ r+ @. |    Selector sel;
0 Z3 e* v9 Q8 T+ s6 N' l    try {
7 u  f8 ?$ p+ v1 e7 m      sel = new Selector(obj.getClass(), method, false);
9 ?6 C3 u8 s1 D) M" j8 H* d8 Z    } catch (Exception e) {
7 w6 J& [' I& M2 N5 O1 Y+ P+ U& \      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: f: Q5 n" j5 A* |          + (obj.getClass()).getName() + ".");
5 {9 ?+ N% N5 C* j      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
) o& {8 r  e, @/ V) }) v      System.err.println("The process will be terminated.");
) i3 }8 d2 N8 t  |# ~+ b. ^  t      System.exit(1);  s# e5 R1 `/ p/ v$ M; f" O
      return null;: f. W2 K- T! E) }
    }
) i& U/ S+ t' d- o6 C3 z9 ]    return sel;
4 h" s1 E* X0 t& N; t" `  }
, {& W* l/ O) F: O( h* ?}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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