设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10207|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
* j3 |, J: L: Y+ l: ssel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
( Z3 l; M5 Q5 e+ q9 r4 S+ p  [. d
: Q; s4 x3 A* h似乎缺少了一个SwarmUtils的类,不知道怎么回事
/ S1 I  ^( K7 F  x& b4 k( T) v. M: D' d$ o% I$ X
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
# z1 \8 ^4 B5 v( {
" p. ~% c( V  W( t9 X& o2 Q& `( gpublic class SwarmUtils {( {/ z8 G( r; e& z0 Y5 r, k
  public static Selector getSelector(String name, String method) {9 i6 s' H; Y# N( \) j% A
    Selector sel;
1 G; k& z* i! l& J: j    try {0 K: d. {( t5 W% Y# j( O) h1 ?
      sel = new Selector(Class.forName(name), method, false);: Y& G& C9 {4 ?4 r& ?
    } catch (Exception e) {
8 v! l0 Z7 [) s      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) h; U0 E3 K. s+ T      System.err.println(name + "." + method + " returns " + e.getMessage());& C$ V4 J0 k! o" a8 @
      System.err.println("The process will be terminated.");
! E, W3 y5 m- q      System.exit(1);
: q6 y* M' F! N# U# F      return null;
& C9 k$ N4 f  P: c7 M    }
3 J( ?& ]2 b, B  L# _    return sel;$ H: E: n+ ?9 l
  }
7 @; M5 H/ B6 g) n: r; C3 N" l/ X8 ~- m6 N( q
  public static Selector getSelector(Object obj, String method) {5 j- X. s" R$ d% l4 @7 a% h; _
    Selector sel;) i3 |; T# I. J5 Q) u3 j' i
    try {: V6 U1 G. s) z6 e# p9 L9 e
      sel = new Selector(obj.getClass(), method, false);0 a. T9 s0 _! T6 S! k
    } catch (Exception e) {
6 X1 E* ?# O# f4 c. u      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
5 G# G2 p$ a0 W: j* X  i          + (obj.getClass()).getName() + ".");$ c3 O  |2 M3 L9 D( o6 M
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());  k4 M; ]7 _, H2 e3 e' _
      System.err.println("The process will be terminated.");
; y& t2 d& i/ ~0 |      System.exit(1);/ s/ v4 L$ e0 H8 D" |1 V, p" W9 |
      return null;5 z$ s+ j1 q8 e3 Y
    }* S' w9 H$ N7 h
    return sel;' b" U- ~1 E+ u. I" V# O
  }2 J8 w4 l) m: X# u5 @0 Z
}

评分

参与人数 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-24 18:40 , Processed in 0.018014 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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