设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8991|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行7 L( C! l6 D) J2 I! x
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
! o3 M" [4 Y+ U8 T. ]
/ q2 D3 q6 v9 ~# G. {5 y似乎缺少了一个SwarmUtils的类,不知道怎么回事
2 V) D; L" I' O/ ~& S& }$ ]# y- s8 u6 W0 d7 m. A* {
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
7 J+ b# \. ~, r! D1 j3 k
" r- ^' P: T% r* F5 r  mpublic class SwarmUtils {- F6 A& M9 g, R! ]# X1 U* s
  public static Selector getSelector(String name, String method) {
; X9 I& s& j- J2 D    Selector sel;
: y! K, ?# m2 n& R( N$ z; e    try {+ k; g6 J8 h: [
      sel = new Selector(Class.forName(name), method, false);
2 ^' X4 B7 E( Q6 _) P9 t    } catch (Exception e) {  k! ~7 P! V( @
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");' u" U5 c" l& \- O! Z9 {/ n& B2 J& o. K
      System.err.println(name + "." + method + " returns " + e.getMessage());. s9 B# n0 _+ o4 u1 Y5 x& c( b
      System.err.println("The process will be terminated.");
* S9 X- H4 H* k  x2 N  W) b( p, u      System.exit(1);
  @+ U5 R" }3 ]7 N) Q+ l      return null;( ]3 K5 x# m% f9 m% ^- J4 Z# o
    }
) E) V# ^' h, H* S" H    return sel;
: e; I5 p( A+ M# `: g: i2 z* H  ?; C  }
) b7 O! Z( o* m0 U- r% }
' [: H! Y. C( I8 a7 d7 U  public static Selector getSelector(Object obj, String method) {  R7 U4 _. z0 W0 k, `' r0 }
    Selector sel;1 i0 \% g  W( L
    try {
  Y3 a$ V. x4 R) O      sel = new Selector(obj.getClass(), method, false);. W: P. l/ }* m$ C- b
    } catch (Exception e) {
( L: s( m5 |; t1 t) d9 U5 x/ y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "1 Z/ F, h4 r8 a+ h; ~# F
          + (obj.getClass()).getName() + ".");
, g( L, d' h, x0 |9 ~, r      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
/ d" }1 g- ~: ]4 v5 c      System.err.println("The process will be terminated.");
) N* ?) I) v! r- |      System.exit(1);
1 D$ R1 [, P0 f) N( s- O/ ~! k      return null;
0 ^0 o# L: k) P& m. H3 O    }
3 f2 P9 |2 X* e( y% z    return sel;( T  N5 G+ G! ]; b
  }; f+ M) v2 k; h5 y* h
}

评分

参与人数 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-22 16:45 , Processed in 0.018736 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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