设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9441|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
$ [" R; t" \  f) h; ssel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行( g3 Y* p5 b% w
5 t. c; ?& I* u. g. V
似乎缺少了一个SwarmUtils的类,不知道怎么回事
2 y5 e* [8 L' N' v: F  [2 C; D/ Z( z, ^0 F
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
. D: h; [4 e6 z- q( w& X0 L
! k1 I: J- E1 b* p) E/ Xpublic class SwarmUtils {, o# R) R; I6 R4 T
  public static Selector getSelector(String name, String method) {8 Q1 |. Z* y# [6 [6 Y/ u8 u& O, h7 x
    Selector sel;
3 W( ^9 r/ L6 R+ ~3 V/ ?    try {
5 N9 ]7 ]. I. }; ~* i: y+ L5 M! {      sel = new Selector(Class.forName(name), method, false);0 E& l" P0 E% X8 E: L# ^6 P$ o
    } catch (Exception e) {
: c& V4 r/ t* D# l7 h      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 D/ `8 [6 u: q3 F0 b      System.err.println(name + "." + method + " returns " + e.getMessage());
6 f8 L" R! [  T5 x3 [( d      System.err.println("The process will be terminated.");
( c4 _  b! b! g9 N. M  S0 B1 U6 e      System.exit(1);
* q; N6 g0 \5 t+ o      return null;
1 S' b0 O+ }2 d  I$ i) D    }
& T; @1 R* l* q1 e; T    return sel;
0 A5 j6 s+ o& T; m9 K  }7 \" t* X. O# M# j6 G, g

! I" P( o- m" x  g, ]  public static Selector getSelector(Object obj, String method) {
% N% E; ?3 _) M  H    Selector sel;* q  c# L! W. c9 m; U5 {
    try {! _" c. {  ^1 z
      sel = new Selector(obj.getClass(), method, false);
' w/ O+ y9 R7 e' Y7 j- Y    } catch (Exception e) {
+ k  {5 u7 z4 \6 U! \, k4 Q' y% J      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) |. m3 }6 `. g( b8 C9 s; J          + (obj.getClass()).getName() + ".");. |" T' S7 r* x& H$ l4 z) n- G$ W
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());: ]/ q* n7 |1 b: s+ ~" x7 y; I5 Z
      System.err.println("The process will be terminated.");  Y/ v$ v; i2 p4 L; Q$ ~
      System.exit(1);
4 C0 K4 ~  I$ I6 ^* W      return null;
5 e3 m7 o3 ~" A8 s    }% o; ~+ v. r9 }
    return sel;5 ?6 s& N: Z& V) f0 h- G. X
  }
) h5 v  M/ L1 h4 U; [* A/ A9 F}

评分

参与人数 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-4-24 21:44 , Processed in 0.016564 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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