设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9388|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
; {! @8 ~3 C1 K7 _2 Ssel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
* c* r5 s$ l, ]8 h  Z, b  K) D! J: G) g( X) e; a; b2 V0 M
似乎缺少了一个SwarmUtils的类,不知道怎么回事
1 z, G# w( ?3 u. @: a, ^' E! L
0 N0 u. f1 N% R( ^4 {. I朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
: O: [! ?5 Q+ p: C) e2 C5 Z
" L7 ?$ L, w- u, _# G. bpublic class SwarmUtils {
3 F/ {/ {7 M- B* \( p# P% M  public static Selector getSelector(String name, String method) {
& t# A4 T" v% V" |* x6 }    Selector sel;
/ o' `7 d( P! v' S" E) M    try {; L; o- ^3 l8 v, ~7 g/ x% P/ V
      sel = new Selector(Class.forName(name), method, false);# _, T% ^; ]* {% V
    } catch (Exception e) {
/ x$ \& j  _5 a+ `1 d3 K4 V      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");+ O& H4 D* N$ N3 c( H2 w2 a
      System.err.println(name + "." + method + " returns " + e.getMessage());
4 J$ V" J3 w0 M- ]# i      System.err.println("The process will be terminated.");  O* j3 C: V5 ~
      System.exit(1);
( X# E" U. I3 X, Z/ X$ e5 x      return null;
; G; q1 Q% d9 m9 a2 M) }    }0 d5 u4 S6 ^5 b+ D$ f% P. W7 g6 _
    return sel;- a  T5 N7 I' P, k4 G
  }& s" F) D( [; {0 {: H

4 u* }" _% k& z9 t% B1 O# I7 e+ P  public static Selector getSelector(Object obj, String method) {3 W2 V7 X/ E$ g9 @% W& S" L% T
    Selector sel;+ W" r( G0 x( N+ h$ P& }
    try {
) m6 P) M# n8 L( d5 u0 D      sel = new Selector(obj.getClass(), method, false);6 H; q& u4 R& Q8 W, s4 S8 _9 S5 y
    } catch (Exception e) {" t, d$ x; k- |4 K7 \8 ^! b0 r
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "- z8 y/ s! U) w
          + (obj.getClass()).getName() + ".");. Q# Z/ M. P; h
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
8 Y! Y% ?0 p) v, V4 q6 I% s      System.err.println("The process will be terminated.");) S4 i) A6 }" l, @
      System.exit(1);
2 k: k  i% R2 E5 n' G+ X( }) o      return null;
4 P& e+ a5 r; A5 v4 R% z    }7 n. \# [4 S' r/ \3 P
    return sel;
* J7 x: i+ E4 C! l0 p1 q1 N8 y0 X  }
- t+ T- I8 J: W) k7 c1 Y. N6 v}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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