设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8817|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行- g3 g, Z! Q. i6 _/ _" Q3 @( p
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
1 f' D0 D7 x3 ?- Q& c7 d4 S+ n, R: \' x! [# O: K: \
似乎缺少了一个SwarmUtils的类,不知道怎么回事
" S( B& A- X' C) u7 W
: ]+ L5 \# O- N! E1 ?1 Z. i朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;( R6 t0 ^6 X1 k1 z8 M6 ~

6 u5 E) D/ K4 A. Mpublic class SwarmUtils {
' a/ R6 ^6 ]6 H: l6 Z6 Y  public static Selector getSelector(String name, String method) {5 q* s- R+ `& x3 ~
    Selector sel;
) _* y* g. F: Z, w5 A4 ^    try {6 U, j: b0 A- x" a) @) R  o3 e
      sel = new Selector(Class.forName(name), method, false);* C' R; a; t' b5 C: _9 B
    } catch (Exception e) {+ y- f+ J9 K" u  ]; r% b: N
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* i) y( [# V; }( U# [* a3 Q      System.err.println(name + "." + method + " returns " + e.getMessage());. E0 o- n5 O7 g9 i6 K5 [
      System.err.println("The process will be terminated.");* y; b; S% l" J+ P, W6 `; W
      System.exit(1);# K5 ?4 i5 g2 |
      return null;$ B/ _- K/ A; ~
    }
2 g& s; C. k, M8 p! Z1 `; g    return sel;1 t0 t; S1 l, ^, k: T
  }" q9 R( h+ P# R- |+ c/ N
1 _9 W) Q- i/ r
  public static Selector getSelector(Object obj, String method) {3 W1 \' ~1 c3 i+ T) [
    Selector sel;
, y/ A% S# @. q) @9 Q    try {
! M& A4 p9 U1 ~" @& ^9 T      sel = new Selector(obj.getClass(), method, false);
1 n6 E6 D; k- i    } catch (Exception e) {
6 w' P; \# i- z7 I5 S! O- c      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# M( b3 h7 j3 `: l; g; L- |          + (obj.getClass()).getName() + ".");: j( G+ F; ?) A: x! b/ ?. A
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ E, f  u7 B! i, M" l; M( Q      System.err.println("The process will be terminated.");
: V2 M) @' @; ^6 X/ }      System.exit(1);3 W" P7 E8 t) A
      return null;
! ]3 ]7 m7 u1 w    }
$ O, P* \5 m1 d- V    return sel;
8 h# ^: s  {1 n# ?& ^  }+ @- C, R# G! X, P( ]
}

评分

参与人数 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-1-30 08:21 , Processed in 0.018571 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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