设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10001|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行0 X' F9 l( O, J5 b7 Y/ ~$ t, j: [
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
( J5 ~  z( f+ O  k+ l( x2 a
# ]; h) O1 o( w. Z似乎缺少了一个SwarmUtils的类,不知道怎么回事
1 E8 ]( \" }5 R; f) u, s" P  E5 n' `; B
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;; }% Y' D# J9 Q: a- Y9 U
: J# e; \" n' H( i' {1 {
public class SwarmUtils {
' B1 P* F. y+ Y7 \  public static Selector getSelector(String name, String method) {
4 B, A9 G: f4 _: U, x    Selector sel;
: m9 t5 B$ a0 [  H  {, q/ `    try {" ?, C( b! ?5 ~* z* w2 Q" T
      sel = new Selector(Class.forName(name), method, false);" m  ?" X# q/ ^- h9 M  Z  O
    } catch (Exception e) {
. w8 u0 M5 O: f) r, p      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 I' `/ b; n" Y6 _. b& Y
      System.err.println(name + "." + method + " returns " + e.getMessage());
# V0 m9 S: P6 J5 o4 `; c      System.err.println("The process will be terminated.");' S! m6 r( \5 ^% y8 L- U
      System.exit(1);
: I# Q4 w- }6 Q8 [+ Z7 t: ]. ]      return null;) J$ p2 W0 i6 f' _( N/ k
    }
1 ?, Y& {7 v/ H4 _7 A    return sel;
  Z& M1 T, d# ~. a  }6 l, E: l- a% D& C" c5 J, ~
, Y" ?- e: L' w. C, z8 ~
  public static Selector getSelector(Object obj, String method) {: I( C- r7 {  r, A) n- |- P
    Selector sel;! J8 k( H% G  A: ?% F
    try {
, N/ ~' W! v$ Y" F; g# P9 W& s) w% u      sel = new Selector(obj.getClass(), method, false);
8 M9 F2 Z& {+ W) b8 f$ z! G* L& u! Q    } catch (Exception e) {8 f# u) t3 m, j. B' ?% u
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
1 H# D& G: Y# N* l, {) n3 c1 |          + (obj.getClass()).getName() + ".");
- H8 i3 w3 _1 Z: N' k; F& W7 t      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- T3 t. v4 I" ^+ D/ T      System.err.println("The process will be terminated.");" Z: A% t: \: ?& X% I
      System.exit(1);9 r4 S0 z7 t) t" H, Y
      return null;  h+ O& ?/ F% t
    }
4 E6 V3 ]! J" t; z# }    return sel;' i% H8 p* T, x5 M4 A4 B
  }
& P7 }* n+ t! d6 A+ m' {}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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