设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10750|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
4 ]5 U6 }; Z2 psel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行( k; w8 Q% c" J5 ^5 p7 R

+ `( I* f, z" ~7 G) H1 |  x似乎缺少了一个SwarmUtils的类,不知道怎么回事 * y! @& t: C# P
) ?0 L( S% I: O* |8 v* a" B
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
) b' W/ W$ I8 O/ f  J9 F1 P5 I' g9 T* z: y/ ?8 u% G
public class SwarmUtils {
/ C/ Z* |) _. h3 B4 J) N3 Z# `- h  public static Selector getSelector(String name, String method) {
3 D$ ~, E" t. o7 q; Q2 y& L: T    Selector sel;7 a  H+ S; x, N
    try {
: k0 a. ?- e6 Z3 t& G  b( l      sel = new Selector(Class.forName(name), method, false);% T# \% @3 Y, f( F% C2 h# J1 @
    } catch (Exception e) {$ y# d; i* T& T
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
& ^" R- |7 g# b7 T1 @      System.err.println(name + "." + method + " returns " + e.getMessage());) X' G: v7 @$ I! l2 b# ?8 Y$ d, t
      System.err.println("The process will be terminated.");
& s! N' l! l" I- e      System.exit(1);4 m) s  O- Y  B" N) O
      return null;
5 Z6 c* V+ Z' a6 w5 P    }
8 D8 N* e% Q5 i8 i3 S  Y    return sel;
3 P; Y+ k9 `6 g4 c" q8 [  }
% G* M! P" k1 a& h  ]* C) [& W  B% L" @( Q3 ~, b/ \  k# b
  public static Selector getSelector(Object obj, String method) {
3 k# H1 \) t- ?, I9 x/ I1 m; n    Selector sel;
0 h  G3 P( Q8 |  \. u0 H    try {* q, G, n! v  A1 y
      sel = new Selector(obj.getClass(), method, false);
8 g% X! B: R8 c& v    } catch (Exception e) {
: F0 x9 S6 U6 ^3 Q      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 O1 v2 \' c; }
          + (obj.getClass()).getName() + ".");3 ?1 E# P  I1 V0 C- L3 i
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());2 t" }! m0 d" T2 X0 {
      System.err.println("The process will be terminated.");
8 t7 i  n: N" j' j) K      System.exit(1);
  G0 e$ N6 p( @0 ]  h+ e      return null;: C- l( O6 e. v$ ~- N
    }
+ b1 u2 s7 z) }. ?    return sel;# I5 c1 O# `$ d$ J5 ~& v& \
  }
' h# i% q9 l$ h% T! ~}

评分

参与人数 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-9-23 13:51 , Processed in 0.022396 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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