设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9941|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
! h, G7 J  p% c  l, Ksel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
: M  N, Q  h0 q4 \0 m% a5 H) A7 G1 P7 W
似乎缺少了一个SwarmUtils的类,不知道怎么回事
' R( w) G6 Q( k1 v# s
  s% r* H- ]1 s8 ]- ~& @% x- F) y( x朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;, Q9 }; V3 y* ^5 B+ C

- c7 A  I( j) A. k5 [1 kpublic class SwarmUtils {, C& f1 a6 O/ z* ~4 d1 H
  public static Selector getSelector(String name, String method) {& f& i3 w- |1 F2 I3 h- |
    Selector sel;! `9 e& [8 z5 ^& {5 T" G7 I
    try {0 U: x" K3 j2 B
      sel = new Selector(Class.forName(name), method, false);3 l) d( W0 K' \' V+ i* E* C0 W7 f
    } catch (Exception e) {% P8 M- B+ t- w+ J4 U- k
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: a9 n1 H- t: J      System.err.println(name + "." + method + " returns " + e.getMessage());; t# M/ v  q% M
      System.err.println("The process will be terminated.");; d8 n- }/ j! P" Z
      System.exit(1);
) r: u5 C9 ^+ W6 L$ W0 l      return null;! E; f. L* g1 A) \- e
    }
5 _8 q& p4 M3 r1 S- z' D& j+ E- ~    return sel;! U' a2 K2 m/ i! i( {6 V  j
  }9 _* X0 C; h; Y) _/ i
9 C8 z. L6 d6 L' I
  public static Selector getSelector(Object obj, String method) {2 X. y4 z7 F* V3 `% b
    Selector sel;
) x; \; u1 E: g! D" z4 b    try {
+ h5 t9 Z, F+ B7 a! a* N) T      sel = new Selector(obj.getClass(), method, false);
; K  b6 z  G% P3 C: E/ }    } catch (Exception e) {
6 ^( i. u. h5 n8 t2 D      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "7 V% J  S. K0 _
          + (obj.getClass()).getName() + ".");$ g2 `. R# q0 I2 M) N
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% s& O9 m5 o" f) ^: k0 U( p; ?0 y      System.err.println("The process will be terminated.");( w! [0 r: {3 t7 e2 L$ ]
      System.exit(1);
, a+ L9 P2 f' Q% I% l9 n% L      return null;) |* u) Y% K  D5 r- c7 D
    }; g* c6 [" S9 I  U3 Q
    return sel;
1 P- ]% E- d$ T$ m  l5 H  }
4 F2 @: G9 |* U& s( X/ f9 _}

评分

参与人数 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 12:32 , Processed in 0.015147 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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