设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9144|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行9 m# Q* T: O" |  O/ H' A" S
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
# _. E4 \! F; B+ H" J5 W6 B
. R, l1 y9 C6 J# g) y, f* D6 v似乎缺少了一个SwarmUtils的类,不知道怎么回事 - m6 M7 N; ^! z' b8 c- m

+ L% U+ G, s" y5 c0 X朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
6 N6 L7 j4 R# d4 P' s  N* `6 \
: I. w. e1 m8 d8 P+ M& X0 Zpublic class SwarmUtils {' t" }4 @0 o% @1 U5 V0 a1 R2 ?% K
  public static Selector getSelector(String name, String method) {
0 b! j; ~" U! ^( v+ z+ O    Selector sel;
5 R3 I+ h( X7 g$ H* l    try {& H; I6 y5 ]0 P; h5 {
      sel = new Selector(Class.forName(name), method, false);5 W/ a) x- o' o) C. f
    } catch (Exception e) {
1 y& Z0 H) ?. Y0 p1 p4 d$ B, k      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
6 K! t: i" j: J% a$ a' _      System.err.println(name + "." + method + " returns " + e.getMessage());
# v- ]3 y1 j7 {: s0 i4 g! h      System.err.println("The process will be terminated.");
5 o6 S+ C1 X/ ~9 r5 A2 b7 n% ~      System.exit(1);
4 Y! T3 ]1 U0 x  l1 c      return null;0 f  a" i- n, o- a/ _
    }
- E' a& d( r) B7 F; m  i/ I    return sel;; V6 I# a0 c: Q' Z% T8 q% G
  }; e" J9 r" N8 x9 q/ I$ t& n9 ]
0 R. n$ G) y$ C' [% l2 }9 W
  public static Selector getSelector(Object obj, String method) {
. B9 W" R2 q4 f    Selector sel;3 P" Y. h. D8 p; r, Q, r
    try {
# d) z% Z, }% L/ ^; R      sel = new Selector(obj.getClass(), method, false);% g7 V7 s! }, G: }- Q% F7 v$ E+ `0 E
    } catch (Exception e) {; @/ e& P2 j! Y7 s7 ]) n
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", x7 B" W: w- E* K8 F4 _; A' w4 {  r
          + (obj.getClass()).getName() + ".");
. i: g5 J* j5 |& F      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% S5 A( V- S6 n3 U! v
      System.err.println("The process will be terminated.");0 T% L  l# B9 F& X4 a! \* c
      System.exit(1);$ V# p, q6 e  {# F' r( Z* l4 l
      return null;
4 O2 j% B* M2 G8 s, p' f    }
* x. u: l2 g# C    return sel;
# z4 j3 v$ n3 Y$ W- _. _$ X  }
2 K2 n; k6 \1 Z: F}

评分

参与人数 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-3-21 17:42 , Processed in 0.021090 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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