设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10391|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行" l/ D8 O3 q" S* |: ?& a% g
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
1 a3 ]! b, \, b6 R$ h, P+ d! b' x; P- j2 i7 T; v
似乎缺少了一个SwarmUtils的类,不知道怎么回事
3 U% N* c8 I) h( Y7 C, s; s# @" c) t/ n3 C" c
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;6 e" h7 D; ]* K

4 }4 ]: K* c% Jpublic class SwarmUtils {' D; ~9 v) J! I. o' {4 A
  public static Selector getSelector(String name, String method) {
4 u& P  b, C1 `, w2 s3 d7 r    Selector sel;' o4 Q: H5 n3 N7 O) y, F3 h+ T
    try {
1 d3 U3 ~0 b* x8 b6 H1 a      sel = new Selector(Class.forName(name), method, false);* w& b3 @2 s2 a  G. J
    } catch (Exception e) {
& |6 S' I1 }) |4 s$ B      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& T1 W; b& k' c" `+ M9 z8 p
      System.err.println(name + "." + method + " returns " + e.getMessage());  e  }2 v( E8 R) ]3 t  N4 r
      System.err.println("The process will be terminated.");8 s3 b( m0 O3 `+ T2 G& h# `( z
      System.exit(1);
: N& g% l% r& g, x  ]* U" |( Y      return null;
5 g6 W8 Z1 O% \) Q- p; ~1 x    }! k) h3 L2 P# G
    return sel;1 l8 j4 R+ l  V% ]/ t
  }
% C. t( V! O% a% x! u$ w/ {8 R; C! J( P: `+ M2 g% r
  public static Selector getSelector(Object obj, String method) {
  |1 l" B9 X( _9 c8 }5 U. m! L. {5 l    Selector sel;, z$ k, y; \2 q; Q7 c+ P
    try {
& V& ?) z' S' I" O      sel = new Selector(obj.getClass(), method, false);" P( O" W1 N! m4 b
    } catch (Exception e) {* }9 o, [7 m- Q% J; ?
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& F. a5 `' q# H7 U; I
          + (obj.getClass()).getName() + ".");
1 E8 z1 s5 H( H2 s1 {) S( v& [      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. E; D7 v, t+ {9 h/ U/ D% b
      System.err.println("The process will be terminated.");0 T; r, }8 k$ y7 t$ ~) B
      System.exit(1);5 N& ~4 ^, N; b3 ~) {' v: G
      return null;+ x% |( `% u4 d0 _- ~- q
    }
& N& `7 G7 Q. w1 |* D6 [    return sel;: t9 o$ D; j( x9 k, |3 @
  }- Z5 v5 r4 v5 T! K4 U7 ~
}

评分

参与人数 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-9 21:09 , Processed in 0.036715 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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