设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10052|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
. W  U% f6 _0 F3 Gsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
) i# |. J1 r. g2 K7 U' J4 {1 }4 V; d9 |7 w( X$ c! C/ H* ]
似乎缺少了一个SwarmUtils的类,不知道怎么回事 ' B* h% B, t0 e5 b6 b) n  N
2 t" x! R* _  @4 f3 Q
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
5 f( }8 o6 p0 R) U( }
8 L* D( m6 R9 w/ p* apublic class SwarmUtils {- w! N* g9 I  z/ A( j9 I# ^8 L
  public static Selector getSelector(String name, String method) {0 W( b4 r0 W+ a8 ?7 {" q
    Selector sel;+ n; W  R) y9 a( D6 S
    try {
+ y. d0 ~4 z% d& U' y      sel = new Selector(Class.forName(name), method, false);9 U( Z: h$ _, m. D' y  t
    } catch (Exception e) {
) J( ^& J  W9 X, @8 |      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- J- d( K) ~5 t5 W) o
      System.err.println(name + "." + method + " returns " + e.getMessage());" N1 S5 u4 U( w! u! ?' T0 ]
      System.err.println("The process will be terminated.");( B& d7 |  G% L' J( Y/ @
      System.exit(1);$ {* J. G  U& x
      return null;% q$ _7 B9 G% L3 D4 x8 i3 `5 Z
    }
3 A# u: }/ ~; h" Q/ @6 j3 r) o7 Y    return sel;5 X1 _1 y/ |( ~* q; M7 f
  }# o: B& W& |. x+ x8 O6 E
2 p; S- @3 Q. f8 T9 c3 ?7 @- G
  public static Selector getSelector(Object obj, String method) {& f. E% W; s3 b% H$ K, S  }8 R  r
    Selector sel;
2 G& P# g7 K9 A/ r    try {
7 H) d6 H% X7 r  A( O      sel = new Selector(obj.getClass(), method, false);
( I$ }5 G& L# }4 Q) n    } catch (Exception e) {
2 N! j2 r: N# M  d; }9 x& p      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
  ]- B9 H% g8 v8 N( k7 N' n          + (obj.getClass()).getName() + ".");5 I" k) l5 W; ]. r; h; p0 c6 f) W0 c
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 m9 o9 [7 ?5 u& M( U( `
      System.err.println("The process will be terminated.");) c0 u6 d2 R' S/ {; O, D
      System.exit(1);$ D$ k; j! Y/ Z3 j& Z3 ~* D
      return null;5 K. y$ H+ Q& `7 h7 L# J& h; e
    }
1 K4 V2 `% O1 J% @    return sel;& I! X6 A8 s1 g1 y+ N+ I# Z4 B
  }. o3 r4 l( J9 X% C
}

评分

参与人数 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-7-12 03:21 , Processed in 0.022039 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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