设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8779|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行& e# ~7 k7 ?( U9 p0 _- a
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
7 M4 h) O& }6 f4 p9 D$ {8 \  T6 Q- z
似乎缺少了一个SwarmUtils的类,不知道怎么回事
  w6 G2 r! |4 d' ^) u: p  z; M8 `& |3 ]7 L6 c) T1 z2 X5 o/ {
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
! d7 y  Z, P2 q+ ]6 b. ]6 ]( m! h( l6 c! C
public class SwarmUtils {
8 Z8 |+ M  A* f5 S  public static Selector getSelector(String name, String method) {
  d% l$ U$ B) t6 h% k9 N( J% n, Y    Selector sel;+ g2 G) {0 U2 p: U9 w2 W. P0 Y
    try {
! T" t+ B2 ]3 R. L4 T1 u7 D1 r      sel = new Selector(Class.forName(name), method, false);8 t. m4 R) l! f8 q( _
    } catch (Exception e) {
3 Y8 R5 N. R0 K8 T+ f0 B2 ]      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: `# U8 x3 I# B% A3 ?& G; a/ X7 _
      System.err.println(name + "." + method + " returns " + e.getMessage());
! S  [. P: W& H7 O- q% O6 h$ R) K/ x      System.err.println("The process will be terminated.");
/ D- o" A+ g* I( n$ e      System.exit(1);
9 n1 @! C, ?4 t, W$ p0 U      return null;
% \4 g, }* O2 v6 k+ ^+ g    }, \* m6 w0 K) W( k1 @" S% l5 y; M
    return sel;8 e4 g9 X) n- P! b( Y) E
  }
8 w0 R- G1 w2 U( T, v& o7 U+ F7 G% D. N4 ~# ^/ m
  public static Selector getSelector(Object obj, String method) {8 g8 o6 E( A8 E# u; H
    Selector sel;, H+ h& \6 V- ?- ?# U6 b  n
    try {
1 @6 r0 P3 d4 G$ x% H! N      sel = new Selector(obj.getClass(), method, false);
! e% L; c5 W0 y' g. s! a    } catch (Exception e) {+ s6 X. D* o! G. {2 T
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 D3 ]6 |4 r  U0 N$ }. ^, S
          + (obj.getClass()).getName() + ".");" |) ]% ?. M# }8 z. q
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
4 f# W0 o2 ?+ _# H6 ^7 ~2 ?      System.err.println("The process will be terminated.");
- L  {/ s6 ]% i! o# l      System.exit(1);
2 [- E9 V* N3 H# Z      return null;
" f# n( s. i$ W    }, P1 k1 w6 e. K0 h
    return sel;
; G/ [1 ~2 U# H+ H5 p  }7 Z( X+ ~9 ?3 x8 g4 w; K: l
}

评分

参与人数 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-1-25 17:06 , Processed in 0.016157 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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