设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10679|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
4 H+ w% U' \" f' d6 x% j( `5 csel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
9 C& c' u2 y' N' z) k  I7 _  b# k' ~5 c7 k, ?9 O3 B: z8 U
似乎缺少了一个SwarmUtils的类,不知道怎么回事
/ [. T# s1 o/ i) m4 Y4 O' i9 I% p) f7 {
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;' g/ y6 s" E, V" j

3 h+ m" A$ \) {public class SwarmUtils {+ g# L4 b3 m- h6 |
  public static Selector getSelector(String name, String method) {
+ U/ D! h( K* S! A. x    Selector sel;% {0 I  V' C. v! X" q# M
    try {; z0 s( g$ A5 W$ A% I% I6 @
      sel = new Selector(Class.forName(name), method, false);- K: {7 X! R/ b7 o7 b% R
    } catch (Exception e) {
+ K) Q9 f6 I/ K      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( @* [' z: B- G3 T) s: C
      System.err.println(name + "." + method + " returns " + e.getMessage());. t# c, T/ @& m* ~9 C
      System.err.println("The process will be terminated.");
( l: ?3 V8 T' m2 p: T0 j      System.exit(1);
8 q/ z" Q$ h+ @4 E1 c: w" `      return null;
2 y% {4 C! z+ v  Y  D- Z, j! R    }
; r' n4 k& F3 w) D4 P7 D0 w  M    return sel;4 d) I9 v. L3 t; O
  }
0 L1 Z  g3 o7 L: \- l$ k- c* m+ d# a$ e! e: Q
  public static Selector getSelector(Object obj, String method) {
$ b4 R' v. N) y9 E* b    Selector sel;
4 n$ }, C) V% L6 G6 e7 Z    try {4 c3 f; E8 J! l" W. W
      sel = new Selector(obj.getClass(), method, false);- q& d. D$ C6 N+ h2 W
    } catch (Exception e) {3 q4 H2 \- @, M- v7 \! r
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 y4 f, _' o5 r$ g7 p- G          + (obj.getClass()).getName() + ".");
/ b3 c) j4 J$ |* s! @3 A( T% |      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());$ G$ z7 I! K0 b) O, N( _; M
      System.err.println("The process will be terminated.");
3 h! o  U' c6 W( d' {- D1 X+ \      System.exit(1);
# p' x/ E! ]$ D. Y9 k      return null;6 {( E) Q0 q. Y4 @% i* y
    }; P* _0 h0 i& A1 F( q
    return sel;
8 x# q/ ^2 g# U  }
' c5 H5 k+ u9 i: Y5 v1 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-9-17 18:10 , Processed in 0.018044 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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