设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10388|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行8 E$ k2 m' p; l  {
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行/ z. y( ^, X4 ]. D' @
% X+ o5 j' i+ U5 [- ~" X& g
似乎缺少了一个SwarmUtils的类,不知道怎么回事
: H1 B6 F' a3 S1 E& b& ^. \9 d
4 l' j7 A; \& f# C6 g0 ^( }) G朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
* c* d* p6 i, ?
0 i5 p9 B0 E. ]" s3 A+ Npublic class SwarmUtils {7 V  L% R+ F+ S' [
  public static Selector getSelector(String name, String method) {9 f/ [/ O& o8 ~$ Y; `
    Selector sel;9 M/ P2 E" N5 _7 a
    try {
4 z1 c& t1 L  z      sel = new Selector(Class.forName(name), method, false);/ z  e5 |) f7 e1 }
    } catch (Exception e) {9 C( L3 O0 |& x
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: [: b. J9 R0 ?; i9 G      System.err.println(name + "." + method + " returns " + e.getMessage());" c3 g4 y) q2 ]
      System.err.println("The process will be terminated.");5 r- p3 D# i$ H; ?) g+ ~
      System.exit(1);
5 y" q2 `$ h7 Q4 x" R0 A7 ~/ J      return null;
6 L- t% ~1 C- x0 k/ C1 q    }  Z6 Q) m- X4 L, ^( d) A
    return sel;
0 I, G% E% V& _/ U- n  }
5 `3 w$ S$ R9 B) P$ u$ a) i0 J9 |* A1 {  N. h3 r; ^/ }2 f8 e
  public static Selector getSelector(Object obj, String method) {
$ L0 o6 u/ v, Q9 i# U( W7 |7 G) M    Selector sel;
' G' B% Q: C% j; C    try {9 c  B# m0 V+ H0 J2 K8 r: Z
      sel = new Selector(obj.getClass(), method, false);
. M: w1 J$ X; v% C, I. Z: Y    } catch (Exception e) {% s$ I  B3 A& l$ [) g3 x0 W
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& ~6 i( l0 u/ h( H  C6 B/ A; W
          + (obj.getClass()).getName() + ".");
* Q$ ?; X; F6 `* t3 c) v' @      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- e) h2 ~: d3 M$ _# y# [      System.err.println("The process will be terminated.");9 f. L9 _( z/ c- W
      System.exit(1);9 G9 p; Q8 H/ g. I7 N! r! O8 D
      return null;
% O) ?5 Q$ l, z8 V2 c  V    }
: j- |' r" M: H! M7 B    return sel;
, r# ?6 M+ q5 y  }, K2 x; F5 I# V* _7 [
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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