设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10501|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行3 h/ S& U: X% s7 D
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
& g. k7 h: L/ w0 z! M+ |* K
* ]& l6 W3 U" W$ n2 y( h似乎缺少了一个SwarmUtils的类,不知道怎么回事
4 V! E2 S4 f/ a) k' P
- g! |. f8 f5 o& u8 V朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
6 K9 L, ]& [' e0 A$ i1 n3 o! A5 H6 \; D" Z1 Y$ W' @2 M1 O- s# I1 u
public class SwarmUtils {- i& ^3 C5 }3 R
  public static Selector getSelector(String name, String method) {
& L6 a6 Y# k6 N- B$ k    Selector sel;# t6 m1 b/ l" {
    try {
3 [0 ]" l3 A: r  M7 G2 D7 P8 D      sel = new Selector(Class.forName(name), method, false);
# G2 X) f" s2 F1 R7 M0 v/ W    } catch (Exception e) {
& ?% @% b, z4 k2 u: Y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) P7 j) a+ j0 ~/ O      System.err.println(name + "." + method + " returns " + e.getMessage());5 j* r8 R8 }3 v) V! V
      System.err.println("The process will be terminated.");
& D- g3 j6 G' L( H% M6 `      System.exit(1);
8 {3 S$ `$ u( k* h% }$ Y# `$ R      return null;
7 J8 T; Y/ ~% q0 E& b# Z    }
. i* t9 K  M7 V: K# T    return sel;
' Y8 w' G  g2 k% o; _+ _1 q1 b  }5 T" f" @5 r# Y2 a' G4 l

$ X( N4 v+ W$ [! V2 B' }/ l+ h  public static Selector getSelector(Object obj, String method) {' U, B! f: v8 Z0 b
    Selector sel;
" R. C9 N$ w* v" I0 ]$ e    try {
( E. u% v* b# j6 O/ ^& u+ C6 m      sel = new Selector(obj.getClass(), method, false);5 J3 p1 ^; _0 s. n& c) C) n& y
    } catch (Exception e) {
/ S; ~1 z6 Q; _' B8 W      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 P4 Z0 r6 N5 n7 G! o
          + (obj.getClass()).getName() + ".");
4 y! `8 S9 r% \  X$ y" D1 P      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ V& m8 T7 F" y! v  j      System.err.println("The process will be terminated.");
. u5 V9 Q' v7 B4 x8 q/ Z- v; a      System.exit(1);1 `, @2 n' N+ e( W
      return null;6 ^1 ]% n# k: g0 V
    }! ]: h+ B3 o) p, d9 N% Z
    return sel;
$ G, b& L/ J  r0 I( E# b7 {# t  }
% y. `7 @, W) {: h}

评分

参与人数 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-26 13:40 , Processed in 0.023437 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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