设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9572|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行4 j# d$ m0 s. @$ o( h. L
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行+ i& S3 H+ l" u' G. o9 W
$ r0 P, j' ~# {. v0 }- E
似乎缺少了一个SwarmUtils的类,不知道怎么回事 ; @: l, S  X! J: s

& N) V: Z' b+ L4 M5 x) O6 p6 l朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;4 J5 i' ?9 Y5 L
! i" F4 t1 B3 u1 d# M
public class SwarmUtils {2 q, D- S7 P  w$ z9 @
  public static Selector getSelector(String name, String method) {1 m$ W* W5 r% s2 C8 {
    Selector sel;
+ s; s, _3 j, ~7 J. e! f    try {' `& F+ Z/ J* f: |& D! i; i# R
      sel = new Selector(Class.forName(name), method, false);
5 j* O( d! ~5 J! D" j# s7 G    } catch (Exception e) {6 {% @4 Z6 C1 t( A9 j0 M( R( e) ~
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
+ F9 g# y: f9 e' S- n, {      System.err.println(name + "." + method + " returns " + e.getMessage());4 Y% N  Y8 E5 b9 d8 u
      System.err.println("The process will be terminated.");
% h& i) z7 G4 d# m      System.exit(1);2 x2 l1 f& B; A  z4 R8 n, \: p
      return null;' G% C$ ?( u, L! s
    }
' G  P3 \3 I: l" Y* y3 d% V! D3 X1 n    return sel;  H  X' D. Y" u- o4 b" n5 ?
  }/ S, N" p* q1 s6 o* U
! w& f  i6 o4 ^: V
  public static Selector getSelector(Object obj, String method) {
0 q- W+ y" C) b3 l3 L/ Y9 n( O9 ?. o    Selector sel;
. y4 G% ~, [. b7 C    try {5 f& ]0 n& j4 x
      sel = new Selector(obj.getClass(), method, false);
9 c3 s4 |% ?- u# t- E    } catch (Exception e) {
, ~" d* \" q4 b8 h      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "  _: T# m; @) T! i' N
          + (obj.getClass()).getName() + ".");6 N# X9 T6 `1 |; ~
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());2 x6 `# e) w8 M; u6 F( ^7 x% |
      System.err.println("The process will be terminated.");9 Z3 F4 v: D% h) |, s/ m/ a
      System.exit(1);
/ S8 ?9 w  ~; K: t: O. t      return null;
% {: B1 p* g% A1 p7 `  S) V    }" ]! I% o2 C- J0 w+ z$ s
    return sel;
: F0 @! a. t0 s  }
; K. i4 f. b& w" l! ?+ t2 T( E}

评分

参与人数 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-5-8 15:17 , Processed in 0.015678 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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