设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8983|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
. R# E- U* \- e! {sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行9 l& P- \1 _& D3 Z0 v; V

' }3 @# x/ \# L; _5 ]. s似乎缺少了一个SwarmUtils的类,不知道怎么回事
- I/ g2 v) H  a& C* m# |# q: O$ R( j  D8 \  R: W* B; q
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;# g. W0 Y& e$ o, J4 L9 T
; S0 ~) [. z1 {+ Z1 w# V
public class SwarmUtils {
2 P9 S3 `. p8 \  public static Selector getSelector(String name, String method) {( `# j1 ]6 ~$ _1 Z) `0 a
    Selector sel;6 {9 x0 `9 I4 T2 N; S5 N$ n! M/ W
    try {5 ^; R, W. N4 w+ Z0 A2 v
      sel = new Selector(Class.forName(name), method, false);% X% @% j7 t2 p) c6 H% X/ A
    } catch (Exception e) {8 Q/ q. Z# _/ l
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; P2 s  x- `& R! W: a
      System.err.println(name + "." + method + " returns " + e.getMessage());
+ M! g# Y9 y- c3 ?8 s      System.err.println("The process will be terminated.");3 m- Y7 l% f" e7 r. y/ G6 x
      System.exit(1);
- ~: a# V" F. G& e- \      return null;
& v" \: `3 z6 B! x: g* }+ c    }
: p+ \- n. O  G& k& g    return sel;
) p2 U/ b  P: e  }
6 l" Q. h, _" M: x6 f; C9 E# I5 q# S2 W, f' {
  public static Selector getSelector(Object obj, String method) {" Y# n& }) O* S2 D+ A$ c
    Selector sel;
, K$ r* j6 A. }5 L    try {9 ^$ ~8 N& Q1 @# V- \( X' u; r
      sel = new Selector(obj.getClass(), method, false);
; X5 D( G0 b# Z3 S    } catch (Exception e) {* e" `: L9 a6 Z6 X4 F- q% E/ \& v
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- O9 a( r' u4 L5 h/ P' n2 D. M- [  B+ C          + (obj.getClass()).getName() + ".");
  C/ ^: `' L1 q: }      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- A* a0 J. s9 [9 @) W& M      System.err.println("The process will be terminated.");. E. }; ~" @0 s' @8 \; U
      System.exit(1);+ u: B0 K9 _+ ]2 q$ z/ K7 P" F
      return null;
) e  {6 R3 r8 B( k8 i) Z+ p    }0 `9 J5 s: V6 }
    return sel;
! d  ^" R9 n  B9 J9 K' Y7 _& |  }* o0 c! F+ d; o6 z% P% h5 h% B/ 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, 2026-2-21 08:06 , Processed in 0.019755 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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