设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9938|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
5 B% ?8 v' X% R3 V2 {sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
, C/ R3 q- I: B
1 g+ w7 W' u0 t0 L7 l% `" W2 F似乎缺少了一个SwarmUtils的类,不知道怎么回事 # `/ L: `, _8 F5 h5 L

# S- s, E; q: ]- g/ C朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;$ K" h' M. b+ _$ W) w; J

/ f" F6 r% T! g& b# q% H: ypublic class SwarmUtils {) W1 V' a: g: d: I- {
  public static Selector getSelector(String name, String method) {9 _% o9 r5 }5 f, J
    Selector sel;
4 t; }, y2 T2 [' o) ]5 W    try {+ M; ]' e; D$ A
      sel = new Selector(Class.forName(name), method, false);
- P# b5 G9 C! I% m+ @  j: h    } catch (Exception e) {
" y8 m$ q% m7 H( a( H, U      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) D: ~; ]5 k& [% t" z1 i: \! s      System.err.println(name + "." + method + " returns " + e.getMessage());
0 n9 Z. h) x5 \* V      System.err.println("The process will be terminated.");
- s! ]; `  q7 O) j! o      System.exit(1);
9 }$ o& O4 ~" z9 L. W2 g% e- d      return null;
/ F+ c% p# h% d! y- b    }# C" j) d+ l' E5 D
    return sel;% v1 e6 z4 i  g1 c+ G
  }. l% J  X3 X2 ]/ }
* Q6 O( s* Z  s
  public static Selector getSelector(Object obj, String method) {. N' H& B% c: j# Y, {, ^4 H" T
    Selector sel;8 @* a  A3 \  C0 z; H
    try {
( O2 l4 S7 R# I  D" d      sel = new Selector(obj.getClass(), method, false);
7 ~- G' n3 U, {6 l. n: T    } catch (Exception e) {
+ U* j5 K0 ~: Q2 m2 J& p3 f3 y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' \. p2 Q8 k3 V' g7 X3 P          + (obj.getClass()).getName() + ".");2 [1 G# t* r4 U1 L
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 r; Y3 l. C3 u7 j" [      System.err.println("The process will be terminated.");  e# f! a) r  e1 R% v
      System.exit(1);
  @% V" L+ q# ~+ R- P4 j8 q      return null;% v5 S) V5 D2 `9 w- q# w* Z
    }
  k% N, I9 Z) m( x: {% ~    return sel;8 I; K. y" c0 b# X" {
  }) A( n. D3 _( X0 K. H- 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-6-28 22:21 , Processed in 0.015833 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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