设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8557|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行# m6 l/ @5 y3 o& L" h. h/ s
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
+ f$ T  l, X( P1 [& D* ^8 R2 v7 A; d+ K, `5 k* g
似乎缺少了一个SwarmUtils的类,不知道怎么回事 " x: L: o. C8 l9 v! v, @! C

- i) R1 T* i9 C9 Z朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;$ U3 g3 p& {) b5 }- }

6 x/ L" ~4 T4 A7 Q$ j  g- Zpublic class SwarmUtils {
1 f' l$ a9 v2 q0 B4 v& t4 x9 A8 ^/ v  public static Selector getSelector(String name, String method) {; f( e* r  ?& g# B  F2 ^6 ?( e
    Selector sel;: O* X! x1 t5 b+ M
    try {$ t5 a% A/ _8 D! j* B
      sel = new Selector(Class.forName(name), method, false);( j! {4 @/ }$ i3 q+ e+ P3 H" A
    } catch (Exception e) {; j5 Z) }/ A7 v2 Q# t# B
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");+ Y. `* D% z2 Z9 T7 U% z
      System.err.println(name + "." + method + " returns " + e.getMessage());! C' M; p% q& Z1 z# y( h
      System.err.println("The process will be terminated.");
* c; a# K  d& U; N8 R/ Z6 ~+ M      System.exit(1);" m5 @) R9 k% y  U! q
      return null;% `. a+ K  ?$ A  k( ^/ H5 Y/ N
    }
$ z! C0 j9 Z& v2 g7 U    return sel;
/ E& L8 O9 O+ z7 ^" j  }4 H! E' N1 d+ E+ d5 u7 A4 k& N
/ {, A* S! M9 n/ t' [! R
  public static Selector getSelector(Object obj, String method) {# a! M% l3 |8 S1 M* M+ V
    Selector sel;  P7 l" K. b* t( o
    try {
9 V+ n& R( b  }- M, ~# \1 w      sel = new Selector(obj.getClass(), method, false);: h1 j8 D! \* H  h8 O
    } catch (Exception e) {% n' J  s( _9 F- w& E9 S  q
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) }& \" H/ q' d. j; H0 j# |: M# r          + (obj.getClass()).getName() + ".");
+ b. R/ _2 |, f# A      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
  `3 G, v  }- Q$ T- y      System.err.println("The process will be terminated.");9 i9 Y  H. j* ]- W% b8 M
      System.exit(1);9 T+ Z* i9 z2 W
      return null;
. ~: t) t/ |5 g, w) a- M8 C    }
5 N7 Z7 `4 P: g& j* U# A% c% c" q    return sel;' ]5 U, b8 }4 O' y0 k# v
  }4 O' H5 ~  j5 c( U5 ?7 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, 2025-12-15 04:13 , Processed in 0.023653 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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