设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9671|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行& r$ E/ N6 p3 I0 @& u
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行- l7 V7 ?$ p6 Q) A, t* S6 t, d

# m. \- R7 o* _+ E! _& y* Q5 [似乎缺少了一个SwarmUtils的类,不知道怎么回事
0 G& J" D9 K3 {: O( V# _' O, P6 H/ Y, E3 g/ p( I
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
5 w0 M4 z: R( ?
; ^) e5 b' ~9 l9 o, Ypublic class SwarmUtils {
8 c8 X* X3 ^6 z7 ~  public static Selector getSelector(String name, String method) {
2 k" l7 N) B, F" U0 J2 [  _    Selector sel;% O  M$ v" r5 P. D7 L3 G* ]
    try {6 E  N2 a9 o9 s
      sel = new Selector(Class.forName(name), method, false);
% N  v4 n6 w4 v2 Y0 p3 w3 A! }    } catch (Exception e) {0 M" u9 Z  g- r4 Q2 M
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
  l9 T3 l6 {$ C( t0 w      System.err.println(name + "." + method + " returns " + e.getMessage());4 W  J+ X8 N" y/ v) _: G
      System.err.println("The process will be terminated.");
- i& M8 ~0 ~" I- Z/ U      System.exit(1);
- w3 V# e7 w+ u      return null;
& S1 N# p, {& }) X! G. f    }2 u8 ?! i% {& s! r. f: q( \
    return sel;
% G8 w4 c) W1 \. f9 P  }
  m& `1 E! m7 r' G; x( v* ^
0 D2 }$ k& g4 H  public static Selector getSelector(Object obj, String method) {: q7 ]" k, c0 h! D* [0 ^
    Selector sel;
8 `. _' ^" Z0 {    try {8 p1 K$ q" w- x) Y
      sel = new Selector(obj.getClass(), method, false);' N" h  q, I; L9 V
    } catch (Exception e) {
- P- Y7 @( B# y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ". {: l2 o! n- S: o. ?' g; W
          + (obj.getClass()).getName() + ".");  u" J9 [) m2 F$ ~: I
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* x1 I$ l# e1 J  h$ X( L
      System.err.println("The process will be terminated.");
0 V, g! N3 l6 A$ s6 m      System.exit(1);  x+ o. D$ u' s3 j* L  G( A
      return null;. G4 {' J0 j4 |1 Z: L4 k; {& `
    }; w3 F3 a: ~4 ~5 ?
    return sel;$ m$ v% b2 y5 Y) B# A5 i. W
  }  r: f) \8 j2 k. J0 q9 ?% \9 }
}

评分

参与人数 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-5-21 23:39 , Processed in 0.023023 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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