设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10279|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
1 e7 d9 u* Q7 A' Vsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
, F/ s  Y  y1 c  f) a* a9 i6 A$ f' K
似乎缺少了一个SwarmUtils的类,不知道怎么回事 # F$ A- x' B  T3 P+ m

' Q3 j  p5 l" \) w% A: K' S+ v3 [7 z) z朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
9 O7 F/ K- ^' M$ \
; D, J% p0 w) n0 |$ apublic class SwarmUtils {3 z: V' q  j- G/ u4 u8 U: c
  public static Selector getSelector(String name, String method) {/ e+ O, C: ?4 H% P- U) L
    Selector sel;9 j, y( U) H8 x4 j
    try {/ |. J9 V8 p- a
      sel = new Selector(Class.forName(name), method, false);
" Z& \& \  R; T) ^6 ~2 T" p6 B    } catch (Exception e) {
' n7 N( h0 l( ?  J      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; {( v/ L8 g* q# l# k
      System.err.println(name + "." + method + " returns " + e.getMessage());
5 v6 V$ R6 V7 M- e0 f+ m      System.err.println("The process will be terminated.");  C; P1 v+ c; a4 S
      System.exit(1);! b, Z/ K: I% g  ~4 b$ U% L
      return null;3 s+ y4 c. w/ u- r/ y& R
    }% a; u4 E4 I3 K  G/ Z: U8 B6 w
    return sel;
" @" M6 X! }( O( y5 Q4 D# o/ C  }5 T6 e  y; b( y
# F! P& `5 o' h/ }
  public static Selector getSelector(Object obj, String method) {
* ?* f6 A% t7 s1 h/ \# D+ X    Selector sel;' a* Q( T' J) _* k' W
    try {
  i1 x6 o& C* b' v4 r) I, m5 ?* _      sel = new Selector(obj.getClass(), method, false);
- e! y- R! T5 S* [' z, L& p0 t    } catch (Exception e) {
: V$ O( e- `2 j      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
% l/ B! j9 q2 D9 w: G3 R- B8 x          + (obj.getClass()).getName() + ".");
2 Y+ b) [( J7 }5 F& d" Q      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# Z. C/ u7 r5 L( y+ j0 n      System.err.println("The process will be terminated.");
0 }+ M% i: x) w$ u9 W  W      System.exit(1);  {% |) }/ ]; w+ r$ {# I
      return null;
% h, l" \5 W2 W    }( E5 X. s; {3 m1 [; Y
    return sel;
$ M" y, f' p5 s1 m5 J  @6 r- s0 S  }
% Z& w, B* B; u}

评分

参与人数 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-7-30 16:05 , Processed in 0.089541 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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