设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8864|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行# h9 n+ q' u8 H* [
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
% e$ J& {+ L3 A' y+ G! O) ^
0 B  G) s8 g+ Y% F) P7 c) p似乎缺少了一个SwarmUtils的类,不知道怎么回事
) N7 m5 w5 z% P- }( G6 N% b2 Z$ e5 q1 i+ r& S- W; Z; ?8 Q
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;4 t' D% n+ R- M- I2 n* l

4 k/ O$ _: @, T- P2 epublic class SwarmUtils {
+ |% W8 a! O1 c0 V5 o  o2 ]  public static Selector getSelector(String name, String method) {
5 u0 _: v6 C  c  {( D" [; h) v3 B    Selector sel;
! {' \2 z- l! Y9 ~: Z; Y/ I    try {
. D' c9 l7 K' b3 ^& f% f- x      sel = new Selector(Class.forName(name), method, false);
2 Y2 ?; [3 G* U2 e$ T# [! O    } catch (Exception e) {7 B. _' l: H) X0 u
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");/ j: x$ j- P  m8 G
      System.err.println(name + "." + method + " returns " + e.getMessage());
1 L7 D) ~- l) N7 X1 Z, u      System.err.println("The process will be terminated.");8 @5 m. f  q+ G; c0 W
      System.exit(1);9 K$ E9 L+ }7 E" M
      return null;- @1 D% S& l+ `) U, P9 ^4 ?" v5 D
    }9 H8 B: u6 s8 Y& V
    return sel;2 K9 a3 y( l* g& x; H) E+ G: i
  }
8 |9 _# t* _+ T6 F
+ _) x1 Z4 w2 M( Q  public static Selector getSelector(Object obj, String method) {: B; L' l2 Z+ m. T
    Selector sel;
1 r; @# y9 M( G6 \7 ^4 J    try {
0 K$ d2 V0 p2 ?* E8 f; l  ]      sel = new Selector(obj.getClass(), method, false);
. O) S% H1 o( ?( D2 O; i$ |    } catch (Exception e) {( w7 V& @4 l; I! u* ]& C$ I6 M
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 [8 z) w7 E, [  R/ o% W+ Z! X
          + (obj.getClass()).getName() + ".");
3 x, w! N' I. t" m! z5 B) W      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. Z+ R5 |0 |* d8 X$ h0 }
      System.err.println("The process will be terminated.");
  K4 j3 Q6 T8 N9 n      System.exit(1);3 b4 p* |5 R; B8 B4 U% Y, G
      return null;3 h: v2 {! @8 {' c: y3 l: T
    }' P8 L( q! W' p" r
    return sel;3 I; d5 Q  \) n- i. M- E
  }
$ V0 {: _$ l2 S+ W# m}

评分

参与人数 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-2-5 17:45 , Processed in 0.019450 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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