设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8063|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
4 _; j0 g/ t7 D* D0 usel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行1 U" f  Z1 I  C5 M' y, X1 d
3 r0 p+ l  Z" |4 K% R
似乎缺少了一个SwarmUtils的类,不知道怎么回事 - B8 P2 f1 c0 [+ r# f. R! l

* ^, A& u1 y/ J7 s; k朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;1 o. W# u/ p* ~6 V# Y  R

4 p5 d! d3 v% U8 ~" }4 Gpublic class SwarmUtils {
0 c6 _; e; X5 |0 y5 K  public static Selector getSelector(String name, String method) {6 y2 G0 c, e: i) }
    Selector sel;
6 D4 l# {; j  D7 O    try {
1 Q, L2 C. ]  H" W4 _7 x9 R8 a1 r# I      sel = new Selector(Class.forName(name), method, false);) |6 |% |, q4 |: b! |1 f. t5 {' l
    } catch (Exception e) {
7 v* V' j+ K6 ~      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ U: ~* E6 P' J( n6 [7 R      System.err.println(name + "." + method + " returns " + e.getMessage());
& a9 }' P& C& b8 V5 y' n      System.err.println("The process will be terminated.");$ c5 D  _- ]% J4 m& l
      System.exit(1);
; r2 H2 C8 a0 z6 q      return null;
9 _6 p" r/ l/ F: B$ d  {' p    }
1 w* b$ Q  i+ x; ^    return sel;
# ^8 [  \; j  z8 n4 ~1 G% A: j# O5 O  }  T9 K4 w4 h. F1 H2 F6 W; I9 T

( O4 r1 D& ]9 R8 U* N- c  public static Selector getSelector(Object obj, String method) {
% a1 m4 T7 G2 w    Selector sel;
3 W; Q, N1 \2 v    try {
# Y5 M) W1 ^+ _' n/ x- x' c5 _5 P$ q      sel = new Selector(obj.getClass(), method, false);
* l$ t, l* d% l1 y    } catch (Exception e) {& d! `5 a/ k" x9 K: ]+ r4 C
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 u" }7 s+ b/ t' X5 [4 ~
          + (obj.getClass()).getName() + ".");0 P" u$ Y: |) c& l! Q
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. s9 {, {" h6 d; `9 R) |& O' q5 w
      System.err.println("The process will be terminated.");* k5 S& c  o0 I
      System.exit(1);
  P# u0 y1 ]! Y6 N) {% \: A      return null;
! U. B+ N- X! A& g" p& B( {0 ]    }
: Z' C8 b+ s! k' L# M8 d& Q& _    return sel;$ }" g/ x0 Z& M( Y. r. L
  }
  X, _" }4 e- u6 d" U}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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