设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10082|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行0 u5 L/ G, c% N3 m0 s
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
, C0 B/ L/ Z1 i9 z) Y- {# @
! }. U/ D/ @3 ?/ D似乎缺少了一个SwarmUtils的类,不知道怎么回事
# p  l) C1 o) x. Q1 y( K7 y3 i4 Q9 V0 }0 Y$ M
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
; i* r  U- \( H2 L, r" G% j  `$ t7 Z3 J
public class SwarmUtils {
0 y& K/ _/ |" `* }2 A' t8 C- g. k  public static Selector getSelector(String name, String method) {. H& E, W1 F* U' k
    Selector sel;
+ }/ f9 Q7 G- v2 _& p    try {
4 w1 {9 V* r. l6 m( l! g) N      sel = new Selector(Class.forName(name), method, false);% m4 G. y: D% J& Y7 x3 d5 Y- q
    } catch (Exception e) {
1 k2 E) S, ^, P/ T' Z0 A      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; @0 J, ~: {( I- C
      System.err.println(name + "." + method + " returns " + e.getMessage());: W+ |7 U4 d0 s6 S. p6 u
      System.err.println("The process will be terminated.");
% u: S, j+ x- D, m3 Y3 |      System.exit(1);
' s1 w* T( j/ t4 l1 N7 f/ b/ x. z      return null;& s- j2 I; k) |* [
    }7 V- H5 }1 ], x* d5 [
    return sel;
9 `4 f5 t4 p0 R. ~  _  }, s6 T) B1 C! Y* \

( w6 s5 E! h3 W& a0 A3 \) T6 U! A  public static Selector getSelector(Object obj, String method) {
# w+ S/ d1 i! g2 ^$ K3 @( r: R8 A. b3 }    Selector sel;
- i  U. E% `: @& y3 F/ m7 X1 K$ Q% H# X7 w    try {' f1 |3 |! O" {: R/ A$ ]' g
      sel = new Selector(obj.getClass(), method, false);
3 A* d% j$ ?( u: b; k% d8 t    } catch (Exception e) {: H  |- C5 F1 c4 @
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
% E$ P$ t7 \8 p: i% H8 E$ P, J8 W3 C          + (obj.getClass()).getName() + ".");
5 h. l4 y1 {0 l" z9 L      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 l6 @9 \0 P5 ?' T      System.err.println("The process will be terminated.");# S8 q9 S5 `3 t9 N
      System.exit(1);
+ c8 ~5 Z& R0 M/ C- ]( W/ F      return null;9 q5 {2 R  n( ^6 |3 g
    }
4 C* ?2 b/ t& M/ [    return sel;
& g$ h/ l# ?; {/ R6 ^3 {2 X  }/ F0 `7 I; u) z7 k5 R* P
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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