设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10595|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
% x: a$ @) U8 b  R/ V. U" ksel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行2 P: Q  E/ U) z) d

3 _! Z: F' w) ~1 N( j. H似乎缺少了一个SwarmUtils的类,不知道怎么回事
- q6 H% F( }3 k. @; ^- W  _: H( w
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
  Q" W6 X7 U1 w5 q
1 M9 n( U6 s/ f4 \/ }( [5 n9 K. d2 Z6 zpublic class SwarmUtils {
6 ]" Z) t0 Z5 Q% e- Q  public static Selector getSelector(String name, String method) {
# C/ t8 m( K0 P' I: b6 _    Selector sel;& L8 R, ~0 K8 b$ f
    try {( j" x* I4 \$ R& v
      sel = new Selector(Class.forName(name), method, false);# r1 x% R* b) P
    } catch (Exception e) {
5 d+ C& w8 I- e      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 M1 y2 B* _- m* k9 M$ ?      System.err.println(name + "." + method + " returns " + e.getMessage());' z9 K/ L: R( ^% F
      System.err.println("The process will be terminated.");
; D: i7 |( D% w( z, s5 G      System.exit(1);+ \, i" K9 B7 y6 E" W7 @  |
      return null;
+ g/ f$ F% n  A, F3 |    }
( @: t0 j( B+ \& y- w, B    return sel;7 o" M* R4 l; R6 w
  }
2 ^# m+ c% g& h8 x6 Q  y; N
: ?- t5 R) `- v* H" a  public static Selector getSelector(Object obj, String method) {
9 F- n" C; E, j% D    Selector sel;
8 [3 K/ b' V! K2 e; K    try {
0 |. K: D  v0 c) e. @1 j      sel = new Selector(obj.getClass(), method, false);2 C( h( x; e+ M4 c7 J
    } catch (Exception e) {
- H6 h8 u. i2 M# |      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ }. g5 c3 F  \5 F' T0 Q
          + (obj.getClass()).getName() + ".");- S: ?# V: E8 N4 V. Q8 c/ t/ j
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, \8 {% N/ Z8 z3 R5 Y  G
      System.err.println("The process will be terminated.");
' C1 t: d* {2 f2 L      System.exit(1);. G: g; n' N7 m( e
      return null;
& g+ k4 s7 u8 a    }
: d2 o% }( M  t7 Q, Z" c+ A3 ?    return sel;, A, Q) m. \3 N- J( P4 ]" M
  }
6 [& S; ?6 l0 s0 b6 }, n}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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