设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9574|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
! f9 f; O0 O+ r# o* Ysel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
' G, D4 t/ Y; |! ~! H( B, o0 P( \
似乎缺少了一个SwarmUtils的类,不知道怎么回事
( j" H, n/ M$ ~
" n; z. \8 p9 o2 H3 m% K7 Z# a朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
8 `# A4 b  Z3 m% |( S. y& I. `! \" f% q: J* I9 ]# a3 J& M
public class SwarmUtils {; ^: O% {4 I8 X+ o
  public static Selector getSelector(String name, String method) {
. n3 I( a2 b/ L6 `! N. Q0 _- @    Selector sel;
% Q( a" R  a' ?2 d    try {
" u6 N. r4 H; I# c5 k$ T      sel = new Selector(Class.forName(name), method, false);6 l  N9 Q' z' \1 y
    } catch (Exception e) {$ U$ R8 c( I/ T( ~' Z' W
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) ?2 \' O# H6 }      System.err.println(name + "." + method + " returns " + e.getMessage());
1 C8 b3 |' u# c" o7 O  T      System.err.println("The process will be terminated.");
/ i; b8 m9 b7 a1 p4 ]- }3 b      System.exit(1);. n. E- U2 d0 Y% j+ }
      return null;
1 s! {( x) B3 g" {    }
' Z, Q3 O/ e  f' h3 d1 Y    return sel;
: ^9 _/ y1 [! c2 f' ?. W  }" F3 `6 u& v( ^8 I$ M3 ~! d: |
8 h) s- `. H0 |' ~$ G7 k
  public static Selector getSelector(Object obj, String method) {
* l7 t& J0 j, T    Selector sel;
6 c2 G# x% X* t, x) M( U' Z9 T    try {- o/ }# H$ n. w+ d  J
      sel = new Selector(obj.getClass(), method, false);
# m' `' e+ f$ c7 }) ?  b4 d    } catch (Exception e) {
: j  T5 m1 b3 a( u: Y$ d      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "! l+ R& b/ C3 Z
          + (obj.getClass()).getName() + ".");
* r2 B  B5 `3 a: Y! \      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 h4 J7 s1 V; f+ G$ W( y  y, s6 B2 h
      System.err.println("The process will be terminated.");( ~# [7 Z/ a; T, P% ^+ G! K
      System.exit(1);
0 e; f# Z/ a% `/ H! `  y3 k" M7 G* A      return null;
. A: O" ~% F  X    }( u% G2 G( Y; \9 U# B
    return sel;# T7 y  `2 H; F
  }+ Y+ ^6 |1 C6 X2 @
}

评分

参与人数 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-8 16:02 , Processed in 0.015220 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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