设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9551|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行9 W- [+ [1 a6 t" M  J
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行3 Q& }( V3 U1 D' Q

5 `, T9 s/ R# n( ~/ _# Z似乎缺少了一个SwarmUtils的类,不知道怎么回事
! }3 d9 @/ J2 n( N# [5 _/ x2 G6 U- m! v4 I) R1 C3 P
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;9 f* K9 w9 w% v$ Z/ U

' k6 n& {$ n  a+ ~/ R* }" apublic class SwarmUtils {
6 l" `- B' z/ G  d2 B  R  public static Selector getSelector(String name, String method) {
, T& Y* E/ g! f' E+ f! o' C+ G( x    Selector sel;
% J  ~" G4 i, P/ p5 f8 j    try {
9 d7 e" D5 j) J. N      sel = new Selector(Class.forName(name), method, false);
; F3 s0 }3 {: }. ?8 t) }    } catch (Exception e) {, L* P, P) I* \! T7 c% [+ V" T
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
( c5 F9 G" c& O      System.err.println(name + "." + method + " returns " + e.getMessage());8 ^5 ]7 d7 y. x
      System.err.println("The process will be terminated.");9 D# I# I- O( c! {. \
      System.exit(1);, V4 C+ k. R+ s. s& _
      return null;
% w# B! b$ H$ e3 q    }
; F8 D4 p& S/ ]2 j+ ?    return sel;% a# L2 ], G9 i3 ?3 o& ~4 y% @: h
  }2 v# R/ \! g+ Z2 g
- Z5 ]5 h# O9 q8 o9 g
  public static Selector getSelector(Object obj, String method) {
' i8 u! v2 ]3 z3 t  f" |2 j" R; m' h5 y    Selector sel;
2 Y6 `9 @" C6 l+ C& _! i: E, f    try {
9 W; B  m7 i6 V) O3 q      sel = new Selector(obj.getClass(), method, false);
0 ?0 E% u$ u- A1 x    } catch (Exception e) {' f  w+ {# d, L3 H. K* C1 B
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- H  e% o6 Q( o3 V% N          + (obj.getClass()).getName() + ".");) U4 B4 [6 j" j( |8 R) |" S% z
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 i$ r) ?; \" |9 c
      System.err.println("The process will be terminated.");
' `& q& y! x, O9 o$ o) g      System.exit(1);7 O8 m1 d+ ]2 x" z2 {- j4 [: N0 t
      return null;3 O' c1 O$ Y# }9 ^) U8 Y+ ^5 U+ t
    }
) ]1 C  ]$ Y2 w4 k& Z7 {5 R    return sel;( s/ w* J2 H. c- f: C% p3 y9 ?: P
  }9 v% u$ t7 ?$ e
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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