设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5928|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
1 {5 w+ L1 F' B( |sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行) |$ v& F4 t4 T1 X

  k, K; q2 b; l3 ^# C, \似乎缺少了一个SwarmUtils的类,不知道怎么回事
2 e6 K; Y( _7 a
: g2 T. q; @0 @朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
% n" j8 ^0 }& N2 Y$ M# Y6 }
. i( h( p+ t9 m- i, u) Y8 @1 |! d2 f5 xpublic class SwarmUtils {- M0 k1 _/ H" }. _# L0 i
  public static Selector getSelector(String name, String method) {0 k- Y0 f" {' J/ M- ?3 P) @
    Selector sel;# ]) E) t* ?4 u/ Z: B; q
    try {
. C' E( F4 y! [7 M4 o9 M- H      sel = new Selector(Class.forName(name), method, false);
; U% u% q# S2 W9 a. Z. S& V: F    } catch (Exception e) {! A6 \( n9 S5 _/ G
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. x- D/ a  O  }* u1 p      System.err.println(name + "." + method + " returns " + e.getMessage());2 N( l: L8 d- W7 v' D& X' d
      System.err.println("The process will be terminated.");4 V6 ]( g( g/ j5 l5 y3 p+ d* e3 E" E
      System.exit(1);: g% q4 G1 Q( x$ H
      return null;2 x: P4 S2 f( j! C2 {# E
    }" o" d9 X! S3 e! Q
    return sel;8 @+ q# t. G6 L/ o5 e
  }, B7 l/ a7 X1 v6 _3 R$ \7 K

" b- ]- a7 Y; ^7 Q( [  public static Selector getSelector(Object obj, String method) {6 t' b. M- B* R2 g) ]
    Selector sel;. h- e* ?: L( m2 W3 E3 X) v
    try {7 `0 H" S) n+ ^1 o
      sel = new Selector(obj.getClass(), method, false);; h8 T) p# l8 C' a% X5 e
    } catch (Exception e) {; I$ _8 B5 @! d, m( g; ~
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "8 r" l! U" f* j! }7 ]6 ^. s
          + (obj.getClass()).getName() + ".");
' R& T; ^2 F( v( K/ d6 O% F9 k" n# k      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());7 `# Z, H3 @/ k/ E; s
      System.err.println("The process will be terminated.");
' v9 j. o- X4 k' A8 f0 p% j      System.exit(1);
( ]9 m3 m7 J' A2 ~, h- I      return null;1 {2 `& C: o4 R( I2 m
    }
3 J9 e0 y0 T2 ~& Q" z4 e    return sel;% B" \4 @8 r( J" ^, ^, A3 }# K
  }. U7 p% G  L$ _# \
}

评分

参与人数 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, 2024-5-14 07:59 , Processed in 0.016170 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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