设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7990|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
6 t6 R4 r2 D- ?7 p# Z9 F7 P& Gsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
! e- H( x& h0 z$ O/ e+ [) l3 T3 d; C" U
似乎缺少了一个SwarmUtils的类,不知道怎么回事
' K) I  v3 b7 O5 }6 ~6 O( ?, p' o4 P7 E! |
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
+ W$ }- I2 A( t# D6 h7 M+ K
" y8 m6 O" Y5 J' F1 d9 E4 kpublic class SwarmUtils {
" L9 K* n5 O9 H" T5 i; H9 n5 W2 U  public static Selector getSelector(String name, String method) {% ~% ?: m! A1 {2 O& {& B5 k
    Selector sel;
- s' U3 T/ w5 g' R3 o5 b) y9 S/ [( o    try {
! H0 w. U" \( N- {      sel = new Selector(Class.forName(name), method, false);
+ }0 M- Q: o% p6 H/ N) j; s& a    } catch (Exception e) {
% L, G; ~( v/ s8 t$ d7 P# J      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 I+ @3 y1 D4 t5 s      System.err.println(name + "." + method + " returns " + e.getMessage());
$ ^6 l/ \4 q2 W3 E+ f      System.err.println("The process will be terminated.");
; U- E; Q+ h* `$ R/ O* \# T3 U2 C      System.exit(1);
4 ^& e. C/ s5 s5 F" y      return null;9 |6 S) q% [# f6 l
    }
2 U. y8 S5 J& ~: I/ A! {- b    return sel;
3 ~/ P' ?. X% A  }$ w! ]4 g4 j) S: F* Y, I

7 r: V. j% F9 K/ J  public static Selector getSelector(Object obj, String method) {
2 N% g7 x6 f! ~9 K2 h4 f+ ^8 s    Selector sel;- ^# \! Z( m+ p
    try {
$ d/ J+ M  m* A0 w      sel = new Selector(obj.getClass(), method, false);
! H/ D7 A! f' V$ ?+ o  `9 S6 @2 w    } catch (Exception e) {
& j! }2 K1 G9 @7 ]1 Z( Q; c: d      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' B5 g0 D7 L' y5 t' G3 s
          + (obj.getClass()).getName() + ".");
# \# o. N. l2 D# _% q      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 W  I1 @5 a( @      System.err.println("The process will be terminated.");3 y0 W& @, a: _! S4 h
      System.exit(1);
7 R% C5 ?5 i6 |" Z# i      return null;' x2 d8 @- b) F7 e  y! j
    }
$ s" s! q; @- G* w9 B- l, V9 J9 k    return sel;* x# `/ {  G0 P2 a, Y
  }; L( G. J8 q! K- X( I1 @
}

评分

参与人数 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, 2025-9-5 04:25 , Processed in 0.017907 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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