设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6717|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行! ]& I4 ~+ y6 ^6 x  x$ q
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行1 T+ A& O- q/ E+ y) ~+ i

7 n9 k" r" E, p似乎缺少了一个SwarmUtils的类,不知道怎么回事
+ R" A; z* d. `, w( R. z
1 T. {! y" q7 T% T5 U朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;3 u9 q7 t  {* Y* i' ]

1 w7 l7 N) z* Cpublic class SwarmUtils {
) Y5 r& {, ^$ F  S* l8 S/ O/ w! W  public static Selector getSelector(String name, String method) {8 K) L, K2 F/ O" ?8 T2 C2 v0 C0 H
    Selector sel;' N$ M; [* H* O: d) ^
    try {' Q& Q; _! u$ p! s6 h
      sel = new Selector(Class.forName(name), method, false);
% w, F2 ?5 x7 o. a+ g    } catch (Exception e) {
) ?9 E9 u  O' n6 D6 C. U      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. |& O( ^; l; N0 _      System.err.println(name + "." + method + " returns " + e.getMessage());
6 ]6 A6 j. }+ t% a4 k  e# V2 Y      System.err.println("The process will be terminated.");$ _8 x% W1 M( ~! \8 [0 H; M/ v
      System.exit(1);  i+ ?* @. a1 Y; r8 N7 g8 }
      return null;( c, c: E/ Z/ a4 B1 c9 }& F3 O
    }8 o& s  B. P# f; L" x
    return sel;0 e6 P/ `) i, C) E. r+ {; S
  }' n* w% K  x- \- m( W4 x* I; M
7 ?0 _  h, t7 F$ R* @4 N% ~+ z
  public static Selector getSelector(Object obj, String method) {' d/ X' [% ?, v9 x2 h4 y* m% h
    Selector sel;1 M, x7 L# N! W& S7 I
    try {, V# g2 T3 z& [+ F3 z% \9 N
      sel = new Selector(obj.getClass(), method, false);! o3 [9 x, a! y6 A( M! R
    } catch (Exception e) {9 X  H( ^, U- x% |6 g$ e* g, M
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "7 L" G7 r2 Z0 Y8 q6 a) E6 d  \
          + (obj.getClass()).getName() + ".");$ w* `; F2 }3 F. R0 X1 I9 x8 q
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
0 y2 L: W4 }6 ~0 y. d3 v      System.err.println("The process will be terminated.");
7 C6 _/ Z5 T6 a& Q      System.exit(1);
3 p& i7 o7 _3 G' ]' n9 F3 }* \# H      return null;
! w" n: v7 U+ L7 S) @    }
6 J4 z' u1 J+ v    return sel;- A9 ]3 O" L/ P$ i2 a9 r
  }6 S  s  d2 {/ G7 L
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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