设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9064|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行* T# L. P$ d5 R! M2 g6 w$ [* p8 S
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行/ d2 w: R8 R8 B( X- F

& V! d9 D1 h& ?" b$ U1 J& Y似乎缺少了一个SwarmUtils的类,不知道怎么回事 ) ~7 _- Z4 v, A
( P' x& x- L8 D% s  g
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;( u# j  B/ a$ n4 w' t
, x" I9 s* }# t  v" K
public class SwarmUtils {
$ q/ c7 h& W+ u4 ]1 d  public static Selector getSelector(String name, String method) {
- z  h1 ~9 B# x8 ~    Selector sel;. A3 X( a& i# z4 V/ v: w
    try {* e1 R+ C) ~0 X
      sel = new Selector(Class.forName(name), method, false);3 a2 c+ d% u4 t1 C
    } catch (Exception e) {" K# J- T6 }" u  c) h
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! @5 E+ I2 z3 u4 O" f8 s* M* x5 w      System.err.println(name + "." + method + " returns " + e.getMessage());
8 k; h/ i8 A! \+ i3 I5 s      System.err.println("The process will be terminated.");
! k. ~% i" E3 I  e4 E' y      System.exit(1);
- s/ r. Z* T4 f5 d3 ?! y' H# K      return null;
6 K- h  u2 z+ R! {    }
- h; q# V; c$ g, A0 c5 x    return sel;
7 F9 p  N/ y' z/ i% N' I! `) N  }
+ B3 A4 {# e. _' u9 D+ T. x3 F( S
; d- m$ [' @5 ?2 q  public static Selector getSelector(Object obj, String method) {# w6 z- x5 ~% D% e# T" b. ^
    Selector sel;
! Y! i5 u+ }8 S+ }% y    try {6 V: x& v$ d/ j
      sel = new Selector(obj.getClass(), method, false);
. [2 ]+ d( N/ B    } catch (Exception e) {0 k$ f* J8 \7 [2 T0 I' f9 x
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "# M. N7 z0 ~3 n* G2 w5 s! [( L
          + (obj.getClass()).getName() + ".");
& _4 R# e8 R5 T      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
0 U8 p; O: `6 `6 ?1 I) X% t      System.err.println("The process will be terminated.");$ r' h* P4 R5 K+ u
      System.exit(1);* p) l' g' N3 w5 ]
      return null;
: E% z2 @& Q  s; m* k0 I    }
$ d) e& m  l3 ]9 R* d: f1 d    return sel;4 B" e/ V/ M' [2 h# `, j
  }5 H  |- `4 a3 Q, S6 r% Z
}

评分

参与人数 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-3-9 23:00 , Processed in 0.018094 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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