设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9129|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行5 P6 M# _) I. e8 I' A: t# l. i* x
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
5 s# r  Q) m2 K: Q$ B5 M3 R: Y. U( P' Y& `1 @" h. x
似乎缺少了一个SwarmUtils的类,不知道怎么回事 # }1 `% i* X7 h9 A0 v1 R$ a2 s
% {1 U4 C: J1 t- \
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
% @" l" G5 ~9 r* f! x1 B" M* D) k, \: |) d5 f! c. R2 }5 Z' n8 g& M. c
public class SwarmUtils {
! j$ H# U2 S$ X/ E( F  public static Selector getSelector(String name, String method) {
- Z- G2 O3 r$ b4 {& J5 \: N    Selector sel;% X0 R3 x: r6 L
    try {7 H. L1 l, M7 W8 H! n
      sel = new Selector(Class.forName(name), method, false);3 w* S4 n4 N' X" a
    } catch (Exception e) {. q9 p5 M/ P4 Y- E' B. g
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
2 l1 m- T& H2 v+ @( ~      System.err.println(name + "." + method + " returns " + e.getMessage());
3 F7 e: x' L8 q8 ^+ d2 o      System.err.println("The process will be terminated.");
9 l  g3 C4 u4 y: M# o& [# M8 e# i      System.exit(1);
2 M6 _: X( W* d  c$ ], _( x* U      return null;
, @. F$ b1 ]* n% B8 X, R) L) \    }
4 @, ~$ ~* ^" c    return sel;
$ P2 ~: p. T- Y" N" H5 l  y" E) y+ c  }
, b8 t# K4 f8 _" O; J2 Q' u
  K$ M7 d. B4 R  public static Selector getSelector(Object obj, String method) {9 a7 X4 e# `7 W3 F, j" g! Y4 V
    Selector sel;
, E# }, U2 d6 `. ?  D7 A5 G    try {9 q. t# x+ V4 @$ z( U# A7 D+ m& ~
      sel = new Selector(obj.getClass(), method, false);7 y$ h1 Q7 F& U8 _* k0 [
    } catch (Exception e) {' s( z8 h6 G' o
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
! X& C' ]- f6 z1 z          + (obj.getClass()).getName() + ".");9 `" Z! d* b. y! q& F
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());7 U; {3 @. t5 a5 y
      System.err.println("The process will be terminated.");0 ^1 d- X/ s  M  ~
      System.exit(1);( K0 Z$ E" a" ]9 L+ b( I0 k
      return null;
! }. f: v& D! @( d    }: G% B5 |6 P* t& q; [& S) |
    return sel;3 F6 [6 U& ~, O! O; b
  }
0 O, `1 Q' |0 g8 ]  Q. }}

评分

参与人数 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-3-19 19:18 , Processed in 0.021543 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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