设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10435|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
0 }$ E  j' o$ W9 I. }, hsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行/ u6 V3 s6 D) W: p
+ |+ W4 G7 k, n
似乎缺少了一个SwarmUtils的类,不知道怎么回事
+ W" a7 R  `! o3 k4 _2 l0 o
3 g* B: K  }' {朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;. R8 v. U* b4 m9 Y2 [
) d: @; l: X/ i2 [
public class SwarmUtils {7 A- O7 H: r$ ]5 {* `0 J' M: R  A
  public static Selector getSelector(String name, String method) {
* c( c2 ?1 t0 j- U! r    Selector sel;
0 x! y0 w6 {$ l  r  l& e5 @5 A    try {4 o/ T6 z/ }, x# {" Z
      sel = new Selector(Class.forName(name), method, false);
% n: K/ L/ `9 ]2 m    } catch (Exception e) {* O' p- X( J/ }, v) Z$ j0 X4 y
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# K  E5 \4 _+ }      System.err.println(name + "." + method + " returns " + e.getMessage());7 [% o! E) O( ]$ X, J* A
      System.err.println("The process will be terminated.");) t' n% G. z6 b
      System.exit(1);
8 @% p& n  I, i& E      return null;
& c  p/ `* ?1 ]+ X    }
5 i1 j5 [( a; L: v. O0 D& Y    return sel;5 O  j+ A* t% V* x2 m, O
  }
" T; c+ Q( Y" J: B& X5 X8 s% o3 I2 ^. R0 Q9 Y9 I
  public static Selector getSelector(Object obj, String method) {4 D6 w3 m6 p0 X
    Selector sel;
; u3 M* w9 j9 |" z    try {
8 {7 v) C6 ?; `3 S0 n      sel = new Selector(obj.getClass(), method, false);3 @8 k, D, c: d$ T) L. I3 h
    } catch (Exception e) {: j2 ~# k0 o1 p' B: }2 p8 a  _) U
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 c. B# ^9 e7 X; a" m0 v
          + (obj.getClass()).getName() + ".");
3 P' z7 i- W1 v6 N* J      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());3 L" V, p3 j# I$ U: A! k- z8 d
      System.err.println("The process will be terminated.");
) w9 Z) P; H. F9 ?: k/ g+ L% Q+ K      System.exit(1);9 V2 q$ j5 y$ |8 y0 i0 q/ N9 ~
      return null;
2 E* E$ v, x; `9 U) g! q    }
& Y: O, k% O# T  O8 s8 U) v    return sel;
, Y6 n. p1 R, X' m" X4 T  }# |4 J( C* @/ h9 v% {- v
}

评分

参与人数 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-8-17 01:38 , Processed in 0.017509 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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