设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9255|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行: J% Y# w! ?1 R2 q: H0 L
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
8 A5 j% F: `0 c' B- z. `/ J( @% }! T$ f0 w: l! K
似乎缺少了一个SwarmUtils的类,不知道怎么回事 - Z+ ]; K  m3 M1 T2 [% w/ {

- |2 }3 e3 S( x3 K  @& _3 o2 S朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
! _1 |8 ~& f5 q) s/ \. t
3 \% I% h; \2 o. O2 h9 ^4 ?5 [% d0 apublic class SwarmUtils {+ W$ K' T- f  A
  public static Selector getSelector(String name, String method) {0 _  |* p- [% y9 C# _8 K* X8 z# H
    Selector sel;, {9 q" T5 K6 {" k. {+ z
    try {$ p0 d! G5 j1 G, |& `9 p5 K
      sel = new Selector(Class.forName(name), method, false);
' |/ z+ @8 L( H, ~, v0 w! N    } catch (Exception e) {
. v4 ~- y6 [/ x# ^* f( y/ `      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* {! l6 d  q3 ]) n# A
      System.err.println(name + "." + method + " returns " + e.getMessage());
4 R7 w. r, u2 a7 W4 c0 o      System.err.println("The process will be terminated.");
% O( |+ O4 @, j  h4 C2 |      System.exit(1);
" ]3 o- C# l8 [4 F% u+ A. d2 u      return null;5 k: j% [) x, R4 F' Q
    }" {  O- @$ T6 Y* K
    return sel;
8 K& Q" o7 a$ o1 f  T+ I  }
3 q1 F  U& b, r4 C9 U5 p
1 w  J2 q( ]9 S% F9 B/ g0 c  public static Selector getSelector(Object obj, String method) {
  U; K6 W- d* y) K, x2 L4 W    Selector sel;7 n  F5 a4 {: c' `' d% J- E2 B/ D( g
    try {
' {$ F' N. J5 f5 N6 X7 Z& S& E      sel = new Selector(obj.getClass(), method, false);
; S. X& P; H4 ~! v    } catch (Exception e) {: t" n1 }6 w: ]& l) U
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
; T- k7 H# R& }          + (obj.getClass()).getName() + ".");- m7 E* c  \$ |$ x# K
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
6 v& N; O7 j) N2 C! U      System.err.println("The process will be terminated.");
3 A8 o5 `2 }* J      System.exit(1);" c3 q/ ]9 e7 ^% c0 C' D3 A9 U
      return null;
2 Q5 C; u) k9 s8 P7 a3 H    }
5 ?) y+ t) h% r    return sel;
+ D- Z3 g; h* K* w  I* K; }  q  }# U$ i; F& F4 }3 ^+ m, L# D
}

评分

参与人数 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-4-2 10:45 , Processed in 0.018002 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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