设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9451|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
1 z: B0 K8 B$ d' `( Hsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行6 Z$ R) k2 A7 C& P
5 |( r: {( b' y
似乎缺少了一个SwarmUtils的类,不知道怎么回事 2 c& a% G- [" K$ m5 T
1 |! `$ e% b5 N5 e: ?) Z
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;( ~; c( Z7 }7 d+ n' b/ W

. R. G0 }% q7 n8 R* Y5 L) Bpublic class SwarmUtils {
' y& r, e5 v; D1 B) d  public static Selector getSelector(String name, String method) {
) p4 `9 ?6 i/ W5 n% O! h, s3 j    Selector sel;/ X$ E( s0 f! u  W) F9 B5 I
    try {
- r4 @6 C! a& h      sel = new Selector(Class.forName(name), method, false);
6 O9 u% J# V' |7 q; ^3 I    } catch (Exception e) {" [- f# H" l8 x6 [
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 p  f; d8 f9 W7 s      System.err.println(name + "." + method + " returns " + e.getMessage());
4 `. q; r1 P* O( ^9 C" _0 c$ G      System.err.println("The process will be terminated.");* P6 M; C' V& W8 O5 k8 I* n- V9 t
      System.exit(1);
$ W& I' y& h5 h2 O3 M      return null;
/ [: Q! C! Z7 s$ l: d5 Z. t( g    }# R8 D. i' A2 M& A5 G* ?, @
    return sel;
: M5 ~+ @( O2 p, b6 h& {0 N7 \  }
4 C( `2 U. H; F* V$ O' |7 f+ e, }" J
  public static Selector getSelector(Object obj, String method) {
; {3 [9 x$ {% u6 [; o    Selector sel;" @- U7 x% K) N( z
    try {
8 P6 W0 D; i0 U4 }9 b7 x% }  I      sel = new Selector(obj.getClass(), method, false);! |- {$ P9 ~9 z+ e
    } catch (Exception e) {3 [& x5 z+ o+ t& l1 S
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' l0 Y- k1 G- [3 h$ n$ M
          + (obj.getClass()).getName() + ".");
2 |. h  z. v! C0 P, o) `4 m      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());' I7 r2 X0 {$ i3 [/ ?- Q; ^( `2 e% Z
      System.err.println("The process will be terminated.");
  W+ d2 ~! V8 k  `$ u# t, v: s! b" y      System.exit(1);8 ~4 i4 C7 V0 t0 s
      return null;
' K0 u, y- }. g8 `8 u( `. {    }
  Q& L: K8 R: O    return sel;/ f5 ~! P9 {# n2 M# Q
  }* q3 a3 c" ], H$ H/ n& M, u0 C2 S
}

评分

参与人数 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-25 18:27 , Processed in 0.022298 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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