设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9704|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
4 R! V0 ?/ k3 o/ Osel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行4 P& q. C8 m9 ^% s. z6 `9 a
5 G% w" f$ T+ l2 K6 R; |
似乎缺少了一个SwarmUtils的类,不知道怎么回事 " a& o5 Q# H  f1 N/ v! u* x
) k# C1 z4 S' A+ A# S) |+ r2 u
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
: j% _0 U4 X/ N, z
  W1 v& j1 ~- P) i' Gpublic class SwarmUtils {/ R7 b, ^' d: \2 q. B0 f
  public static Selector getSelector(String name, String method) {
2 V+ D1 ?  D3 s0 X    Selector sel;2 |& J3 m. H6 C7 W+ B/ N( f: N
    try {6 y, h9 I; c4 k! @9 _
      sel = new Selector(Class.forName(name), method, false);  N' ~$ c! q* N
    } catch (Exception e) {
* D( R* E+ k& t! e! P6 K( Y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* X+ g1 }+ R3 j; P. K$ q- g( L: N# r4 }
      System.err.println(name + "." + method + " returns " + e.getMessage());
; V6 x  z3 _3 P9 t2 o; a8 @5 f6 q      System.err.println("The process will be terminated.");
" S+ [4 c+ N5 m, X* K      System.exit(1);2 ^8 p8 p1 V& |9 d
      return null;- C# F; g' B/ D$ X
    }
. }- S: ~; ?1 m! F% h    return sel;
8 z: j; N; @, D$ [- ?) i8 ^  }; N# e8 ?& h+ V8 f( H" Q1 u+ S
" X$ e/ Y- H% M* ~
  public static Selector getSelector(Object obj, String method) {
& N! R3 v- ?/ X7 _    Selector sel;8 k# {1 Q# v2 a  x% u" Z& i/ T
    try {
9 y8 R: w. l' H+ `9 ~      sel = new Selector(obj.getClass(), method, false);, B/ Z& p. s+ g* L  q& k2 H
    } catch (Exception e) {
; J* Y1 M( H! _" X3 [8 U      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: W1 {8 D* H" }+ @2 f          + (obj.getClass()).getName() + ".");
) y8 [9 ?& X4 K' ~3 K; L      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 n! ~1 ]5 S9 Q  k6 F( J      System.err.println("The process will be terminated.");
) z* p; ^" ~% |0 W3 l" n& p      System.exit(1);3 I1 {; F- V) O8 H# J
      return null;/ `( f0 e# Y! b
    }
, ]1 }) E8 g. f8 ]    return sel;; W9 d# M  ^, y
  }
/ I6 d1 ^$ j* L* S+ z0 |/ 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, 2026-5-27 21:25 , Processed in 0.017163 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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