设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8745|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行2 y( {, s4 W3 n% Y& i' ?1 H( f- ~5 X
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行& n& d5 r/ \  T
/ d7 w" v1 K" W) t! m1 V2 f
似乎缺少了一个SwarmUtils的类,不知道怎么回事
4 s3 J* Q% d" e' V: f( T& T: l% t1 r7 }% x% t3 |4 E) |0 G: K/ ]* r& O
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;$ r, O( f/ g& [5 d
, V. m4 y$ W! P0 L# N
public class SwarmUtils {
% R' l) g6 }- z  public static Selector getSelector(String name, String method) {
- f0 G* O" p, Q: P- V1 H    Selector sel;
" Q2 _: G7 [5 u1 B& y! s2 w    try {7 }; C1 o8 [+ I4 L" Y
      sel = new Selector(Class.forName(name), method, false);! A% E$ Z5 Q# \- t, p- l$ q% V0 d
    } catch (Exception e) {9 ]8 t. i5 W/ S0 `/ x
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");# s5 a1 D1 V! Q% }5 U- A* k1 b( S8 H
      System.err.println(name + "." + method + " returns " + e.getMessage());
) Z7 T& S; o4 W      System.err.println("The process will be terminated.");
4 k- m* N/ I* D- y. o6 ?1 j      System.exit(1);+ R: g: [: _. E- }
      return null;" A6 n% W- T. H
    }
- s$ N: G, o6 f0 E0 E- c    return sel;% J+ L4 \' a( N+ W
  }2 k+ u/ h% e( ^4 N$ k

" x+ `1 K' ~) E& c. h* z4 s  public static Selector getSelector(Object obj, String method) {
- }+ m9 x, [: y& p/ r; |    Selector sel;7 j! N. N8 H7 s; J, V
    try {
/ m+ U+ Y' B  v  V      sel = new Selector(obj.getClass(), method, false);
2 r8 T1 Y. b+ W7 B6 f    } catch (Exception e) {( u9 p+ l3 @. e: M1 k
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ") k/ c% y- x3 @8 ~* _: X
          + (obj.getClass()).getName() + ".");& S6 Y8 q; S" {5 E! C1 H
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());6 O$ |* t* r: I2 E  Z3 d) n5 u
      System.err.println("The process will be terminated.");, B. d1 d& G% e6 i; l* I. _+ s
      System.exit(1);
" D" i5 p3 z) I  S" ]: {/ o      return null;( Y- |6 ]4 H* v/ k" F8 d
    }
; x6 D# p9 m0 p    return sel;
7 W) H1 S: O1 Q0 _/ G  }
7 s: @/ }" R1 v4 A! T- b+ V0 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-1-21 19:00 , Processed in 0.019862 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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