设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10698|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
* a4 L! I- j; ~2 E6 t9 `sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
- D, f; |: z8 g1 Q" b0 X7 m" h) z) v2 I& H2 P( u
似乎缺少了一个SwarmUtils的类,不知道怎么回事
0 g) ]# `% k, A  w2 p7 g2 x  b& W. g7 e( Q6 h' H
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
$ L' D! C, O* F8 o8 g$ _
9 S1 V) Q7 Q* b- mpublic class SwarmUtils {
' K& S$ v4 Q' f3 a6 R$ L  public static Selector getSelector(String name, String method) {
9 X8 e6 X: M# k9 m4 I/ P4 w& i& N; k    Selector sel;
: P$ l& ^( O+ ^; ]    try {
" ]2 F/ d% Q8 @      sel = new Selector(Class.forName(name), method, false);
5 z) k' z1 d/ a2 O; ?    } catch (Exception e) {
) t& k$ f+ Y' ]- w8 v: y. |. z6 U      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
1 e' m" k% ^" @6 R: a      System.err.println(name + "." + method + " returns " + e.getMessage());8 y2 \% {  B6 }' j) {) B
      System.err.println("The process will be terminated.");, V9 _' c% d  }7 k/ j# c3 _7 R3 K% i: s
      System.exit(1);
% S- t3 R; W8 d) F9 _' K: P) ~      return null;) }+ l8 C! o# a7 L) H6 |' |7 T+ h/ R
    }- {% U& y1 m- D
    return sel;- M( B0 @8 G  T% I" S  v0 t1 Z1 S
  }
1 _; d3 S. I( q" `! @6 e6 p- ]- c2 d& ?$ y$ c, B% r
  public static Selector getSelector(Object obj, String method) {, o7 b( F$ }8 N* q( r
    Selector sel;
# O% z1 k+ _/ O1 Y# |    try {
  E! t! U0 V/ h      sel = new Selector(obj.getClass(), method, false);8 \, E4 n7 C* O- r  z
    } catch (Exception e) {# u# b1 k/ U3 A; C! q
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) N, @9 `1 y& |/ G( u& v- o8 b          + (obj.getClass()).getName() + ".");
& N4 m5 v" Z0 L4 B  U* l0 y      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());2 l6 E5 C0 t4 {( u/ |4 H1 G* l
      System.err.println("The process will be terminated.");
9 }* {& y  ?( y. `3 X# k! X1 {& k      System.exit(1);6 ^" E2 R5 W' a  {) O4 {! g0 M
      return null;; V7 ^' w7 C; Z4 g( f9 E
    }
: y6 g, l& @" b& M1 ?    return sel;' X3 J& w  K5 z5 R8 q# m" z: _
  }
& R1 F" W* y/ H/ m+ U. j! e, [1 ^}

评分

参与人数 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-9-19 09:23 , Processed in 0.017578 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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