设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9018|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行5 p2 K# ?" V4 ~; M, n
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行8 x% x- o# I/ u. g7 f" G( Q

. [- C% l3 {6 i3 q1 d似乎缺少了一个SwarmUtils的类,不知道怎么回事
6 |& t( E+ V9 [1 x
; V2 ~) `# Z2 t朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
4 A( ]3 ^1 R. N1 ]; G; u& ~$ {0 ]3 r; ?% C' {. q% i% s7 B
public class SwarmUtils {2 Q: T; X; c9 d% x. j
  public static Selector getSelector(String name, String method) {/ G6 i( E+ {3 a  T, A/ o
    Selector sel;
% K4 r$ O" v  U    try {) B6 ]3 d" Y% v" D. O& G
      sel = new Selector(Class.forName(name), method, false);
2 h* g; M& b! G& s    } catch (Exception e) {
2 z6 S4 H# D" ^' U$ [      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 C5 e, [# Q" @: Q! l! N
      System.err.println(name + "." + method + " returns " + e.getMessage());( s- n) j$ ~- c/ ?3 n# v- f' W
      System.err.println("The process will be terminated.");
+ p: Z, E& e! c! N      System.exit(1);
! ~2 g0 o6 G. W2 u  W, {$ w' }( {      return null;/ z! m6 S0 d, @8 R  E- p1 J# t
    }0 x5 Y4 z' F! w! f5 n8 v9 I, F
    return sel;
2 X0 ?. `9 B+ I1 P) B: y* C  }7 w- _, ?2 V6 \

( X  F  ]2 X1 ~+ y% y4 L4 |- s: n  public static Selector getSelector(Object obj, String method) {
; A( O8 F! G0 z' k    Selector sel;* b8 l0 N! ?! i3 s6 H0 Y% z
    try {$ J5 g8 B0 u) I/ e
      sel = new Selector(obj.getClass(), method, false);: v2 u, v* J' I/ v4 R
    } catch (Exception e) {
. b' \& P- \% k      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
+ ]0 I% a: I/ e# R          + (obj.getClass()).getName() + ".");7 q& ~: F- k( H# j
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());# X+ S4 [0 g2 ]9 w
      System.err.println("The process will be terminated.");
) Z; v  d  ]  l+ B% T      System.exit(1);( u# O, Y; @0 E8 M0 i3 \
      return null;+ j8 ^' h0 j! ?- q- `
    }: |6 p8 S# u# W2 t7 u; }6 G* T/ d
    return sel;
& b! Z2 @, K( x  }+ H3 M; p5 H6 V: x; d3 A
}

评分

参与人数 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-28 08:30 , Processed in 0.017041 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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