设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5910|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行3 K+ z; u9 p7 ~' u" _" k7 @
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行8 G- `4 Q8 g5 h
( H% G2 c: {$ k1 n) z" y, u
似乎缺少了一个SwarmUtils的类,不知道怎么回事   i! L0 s! |# b6 v
0 W( {4 q: D7 i2 x6 V% E# v  s! q$ o
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
- D/ k/ g! N7 Z+ [: d
0 L& v* c" o/ X; L$ ypublic class SwarmUtils {4 ~5 L' F1 x7 b# |7 R. p! a6 \
  public static Selector getSelector(String name, String method) {
) R2 z, |3 C1 G9 {% U  [0 K6 P    Selector sel;
2 v  @+ O% A! v7 f2 ?    try {
4 Z2 x1 J; \( `* V* I( R      sel = new Selector(Class.forName(name), method, false);
$ ]9 C2 m- E* _# x    } catch (Exception e) {# s; T/ x/ }' y/ O; i( x- Q8 H" s: ]
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
( N3 _9 e  I, I! a      System.err.println(name + "." + method + " returns " + e.getMessage());2 j1 A3 Q6 p# t. A+ m; ?, a) ^
      System.err.println("The process will be terminated.");8 F8 G9 d2 B8 h6 ?3 V( O1 Q9 \
      System.exit(1);
3 |* r1 A: h; |- z2 w1 n, ~      return null;
; Q! O4 d) m5 {    }
# l; L3 A# }' k6 ]" U# N, L    return sel;
% r+ V, O' V5 f2 h. P0 k  }7 O5 p& G9 z2 H- g; G: j( {- C

1 m6 E  Y6 w7 z, P$ {1 G# \$ Q  public static Selector getSelector(Object obj, String method) {
; o, s) I5 D$ H) I; ?' n$ j    Selector sel;% V7 t  e7 y7 \$ c
    try {
( A, e- A; ]0 J      sel = new Selector(obj.getClass(), method, false);  M; \* ^( t5 t2 i5 g
    } catch (Exception e) {
5 \8 k7 ^, R5 M8 W* u      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& Z: i: x" y5 h0 r; @0 w" {          + (obj.getClass()).getName() + ".");
) o9 n4 O. a8 r+ z      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());: X& u! K; u6 m. D  g0 J
      System.err.println("The process will be terminated.");# A: O! D* z: R9 s! o
      System.exit(1);7 g9 E, ]9 i9 R% w
      return null;
+ J# {1 S  c% J) M7 F  c, D    }+ N" Z+ \* }/ [" `8 j
    return sel;/ m+ }. B& M% g2 J0 N# E: |6 T" T, l
  }% }5 q1 J5 R$ S5 g" 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, 2024-5-11 03:56 , Processed in 0.013621 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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