设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9258|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行' }% Z3 G7 c0 j* j
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
8 a* W. \! K  m5 Z# v
. m+ T; W3 z* q* e9 k& f似乎缺少了一个SwarmUtils的类,不知道怎么回事
! W. h! l. V& Q. f
7 u# s! |2 H+ K3 S朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;# k8 Z3 r% z/ J( _% g6 _1 K

6 m0 @0 V7 {6 J5 ]8 Y: Jpublic class SwarmUtils {
4 N5 N" K, b- s" e& e$ i" q# o  public static Selector getSelector(String name, String method) {
8 o3 S1 e5 E: }( S    Selector sel;! i" n3 [. D- J) G. B; i
    try {8 |7 p4 p# i$ G  p3 T
      sel = new Selector(Class.forName(name), method, false);
5 i# O6 g% N3 {+ b: a) U4 h    } catch (Exception e) {) d" X! ~. v. ?' [
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' c* Y6 x; B7 x1 Q: U& g1 O      System.err.println(name + "." + method + " returns " + e.getMessage());( G( g2 n* D- }6 _) G0 O7 U
      System.err.println("The process will be terminated.");4 A3 }8 @+ p% g6 P# l
      System.exit(1);3 x" b0 X: W5 d3 r
      return null;
% ~# ]; t& s4 d; Z    }- J" c' e" q: H0 z# J, r
    return sel;
4 L. A" ]# n0 E; s# C0 j  }
; x' U& E. ?9 |0 C9 ?/ |+ s; R' p8 `
  public static Selector getSelector(Object obj, String method) {; z9 d0 ~8 e. s& O5 O8 N8 @
    Selector sel;
- _+ b8 J: b# ^7 E! Y9 ?    try {9 ]! K' e) w" s/ ^
      sel = new Selector(obj.getClass(), method, false);
; X8 Y! E5 @0 I    } catch (Exception e) {
6 V) S& @- H) u3 p0 r      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "7 m- h4 y1 k( f  G& _) w+ b6 I
          + (obj.getClass()).getName() + ".");
# f& z" ]+ M. C; u' \/ ]      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
4 F5 t3 x/ Z$ h' f      System.err.println("The process will be terminated.");
  l& h/ @/ o, b: {! m" F: Z' X6 u& p      System.exit(1);
6 O. Q, ^1 d7 r- W2 [! h: H      return null;
% a  j4 I( D4 c    }
# u( L+ \2 [$ ]7 L7 _( w1 {. i. ?    return sel;
" A. O( i. @- H, o1 z  }/ i4 J$ C3 E7 F  `' ~5 O) P" s
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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