设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10653|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
* K' n' e* C4 i! D5 S8 H; {* Fsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行& D( Q) `3 a) q1 I  J! W. }

& k% w% [5 J+ y' R, \8 P  D2 q似乎缺少了一个SwarmUtils的类,不知道怎么回事 + [7 E: I4 ]2 J' x5 q

* R: K4 X# I6 P8 K% k( ?$ q6 T1 h朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;  S8 t+ V, V4 ?
0 |8 y: X  [3 u- p+ i$ P
public class SwarmUtils {) v. R0 l( g1 m% D; a) W0 r
  public static Selector getSelector(String name, String method) {
! q- k/ Q/ R9 M    Selector sel;  U1 l8 Q5 G! q
    try {
4 G1 |' n& z. l3 U# ]& {1 q      sel = new Selector(Class.forName(name), method, false);& O/ r. m2 z0 W& H) D
    } catch (Exception e) {) k! R# X8 y/ J. }" N  a+ ]
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");, a( f, @) j4 l8 y8 ?- y
      System.err.println(name + "." + method + " returns " + e.getMessage());
& q  L8 ]& L  f. ?9 e3 S: Q      System.err.println("The process will be terminated.");
0 q! W$ |2 F6 x2 N      System.exit(1);2 R- d) R! J" E$ i; d, w& i
      return null;
+ [0 L  {: i% T1 |7 E# y8 c7 @$ D    }
, F% m3 p: C# v2 s' E& |    return sel;( V/ F$ {& j( e( t" E. x/ \6 H# [
  }# [+ L+ n# x. }% k/ v% p+ x$ [
- t' s3 J7 ?8 ^* i
  public static Selector getSelector(Object obj, String method) {9 ^5 n$ E$ l9 ]' g" |0 y6 T
    Selector sel;
) B' Y; v. w2 b% I( ^  d% p    try {
1 B# s9 ^) D+ [: E& z      sel = new Selector(obj.getClass(), method, false);
% H5 k. a3 I2 F4 U! o6 H    } catch (Exception e) {
/ S3 g8 g) ]' i5 m9 G% B      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; Q- g% l! p- K; y; h/ W
          + (obj.getClass()).getName() + ".");
9 f' t: |" V4 q6 H3 H$ s      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" m  B7 v/ M6 e( Z- Q* @% y! m
      System.err.println("The process will be terminated.");  ~3 B  ]( D. e- Q5 `
      System.exit(1);
3 @' I* G9 F' ]7 ^1 t7 t* c( J      return null;
, w( i8 k# R7 ?+ v    }6 n3 E6 |' g, X) V0 X
    return sel;
7 C1 e5 A6 Y; \4 {5 v  }
- K! M. Q; [1 k8 S}

评分

参与人数 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-9-14 00:15 , Processed in 0.016335 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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