设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10247|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
+ v6 T# C, v6 D/ c- i# E  asel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
  y! F; `$ R' K; Y+ {1 u
& g3 S6 \1 J2 }7 ]" K2 x似乎缺少了一个SwarmUtils的类,不知道怎么回事
, z8 d( ?0 W: W- t0 r: f0 F' _7 a7 t- H6 H
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;) z/ o' `# e. |6 z2 y& Y
: @1 o( f) f! O& ?( \1 C6 [2 m
public class SwarmUtils {
! h3 l$ z3 f" i* Y+ s8 Q  public static Selector getSelector(String name, String method) {; x& b5 J' C, D1 f& _
    Selector sel;: O$ t+ L( g8 h) z% }
    try {
2 [1 f7 U, [0 W  p) R      sel = new Selector(Class.forName(name), method, false);' O: A: \! R5 p( _, s
    } catch (Exception e) {
+ J* d+ t1 ~2 ^# x& x" w' B  A      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( m0 {0 Y2 c" E  ^4 j7 ?
      System.err.println(name + "." + method + " returns " + e.getMessage());7 U" k+ U* u  i. P/ v
      System.err.println("The process will be terminated.");* ]/ x: k) s# Y6 ]" b( p
      System.exit(1);; U& g4 |0 ~( e* A$ j
      return null;  u) T/ ^  s* G  G- `
    }
- ?% N8 w; }2 O5 u% p5 h; T/ M    return sel;  G+ F# ^6 M, p* o, X
  }8 f& J) A  v: p+ G& \0 h

' h  T; K$ Y0 k& [8 T* m  public static Selector getSelector(Object obj, String method) {
, T" \4 _% Y$ l* g8 G) M& x& E    Selector sel;
+ U7 m; g. g! w4 _/ N3 W    try {
5 `* p7 h& c/ a$ z5 l2 O% O: Y      sel = new Selector(obj.getClass(), method, false);
+ o8 T& }9 \  s    } catch (Exception e) {
3 x- U" N, j3 w- E% m; {* d      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ z. h" Z& l1 L& V3 x( {' l
          + (obj.getClass()).getName() + ".");
9 I( i3 b5 ~3 F) @5 X: m2 r9 v! q      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
  u7 v7 z/ ?0 y      System.err.println("The process will be terminated.");  O9 \) ~0 X" F% f: v
      System.exit(1);
' ]9 Y; A7 O" `9 W, g      return null;0 M/ q+ v# e( V- x
    }9 z7 i( l" y; x7 l0 W" a0 ~7 p& t
    return sel;
- q4 v* C1 c; q2 X; e  }
% J! \% c* ?- i  G* E) j}

评分

参与人数 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-7-28 09:24 , Processed in 0.018651 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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