设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10522|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行, F9 B- h- ], H5 |& K
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
- I$ h# G9 L; E, x, a7 _
) O4 u" b! \0 u似乎缺少了一个SwarmUtils的类,不知道怎么回事
9 y3 e( M* O7 ?: {- w# o" A- [$ s( v3 P
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
3 i% F% H/ ^. f! ?' u! b
" u& Z( A& @) p. Gpublic class SwarmUtils {1 A4 m5 h& q6 Z1 t$ F( ?% ~4 p& A
  public static Selector getSelector(String name, String method) {
/ e- }5 R. {& E7 o% c# F    Selector sel;
5 w5 \+ {5 J/ Y! X& t    try {% N* j" C/ @3 p0 x3 D1 \7 P
      sel = new Selector(Class.forName(name), method, false);" a0 `% w+ G. ?) [0 p% F
    } catch (Exception e) {
& \. g" ~% d, w, j% ^4 B0 W      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");8 D* |2 C" f. X/ T
      System.err.println(name + "." + method + " returns " + e.getMessage());) X' i  L2 q& Z6 V$ F$ F
      System.err.println("The process will be terminated.");, H7 ^3 f0 U7 w( ?! O6 z
      System.exit(1);1 |" Y& p$ K$ ?
      return null;# f5 `, B% j: Q) q/ e8 K
    }
  D1 A+ M, ^# O% T, W    return sel;
2 c, n% r) }" n# z/ L# \3 Y) c* w  }5 y1 ]; H3 `" z# Y- ?
, S! {. e1 c3 U& N, a% c6 g1 x
  public static Selector getSelector(Object obj, String method) {; A4 z/ L0 A6 P* O2 R4 e! ~/ f9 D" T
    Selector sel;1 \1 j# h& i% l+ c' R1 j9 ^
    try {
9 S' {$ j, A- w$ h      sel = new Selector(obj.getClass(), method, false);% R: e9 H7 h% v% O- Y  _
    } catch (Exception e) {
" F3 w0 U( {, F+ I" e      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 _1 i0 G8 [3 Y1 E) R2 d          + (obj.getClass()).getName() + ".");/ P& j3 t8 L+ S3 X, H' m3 d* T+ S5 H
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());; V7 c& b% s( O6 m0 j" T- ~
      System.err.println("The process will be terminated.");
' Z7 l9 I% @# \$ _9 J      System.exit(1);
, K% [# q: y/ ]/ V& [2 s2 @      return null;$ i: O* h" R3 R, t
    }
9 o8 V. R& Q, Y0 s( [" q( D    return sel;; J6 D" d7 A3 I4 H7 B
  }
8 E$ k+ x9 ^& A+ h$ n}

评分

参与人数 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-29 10:24 , Processed in 0.023545 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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