设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9035|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
# [  q8 ~* W, asel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行9 W0 ?3 E$ q: u$ e: r- J' c* c6 |* x4 i

% S2 l9 b, y! r2 F4 l1 z似乎缺少了一个SwarmUtils的类,不知道怎么回事
$ q' _' v" J2 H  z1 ^- u1 F. v+ P4 q( H  V' ~, Y! e3 t
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;- k8 k1 q; y1 _
9 n6 S( |1 m2 A# o
public class SwarmUtils {
) @( |2 G5 r* n- L+ |  public static Selector getSelector(String name, String method) {  j. M; b2 G7 ^
    Selector sel;
0 i1 u# p; ^1 o2 p9 E  o, _    try {* N+ o/ a0 U7 o& o
      sel = new Selector(Class.forName(name), method, false);
! {$ T/ U9 f7 \; g! ^$ a/ a    } catch (Exception e) {9 [& I; g5 q. a, x3 y$ H
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: ~; u5 m  C7 n0 i! O
      System.err.println(name + "." + method + " returns " + e.getMessage());
5 k7 h& ]9 x# x% L/ `  m      System.err.println("The process will be terminated.");
9 S5 R) i& Y, S5 M" U+ g0 W      System.exit(1);; A3 m8 v! y7 v( Z8 `
      return null;% [' ?) G1 _( |' o9 R3 z
    }
& G) F( @  L3 h$ L5 S- Z8 }    return sel;
( X8 k2 w, W4 S* e9 k  }; Z2 w: r6 B$ \/ L/ ^$ B8 E# _
& }; t; k) E; l( v3 @5 b3 a
  public static Selector getSelector(Object obj, String method) {. g; b6 J: f. O) F. F% H$ L9 M
    Selector sel;+ |3 F( T/ W6 m+ t3 @
    try {
$ R& `! t8 |( \: ~. O/ a9 f9 @      sel = new Selector(obj.getClass(), method, false);# C. p2 Y. z6 s
    } catch (Exception e) {
+ s" a7 w# M8 w: S      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ") ]! T: o0 Y# F% G. Y
          + (obj.getClass()).getName() + ".");
+ l2 N- i- k$ r! m: }/ t; `! E      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# z( A3 {* j+ I$ }2 b      System.err.println("The process will be terminated.");, ?0 p! h  H" h
      System.exit(1);
, k  I( N% d* s7 Q/ \( U1 |      return null;+ p6 ^" X1 l  r% G
    }
# r4 |1 M; I2 B) M) h' {5 I    return sel;+ G1 E: v0 ~. X
  }9 B1 a  l: N4 [+ z7 }/ o
}

评分

参与人数 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-3-3 23:01 , Processed in 0.019293 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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