设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7526|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行$ ^- y: P8 i3 ^" ~/ k9 X, Y" U; l
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行4 M1 v. f  S- }

# _5 H* x0 z2 _# x8 I, s) B似乎缺少了一个SwarmUtils的类,不知道怎么回事 $ E+ }- E  K& d2 o; Q0 k0 U/ G

  \) z# V% j, \2 v8 N. ~0 Z. ^朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;, i2 i5 p8 |. j5 b0 O1 ^5 l

( q5 O  z# D; x! v' S, {public class SwarmUtils {, K0 D$ i- h& e( W8 [
  public static Selector getSelector(String name, String method) {/ ?* U1 P* j  b
    Selector sel;
  V: t+ ?' R8 _! h5 R$ ^3 I% P    try {
: j5 n* s& \! q. a  f3 c, u0 a      sel = new Selector(Class.forName(name), method, false);
' g* D2 d8 _0 J    } catch (Exception e) {
3 S" A/ c) }9 z: `# r      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 J% Q/ _2 L. c9 T3 J1 W
      System.err.println(name + "." + method + " returns " + e.getMessage());
6 s7 A& e- @5 k. T9 Q4 t; `      System.err.println("The process will be terminated.");
9 I; x$ L/ d0 _' L: k" ~9 E7 D( I      System.exit(1);
$ O- @% D6 p0 v5 b2 y& i7 D      return null;* k8 u9 t) y7 i) [! s8 b0 |
    }, {, W8 k$ h) s; j- n& n  I# D
    return sel;
+ g5 L! Y6 ~9 J/ }0 u4 r  }' Q  F7 \/ h6 B) L9 C$ W( q! k

# L" O. j$ @/ R' @9 i- c  public static Selector getSelector(Object obj, String method) {
5 f& {4 Z7 S3 C; T! M. ^    Selector sel;9 b. |( V( Y/ t% t7 c4 d' V
    try {- o5 h3 v4 c9 a& Z2 Z% d
      sel = new Selector(obj.getClass(), method, false);' G8 L/ P" \  I5 p% A+ o) [, f
    } catch (Exception e) {5 u  y) Q7 l( a
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 ?- A6 s4 z$ S9 _          + (obj.getClass()).getName() + ".");% m0 ?% i, u+ [! r6 v1 L
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
* f) ^0 n- r$ ?; r+ }- X      System.err.println("The process will be terminated.");" S4 z6 i; g- u) R1 H, a2 _( T
      System.exit(1);
4 p1 Q3 a, s2 p7 l4 [5 F      return null;
9 O2 Q* S) u; R7 x# s: D5 P# `    }& |; m: t% l& k- [" g% k
    return sel;
- @' }' m* y0 B' m2 f6 Z) i: y  }3 X( c$ Q* d$ Z# }
}

评分

参与人数 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, 2025-6-19 08:48 , Processed in 0.019218 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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