设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9641|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行9 {' P, ~3 G2 b3 ^3 a
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行0 }7 a- R" c' H0 i& B4 x
# x! k6 I. N; V3 Y/ P
似乎缺少了一个SwarmUtils的类,不知道怎么回事 8 c$ a, i& g! b- M' j
# C- M3 N) P3 w$ [
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;1 t; c7 F7 D2 Y# s9 m

7 V& y9 }, z/ Xpublic class SwarmUtils {7 D8 _/ u4 p" k# U5 ]: \
  public static Selector getSelector(String name, String method) {
3 J- H5 n! f  @    Selector sel;
6 H) M) \0 H2 B, o" c# i) \( t- ]: n7 t    try {
0 v2 s! r" S4 S3 k- i      sel = new Selector(Class.forName(name), method, false);
8 r4 j% t' l* k+ o7 u$ p# x    } catch (Exception e) {
; W" C; R0 X9 Y  V1 K      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
5 v8 I/ o; @# j( y6 g1 W. {4 K, J      System.err.println(name + "." + method + " returns " + e.getMessage());' k% X5 F% N8 K) w* u0 a
      System.err.println("The process will be terminated.");
3 Y/ v/ n8 U+ E- z; _/ z      System.exit(1);4 u4 z3 S* R* K
      return null;
: s. ~- _( E* X( d    }3 K* g4 C1 P8 w; o( @
    return sel;5 P/ p- R: \4 n4 I' f
  }
8 N* R  ^' A5 K2 G* `
) o1 E4 I% [* R5 v% s1 @  public static Selector getSelector(Object obj, String method) {
2 X' d& @$ A! |- H$ K6 M* P! O) ^    Selector sel;
" h) u  _$ Q$ n& L, Y9 A    try {- T; S3 [' y! P' X( e. `- i4 W  O8 A( W
      sel = new Selector(obj.getClass(), method, false);
9 w3 d* a4 ?% t7 Q; H7 E    } catch (Exception e) {& F' x( R" P1 ]* M& x& v
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# y$ ^# g- S9 Y3 J          + (obj.getClass()).getName() + ".");
1 K0 ?* R) P: u$ S      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 A- N2 R- x( ]      System.err.println("The process will be terminated.");7 t; P9 t4 B  ]& M( P
      System.exit(1);7 |7 j1 a* _% L) k6 ?# R
      return null;
$ d: E6 {% O" [' q) B# `    }
. u. ?$ U" X1 u$ r2 `, f% M    return sel;
2 a9 m3 D8 q1 \) c, M: @  }# _( @$ G! Y$ _; }
}

评分

参与人数 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-17 11:05 , Processed in 0.016005 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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