设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8989|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行/ f$ ?& Z) n! }# \$ X# H
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
' u$ k4 N5 K3 Z+ [# H2 z
5 x( ~6 }+ Z, m/ m似乎缺少了一个SwarmUtils的类,不知道怎么回事 ( V- Q2 }. F/ ]) d* m" k2 l3 W- W9 W

* ]2 d7 {0 ~8 C- p1 R$ w  O朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;# m7 ^& ?7 N" D0 P) C& r% |% I) J/ n

7 K: Y! B* K7 L9 E  J; upublic class SwarmUtils {0 x( d% t2 h% }/ {* e
  public static Selector getSelector(String name, String method) {6 T- R2 l& b! }1 }
    Selector sel;
: ?' H! y5 J; X9 `4 O! Y, |  E    try {; T' e$ b8 @! [, G& R8 W  m  _# z
      sel = new Selector(Class.forName(name), method, false);
7 ~5 r5 N5 a2 X  Q# d    } catch (Exception e) {
* E2 @& u& m& W3 a$ M& h/ j      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
+ s. Z2 e6 u. D* e      System.err.println(name + "." + method + " returns " + e.getMessage());+ R' @" P3 [, t- S& k! w
      System.err.println("The process will be terminated.");
; j2 Y5 D/ Q. P# u; u8 D      System.exit(1);2 V0 U. t$ |% U, [+ W( u  Z& \* a
      return null;
" V$ ]0 t/ J: n7 @0 B    }
. `- a" U# |( P) o4 K, [: H    return sel;
; _; q5 g& p. f- p2 m  }$ [  k! t* _- L; d
4 m3 y8 a/ e* W/ X/ y+ w& V6 P6 O
  public static Selector getSelector(Object obj, String method) {* p& E7 c/ U+ c4 h& n) F
    Selector sel;5 w" J( r" E  N" Y3 a
    try {
6 C  [6 q1 z/ x5 t  ]' r; }& ^      sel = new Selector(obj.getClass(), method, false);5 f! S7 [8 }2 m
    } catch (Exception e) {, L( G# T. F! N" b& i0 p
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
; M, O* G- Y" Q6 @          + (obj.getClass()).getName() + ".");
) J3 q4 ~+ x& w! g( _) H" z      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());# X* [' X9 P- }6 }$ H5 W
      System.err.println("The process will be terminated.");
# C  S* c6 g# Z      System.exit(1);) Q  j  q) k4 n& W
      return null;2 P) J" k% |6 u$ {: w4 t
    }# z# F  K7 D( ?) m) y+ F
    return sel;4 |3 S9 G$ j' A# ]( W
  }# q! n" f$ c, S/ O
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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