设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8288|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
8 t9 ^6 q- u& D. wsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行" Y. S$ e5 G/ E# w. u
7 O; _# t( I4 U6 D; _9 s
似乎缺少了一个SwarmUtils的类,不知道怎么回事
7 D, `+ l1 j# K0 i" P* Z9 q9 n$ R2 s4 Q5 A$ L
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
% q% G1 H. V& [
/ D  U. O0 n1 c6 Opublic class SwarmUtils {7 f' b5 B9 f/ {# D# }( P4 B& C. c
  public static Selector getSelector(String name, String method) {8 \2 r: y  i, K8 g3 P' F2 O7 P) i) e: m
    Selector sel;6 n- a0 D* H- c$ r
    try {7 D! ~8 {4 E3 P
      sel = new Selector(Class.forName(name), method, false);
- f* h2 d& j7 x& x/ T; |" d5 i# }    } catch (Exception e) {
9 A: z  Y: R/ W# W% L2 V      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( M2 q) V6 x' Y5 [# u, z1 J& G( y0 {
      System.err.println(name + "." + method + " returns " + e.getMessage());
2 \9 U# r. y3 N5 U2 V+ K7 _, Q      System.err.println("The process will be terminated.");
( c4 Z' B/ ?6 D. t; f      System.exit(1);
1 d" B: g9 N( q; V$ f4 h# E      return null;$ s& @3 k1 k6 J3 ~& k2 o; ?6 V% H- K
    }# y4 J7 h. v2 p; S/ ]  Y
    return sel;+ J6 S6 Q, R& U, Z. o
  }
4 ~" T, T% R  W4 a
1 e+ _& O% X/ n' f; R: b0 O0 m  public static Selector getSelector(Object obj, String method) {: L3 m7 C. e+ |- \# R, L
    Selector sel;' T4 F8 S  p2 S: _  E6 A, a
    try {
7 F; T' D1 S5 P' I0 b) H  [' @      sel = new Selector(obj.getClass(), method, false);( J' u; j0 }, M8 B  w
    } catch (Exception e) {
5 w  }3 n, t" Q& Z9 Q      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 r1 z0 F7 ~1 H6 o- }! x! `8 m          + (obj.getClass()).getName() + ".");
) a5 T% C- @2 b9 ~  |0 o2 {7 }      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ L5 C, C+ D3 ]$ [      System.err.println("The process will be terminated.");- e0 h, t/ O$ b4 K) R
      System.exit(1);% `* _7 w2 s. z5 A0 ]& }
      return null;
4 t8 |6 L- |# a8 i9 a1 R5 j    }
' n: g3 _3 |/ w! C0 Y    return sel;
1 R1 v% b2 f% g6 |' M& m  }( N; X' P0 @% G- @$ Z
}

评分

参与人数 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, 2025-10-30 02:03 , Processed in 0.020060 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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