设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8952|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行* r0 _) a  |2 E+ E5 N8 d
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
: _( N; f: y  i& E& [' x% A3 x! I- [! O6 V; k
似乎缺少了一个SwarmUtils的类,不知道怎么回事
9 \6 G8 {& [) B9 U% G3 _$ k
1 J" _) z! p0 j, c- k9 g+ P! D6 U朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;4 d) K6 m0 G0 M

4 O% u  F/ j) v! C8 E( S/ ~! epublic class SwarmUtils {
' H  G. [4 c$ t- q0 f2 b) c& a  public static Selector getSelector(String name, String method) {5 l7 m- [3 j+ J. N0 `1 c# e) m  ?
    Selector sel;
" w, O- o4 s4 z+ X- L    try {. `1 C' K* Y# g
      sel = new Selector(Class.forName(name), method, false);) B8 @" h( N: d* A% O+ u
    } catch (Exception e) {
* W7 c: i0 ?0 A      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
1 M2 X+ F  {* S! r2 g4 I      System.err.println(name + "." + method + " returns " + e.getMessage());
* r* S, T4 o0 O* s8 J3 L4 Z      System.err.println("The process will be terminated.");
6 K5 [7 ]6 v5 @: c      System.exit(1);
* w* C' L& m) L% {9 X      return null;" B) {+ z- [7 o
    }
  \  T4 W% Z. ~9 f; ?6 G5 M0 i& a    return sel;# l' b! o1 J2 K7 a7 p& X6 T
  }6 Y1 }0 k0 d. X. z. f0 [

1 ~3 l4 x) D4 M  public static Selector getSelector(Object obj, String method) {0 q: ^' E8 ^1 \
    Selector sel;
# m( X' }1 \9 Y9 |  }    try {
7 R* m' w* x1 j# T6 M& ?1 K0 J      sel = new Selector(obj.getClass(), method, false);
6 T8 u6 W  m5 Y% s$ `, s. I    } catch (Exception e) {
$ u$ e* \, b2 r7 o6 n6 R( o      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ K: @- Y8 x5 U( L* {! `# X( _
          + (obj.getClass()).getName() + ".");
8 V2 z2 P+ \- V9 d  Q      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 D8 J, J% X/ E2 y) U      System.err.println("The process will be terminated.");! s6 o- V. r# f6 J& {& y
      System.exit(1);$ u& N/ F0 @4 l: C
      return null;4 a8 `% i7 J6 M( _" d1 |
    }
8 x0 Q6 h5 }% b, e1 f    return sel;
& n8 h8 H. H" v4 a: e8 e6 E  }
& B1 l- N% L1 S+ _" t8 n! m. G}

评分

参与人数 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-16 13:41 , Processed in 0.018956 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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