设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9409|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
  P, t/ c& q4 \& gsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
: K$ @+ ^! Y; H# X! B9 s9 v& O8 m$ v5 q/ M# |- S1 z. k
似乎缺少了一个SwarmUtils的类,不知道怎么回事
0 W) f; {6 ?, M" p  f6 ^9 S
0 Y  @6 u9 T! S3 [# j朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
; H' p) X# q9 j: D- f; W3 p
+ T! M# [7 d) rpublic class SwarmUtils {: E2 H+ I1 T5 m
  public static Selector getSelector(String name, String method) {# E9 `2 a% c' o& |3 b% e, V
    Selector sel;
7 y. L7 y8 J" @2 B8 D    try {
" J9 l5 l% m5 p! l      sel = new Selector(Class.forName(name), method, false);2 Q1 [) e0 {' {" D- s4 I. P; u
    } catch (Exception e) {
2 Z1 P$ S: d/ u, Q+ c. Y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) x2 n  ^& g* _& N- _, o      System.err.println(name + "." + method + " returns " + e.getMessage());2 \$ s* X$ m- e8 t3 Q
      System.err.println("The process will be terminated.");
* G, L9 H  \0 M! ?+ g  |# H+ S7 w      System.exit(1);
6 J$ S' A1 w3 A$ @- ]      return null;
3 Y$ f# s3 W+ [) W    }- V! r% k! ]- ~% Y# M3 x! h
    return sel;
) w9 o; G/ a: O# j$ j4 w  }
0 S* D7 F3 [3 A, i# B6 j1 ]. u' e* M( o' ?! Q- e
  public static Selector getSelector(Object obj, String method) {
# n  @8 _! b/ J7 m4 O% q    Selector sel;
# ]' \! @, a* {2 e8 T: B+ \    try {) _) v3 c/ }- Y( z2 |* I
      sel = new Selector(obj.getClass(), method, false);
- i( j# J2 O. ~' q$ {7 h2 o1 w    } catch (Exception e) {$ V0 u: O  O; y8 T2 j
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) @/ S; A2 \- [/ q          + (obj.getClass()).getName() + ".");
# P- O% ^& }* [0 _  T2 c* }4 \9 b3 `      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% |" m2 ?# v' p( y7 v5 E
      System.err.println("The process will be terminated.");
, x5 S* S: l  _8 Z, S; N      System.exit(1);
; \! n3 n0 J5 A& E      return null;
# W! {# {) j( M    }* ?$ }% O+ C8 p
    return sel;- v* H1 ^( {4 w- F# \& f8 ?+ D$ C
  }+ u) Z: F! P: i: D1 p5 k3 b, 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-4-19 21:29 , Processed in 0.021135 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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