设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9062|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行3 Q" M5 _9 L. R
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行; _3 K: Z) n/ u- B4 Q1 A8 ~, {

  T7 i1 {; w7 V& H5 {似乎缺少了一个SwarmUtils的类,不知道怎么回事
0 j9 d8 C$ d* _0 X2 k7 r
. J+ W" j0 v  c/ r# A朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
- o+ Y" e4 c! i3 ~4 ]) K5 \' o6 h, t4 B8 b8 l" O1 E' F& G
public class SwarmUtils {+ q  K/ B/ E7 _3 ]: s% x; S
  public static Selector getSelector(String name, String method) {
, x; \0 M; v! k    Selector sel;2 h& D( u* g, x" ~- ~# K- C; |
    try {
. d$ s. J. }+ @4 f# P4 W      sel = new Selector(Class.forName(name), method, false);  k& P4 [( c0 h, ?, x5 H7 N
    } catch (Exception e) {7 B7 x9 m$ t8 Q( g; Z
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");4 ]# N! ?; n& ~& U" p& Z/ m4 _
      System.err.println(name + "." + method + " returns " + e.getMessage());2 r# o: j# ?- @5 P7 @
      System.err.println("The process will be terminated.");( e5 v, N( ?& }
      System.exit(1);
: K9 P1 D7 \+ i( R" h1 }: C, n      return null;* k8 U+ g! b+ A: ^7 p' P. P
    }
4 t; C$ a3 D$ R  ^2 c    return sel;
' C* U/ Y, c7 j  }5 D( O" h6 E0 \2 A4 A1 i

7 G& P& f, i* e: M  public static Selector getSelector(Object obj, String method) {1 f0 o9 L6 j* q" n
    Selector sel;. W# C. \4 y1 O+ r( [0 B3 Z
    try {
5 q- j  x; L8 U0 ], `      sel = new Selector(obj.getClass(), method, false);. M! z/ H6 ^$ u0 f- R4 D
    } catch (Exception e) {
8 ?  N1 L6 @, ]1 n( x      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 V; u* Q( B5 I& B          + (obj.getClass()).getName() + ".");9 O! l$ w6 |: m" a2 }! _) ~1 M
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
8 a) D% e# C: f2 ^9 h      System.err.println("The process will be terminated.");3 r1 r" `- N  }! O. J5 O' r
      System.exit(1);( C  K3 y0 s2 [9 `& c$ w$ d
      return null;
+ w4 s' z, M1 ?% g" W    }
  c# y- p% b' T    return sel;
# r% W1 s! C5 P( n  }
% W* f3 ~% F+ @. C$ _}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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