设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9940|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行2 A+ M1 a- T4 H  j+ Y+ F4 p
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
" t9 Z$ e5 K7 i+ x1 F! E) a
3 ^' a3 G2 y0 N4 C" ?  O似乎缺少了一个SwarmUtils的类,不知道怎么回事
8 N( m0 M: ^# q/ y! }* K/ m% N( X& v: ]0 j) D2 {+ E1 m3 D. H
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
+ p3 a9 M3 `) Q5 R4 Y) ~8 r( f0 O) v. E9 M2 Q( d
public class SwarmUtils {
3 W4 \* L( ^: ^9 T1 A  public static Selector getSelector(String name, String method) {, S  s8 n6 F4 m/ u( E
    Selector sel;! e5 C( P) Y# u3 f) y4 Q* Y3 _
    try {
" e+ O8 @6 \$ x      sel = new Selector(Class.forName(name), method, false);
# }* h# ^! _( H$ y8 l    } catch (Exception e) {* F" S& e5 J2 H) G! Y. _
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 G) T: _9 H8 U0 y( S( W7 O      System.err.println(name + "." + method + " returns " + e.getMessage());" G8 g/ E) {7 q- w  q4 J
      System.err.println("The process will be terminated.");
, s- G4 i$ M- Q% [6 {0 a! w# O      System.exit(1);
+ m1 M8 G$ ?/ O( t      return null;2 \- g: o. f) j; M
    }/ Y# ]4 F( U2 C  j+ x8 M% F
    return sel;3 ^2 T# \, F! L% G. \
  }
, t0 h0 l; ~* E+ s7 n: Z9 `* Q, d) ^3 F' j+ \
  public static Selector getSelector(Object obj, String method) {/ Q2 ^9 M* g* b& }7 x: ]
    Selector sel;+ R- a+ E/ Y& d$ O% x1 P9 p9 ^  U9 F
    try {
4 F3 a6 Q2 P% |8 ]      sel = new Selector(obj.getClass(), method, false);2 ?* x) Q( F, g1 j, M- d  h; U0 {
    } catch (Exception e) {" p! C, K+ S# N' h6 Y" n
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
% J! B+ l1 Z! b8 u" [: B& f+ C          + (obj.getClass()).getName() + ".");
1 S2 r2 h; i6 R8 I      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
9 K+ L% {, O* t  k8 @  Z      System.err.println("The process will be terminated.");3 j3 v* H! @' d6 Y; [% n( O/ H
      System.exit(1);
9 I/ w6 k  T. g$ u      return null;
$ d, }  W) O* ^% p" T    }9 v6 j$ C, W1 u& M  V
    return sel;
8 P+ [1 w1 f) O/ D  }7 J4 ^5 W. @1 {+ a& W, j
}

评分

参与人数 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-6-29 04:28 , Processed in 0.015696 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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