设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9554|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
' ^* {3 E# C) K$ Vsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行2 B- a( Z1 s' X4 B$ J( I& o# Z& s" c
$ @' D+ P. G. u% @. E" \; B* C7 g* w
似乎缺少了一个SwarmUtils的类,不知道怎么回事
. p$ d. O; l1 [$ D1 y' `/ w; v5 z
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
4 t2 u  r5 z) R0 U
0 B- g: G: Q) Z5 x5 d. {public class SwarmUtils {
7 i7 O; n- K: [, a* `9 ~1 p  public static Selector getSelector(String name, String method) {
6 k0 j: g3 [  v8 q. y3 r. l+ ^( S$ {7 S    Selector sel;9 m; x) s9 Q: j8 J: Y& J+ \) F
    try {
. o# B+ L7 j! Y) R# l      sel = new Selector(Class.forName(name), method, false);) X5 [% K' M4 J$ C5 s! z8 S
    } catch (Exception e) {8 a4 U( e! k1 G# a/ l' d
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; E2 S9 V0 z2 M' J, [) P6 q      System.err.println(name + "." + method + " returns " + e.getMessage());
9 g; x: P8 b: D3 g  B9 }0 D      System.err.println("The process will be terminated.");
" @8 h8 P. P. B6 T1 j& A% X      System.exit(1);# ^1 Z- X+ ~  |5 o/ d' [- ^1 f" C
      return null;+ R9 s. v" e% _
    }$ l7 L% t% t$ P& b3 D+ d7 v, d: p/ {
    return sel;- n( {# E8 ?! w2 l/ m" O
  }
1 c/ @# [4 r+ a' d$ \
' k1 A9 {  v' i- f% N. D; C0 {+ G  public static Selector getSelector(Object obj, String method) {
( L6 u) Q& Z7 y5 `" [1 o    Selector sel;
; S) X4 X0 M; K/ J0 }    try {5 S; K8 B. T+ m6 p' ?8 {8 O+ T
      sel = new Selector(obj.getClass(), method, false);
+ Z. B9 |: K& R% e& [    } catch (Exception e) {
; _* L" f8 G- c- g$ O' e      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "8 l$ c3 ]. b5 {6 J# b
          + (obj.getClass()).getName() + ".");
2 F7 j+ z5 i% W1 |9 L! f5 ?      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 b4 A) b1 q, [3 E8 X  J# f( b6 c      System.err.println("The process will be terminated.");
7 c5 d# V/ U* q, X      System.exit(1);
6 {( k8 u8 h$ `, a* J; n4 P+ O      return null;
) y+ E/ I& ~! h9 ?2 i; q7 I6 {    }$ r$ j$ F, e, j5 C
    return sel;- o/ S) ~* R$ k: r. F5 V
  }
! C  Z, e9 `$ r: I}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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