设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10397|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行! T. Y2 X( s4 M1 `6 B- r9 z9 |) X* |& t
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行' a; f/ U% V9 k; w6 z- L3 t
. u  ^: ^6 ]  y+ ?; |* r
似乎缺少了一个SwarmUtils的类,不知道怎么回事 % k: C6 \5 v( W/ t/ j0 V3 ]- t

* v7 v3 x& d$ ^# @6 L/ Q5 n朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;: G5 K: _$ W- F  \% m" V
7 r( e. N9 Y, c9 H1 Z# G4 ~
public class SwarmUtils {
  R! [* o5 d4 R1 g  f% R  public static Selector getSelector(String name, String method) {8 s; {: D8 E# R. _
    Selector sel;4 l9 N9 J0 m5 h$ N1 Y  K
    try {; R! Y2 }& C7 P  b3 c7 F
      sel = new Selector(Class.forName(name), method, false);
* t% J8 q( K6 l; h6 K    } catch (Exception e) {
" h) h# i- A* s, S- k: @      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");2 U7 X) z( \5 L5 P, T: U' Z
      System.err.println(name + "." + method + " returns " + e.getMessage());8 s, j8 d% v- Q- Q" |
      System.err.println("The process will be terminated.");: x' j2 ]( A; g$ i- \- Q, w
      System.exit(1);" r5 x2 ]  S9 N3 K  `# o
      return null;. w7 ?: Y0 s+ p7 g# U
    }0 l  E: E( r4 _' w* Y% [
    return sel;
% f( N5 ]5 e7 r  }7 H8 P( G2 b; _+ Q* Z) `& U

7 T% \. N% m! d2 q! g- t- B3 ?  public static Selector getSelector(Object obj, String method) {
! i: [0 ~) @% l5 l    Selector sel;
* q6 q/ g5 @4 L! O    try {' d$ W1 q9 n+ a- e) K/ }& b
      sel = new Selector(obj.getClass(), method, false);
! M. g& f9 K4 R* x3 U' t" N: G2 x1 s    } catch (Exception e) {
0 g0 {. G" f3 f- M6 z      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "# V  q# Y' j  T6 d2 _& z7 e( p
          + (obj.getClass()).getName() + ".");2 ]& c2 j/ _/ T5 N& k
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
. K: L9 @- x2 @# o9 P      System.err.println("The process will be terminated.");4 c' V$ @) x% A
      System.exit(1);
5 A/ ^- A/ t. x( h' F" `      return null;
" _) l: l! d- G6 D5 D( j  Z- ^( K    }
8 C2 W3 ]1 z$ J/ d! s  O3 k/ c& V7 D    return sel;5 C. l/ \2 u5 R& A" s. Q
  }9 @3 |" R! O6 _$ q; H
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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