设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8928|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
2 G! L% K: H8 f5 A( z! _$ \2 O* }sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
4 e( K/ D( R& S7 U- n, ]9 C  S4 o$ y0 ~! {& S3 q# \# Z3 E' A% H
似乎缺少了一个SwarmUtils的类,不知道怎么回事
7 O5 @* i: x# p/ Y! V; e0 d) A: g
5 H( K( C$ _/ _1 N: H' j/ H8 J4 J朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
" F; ~" r/ _5 [7 d0 o8 w
  e  j) x  H6 C3 Ppublic class SwarmUtils {
0 A/ W, I/ c+ d( b. D  o  public static Selector getSelector(String name, String method) {+ ^% x3 X+ @2 C: @6 s3 R
    Selector sel;
1 j+ M; G0 `, T8 M; N# L* s    try {3 b8 Y) K3 f# a# F" l# X! ~
      sel = new Selector(Class.forName(name), method, false);
0 ^; \# n; }- V2 f$ Q1 _, w! `! R    } catch (Exception e) {
; |& d5 b8 F* ]% n6 t      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( @% ?  f4 f! q0 ?. M+ {! V
      System.err.println(name + "." + method + " returns " + e.getMessage());9 z1 U7 \9 u4 S1 ?
      System.err.println("The process will be terminated.");
0 h, K; i% P1 t: p- x3 x. O4 T      System.exit(1);
' s# h  |% Q! }' k$ R      return null;
$ W% S# e% c+ h% I. b* C: S    }1 M$ R# R7 m  |* X- \* ?2 q
    return sel;
8 s9 f: S6 v. h. d  }
" J9 s+ i; c( Z# N* y) J8 @& Z) B* [( P" ^5 N  p. D
  public static Selector getSelector(Object obj, String method) {) o) C7 g  E+ v3 r- U6 a) \
    Selector sel;( H) R9 j5 y) F9 o& r; B+ ^2 M4 B
    try {, y: n5 K7 p/ l. i
      sel = new Selector(obj.getClass(), method, false);; K7 ?( ^/ G3 h7 E
    } catch (Exception e) {9 a9 {, a" l9 j2 q1 l. X9 e
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 G: X$ {; n  ~8 O4 O1 d          + (obj.getClass()).getName() + ".");% u9 @9 @& k9 x+ t( n! }
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());' D* ]' j4 }2 x$ `6 `1 q
      System.err.println("The process will be terminated.");' R% B, C! Z9 p' c) d3 X: T: f
      System.exit(1);# {2 F, ^/ L0 [: e5 a9 o3 }
      return null;
7 F, ~2 O: m% S9 C/ s: x    }/ w; R3 @% N# C4 O+ |" |  b) @$ \
    return sel;& g. `4 [8 m+ B0 Z
  }# W3 _) e/ W: _9 W- U# ^- W' Q
}

评分

参与人数 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-12 04:18 , Processed in 0.016253 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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