设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10032|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行# J/ s: j( m4 Y
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行9 F; Y" x- s  N. U
) x2 Y& f- r& |0 y
似乎缺少了一个SwarmUtils的类,不知道怎么回事
( G7 N7 w9 V6 g9 V: P  u( B/ ^( e
6 V; C4 y4 Q- m  Y( E朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;5 s- m9 h- S7 C  [, d. o

) m* t2 u- g8 n; h( V9 fpublic class SwarmUtils {% t. V$ x+ J! z. B  X
  public static Selector getSelector(String name, String method) {8 b/ t1 N/ a  h; [- a, w1 \
    Selector sel;0 B+ s. `$ @8 C* V
    try {" _0 s& Z7 r( _1 H
      sel = new Selector(Class.forName(name), method, false);$ |! C' }+ Y) a+ Q; w8 j
    } catch (Exception e) {
4 I% u0 I0 S# @4 l2 a* \2 `      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) w. N$ ~" q) r# @- V' i' U; L      System.err.println(name + "." + method + " returns " + e.getMessage());* S, W- {% X" g& s
      System.err.println("The process will be terminated.");
  O/ h! ~$ ^6 Y: o; y) O) Y      System.exit(1);, L6 L$ J4 w% l+ a0 N# z
      return null;
, f9 z$ X) I6 y0 z    }
# b+ W8 Y# A4 z0 w/ R( B" m    return sel;$ ]# N$ f/ k0 C9 S/ w6 T0 x$ m  b
  }- c9 I! w5 Z$ d5 |) i. M- ~' b( }
# ^: t3 z# \, `6 A" K0 y
  public static Selector getSelector(Object obj, String method) {
" Q  B' a2 L. b, Z: H- O' Y    Selector sel;
* i/ t( [3 i% }    try {
1 l7 A4 E; v* d/ s# n% l; M      sel = new Selector(obj.getClass(), method, false);
+ M7 I& G( v, H0 R# j! p" g    } catch (Exception e) {4 q) C6 z# N2 o* K5 w2 a
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: U) l3 C# T: s5 Z8 y2 m+ r          + (obj.getClass()).getName() + ".");
7 x7 Z# P2 @9 U  |$ R  I      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, s( V5 [3 b7 R+ Z, \6 c! Q9 A* ^" D      System.err.println("The process will be terminated.");
; S; I1 S7 ^5 c/ u4 ^' d% I      System.exit(1);. A$ f$ y' w- X) U, t( w$ W' {! ]
      return null;
) y' H4 Q4 U2 [# {    }9 U+ V# L% [* S& V# @' A- B1 B
    return sel;
8 n" U. T6 N; u  t  }% C# n* k8 h4 ]( a" g
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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