设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9805|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行8 b* I4 |6 n% v8 Z8 a- K! L. L
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
( C  i$ t* t$ Z0 v3 _3 j4 y) F' u# `- ]" I* v
似乎缺少了一个SwarmUtils的类,不知道怎么回事
' Z3 ]0 k5 ]2 V' H$ q/ c: l- M# O8 Y  ~4 o1 t% |
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;  v4 D7 C, k' I! H
: E. e8 G+ B. e/ v+ n9 D
public class SwarmUtils {
8 ?0 h1 H" `/ O) W- o  public static Selector getSelector(String name, String method) {3 z9 D% `- F$ y6 ~) g! f5 ~2 ^7 ]- Z3 C
    Selector sel;
. a7 }" `5 f! ^1 A% @  P    try {
+ a5 [! A; p: X      sel = new Selector(Class.forName(name), method, false);; [# j# O, I8 q: h& v. X! U
    } catch (Exception e) {: l) w8 a7 l* w7 ]
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* H0 Z: Z" U3 T% r" m$ L$ }      System.err.println(name + "." + method + " returns " + e.getMessage());) w3 `# }' U+ |* k
      System.err.println("The process will be terminated.");9 g2 r: a5 q. t
      System.exit(1);
3 V& i& i7 f0 F! [) _) I! @      return null;
3 X' l& f# N" I# y/ u    }
2 Y' Q5 Z% c; A9 ~( k6 J8 r3 T# F    return sel;
0 I' i- P$ j" |0 @8 i; A6 }  }
, h( Y9 a4 W7 j* Q' V7 B! X2 s
9 S6 z# ?. ?" U( W& \6 [1 o4 K  public static Selector getSelector(Object obj, String method) {  I' v! C% o+ ^7 }- s9 F  J
    Selector sel;, F$ C9 a' R* D8 _$ [  E
    try {
- |2 ^& w8 C0 Z+ d) l2 j, D      sel = new Selector(obj.getClass(), method, false);: z8 \5 I; T6 w+ `8 b6 o  d9 d- ?
    } catch (Exception e) {. g; E5 _$ X& X1 \: D
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "( g7 i9 A7 ~1 \
          + (obj.getClass()).getName() + ".");
9 |) A  b5 [' z$ S- r0 `# {      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
! T. Z' L0 P$ Q( K( U4 g( f1 |      System.err.println("The process will be terminated.");
5 p5 _: v) e  o  B1 _      System.exit(1);
2 Y) t7 o8 ]; A# M& k      return null;0 ^1 ^2 J5 ~1 z9 R
    }
8 \- e7 Z0 h8 h5 Q6 a! U    return sel;
8 i- ?0 X: E/ M2 u4 e  }% p4 E3 {# N' z: Z' v( h" e
}

评分

参与人数 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-9 06:35 , Processed in 0.017055 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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