设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9834|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
5 c, a6 e3 E) N( Isel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
  X8 m" p2 T& q+ p5 E) W' D% M4 I7 R8 L( ?1 b% T
似乎缺少了一个SwarmUtils的类,不知道怎么回事
9 d7 @5 O" D. ^* c
: [2 ]& l: X5 o4 o! y5 I: n+ b朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;. l7 S" Y" @( y( d* B

5 ]  j% u& I( D5 h/ {+ _public class SwarmUtils {
/ l8 ]+ I) ^5 n+ h  public static Selector getSelector(String name, String method) {
5 p. B8 R* p0 G$ u7 ~2 W    Selector sel;
* m- N) [2 ~, ]6 q$ ?    try {
" N( [( [) h' ~8 i$ R/ A% @. [, b      sel = new Selector(Class.forName(name), method, false);" s8 Q& O5 J1 _; p2 b: n0 v% q
    } catch (Exception e) {
, C5 O% ?7 l  t2 H' N' E7 `      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' z: G  k$ a0 d6 m8 [! Y5 J      System.err.println(name + "." + method + " returns " + e.getMessage());. t- C: D8 b1 v! X3 b! h, ^
      System.err.println("The process will be terminated.");
, c) b, ?6 j- Z# \4 ?( V      System.exit(1);
0 K. t9 {! b$ {; c/ ?% J) i$ B      return null;
0 x+ ?7 S" x5 I# ~: l    }
% T# _' B5 h- a    return sel;
% e. Z( f/ A) y  b8 V" O  }
) g0 B2 C+ @/ G! T, A2 a  z3 N. _/ ^2 d/ Q
  public static Selector getSelector(Object obj, String method) {3 K% j' y+ z/ X* ?8 ^3 n" Z
    Selector sel;" @: P2 }, `. y2 A' K3 A1 S
    try {0 b0 H: M: Z6 G
      sel = new Selector(obj.getClass(), method, false);
) {, {" |6 P  N  N4 l. D7 ^0 g/ y    } catch (Exception e) {
/ }- I( \+ ?- E$ {0 a; @      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 l/ S0 W* Y) ?
          + (obj.getClass()).getName() + ".");
% R4 T, T* C# x( y- |9 g5 V      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( O% x- c3 U  L5 Q+ Q- S7 e3 F      System.err.println("The process will be terminated.");  {0 x+ }4 x1 R7 d
      System.exit(1);6 n* g6 g( G8 M* Z7 V6 K
      return null;
" g8 A! Q  A' N" Z5 b: N% J    }
( Q8 ]8 c. h! {/ q    return sel;9 J8 ^. b) M& t+ i, \$ b
  }
& W- E3 K7 n; 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, 2026-6-14 00:59 , Processed in 0.015490 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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