设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7588|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
+ ]; r# ]# L* V0 B! E( F+ z3 W, rsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
; T* U' l" j; S5 v' R$ s7 W
6 E8 H  V( Y$ |& R( Z, _. N" o似乎缺少了一个SwarmUtils的类,不知道怎么回事
- S* O+ k7 }* j1 _' n7 R2 d& a- e! `$ u/ ?- r$ O  u
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
  |! Y. _/ s6 _+ A8 d$ L# v1 K4 M/ ]
, M# ]) ~  u3 T: I$ A6 Hpublic class SwarmUtils {" t* g  \8 I/ N- `! k* d! _
  public static Selector getSelector(String name, String method) {" K. M( l, C( e. k
    Selector sel;
8 J5 D7 X" q- h- c( U  i    try {5 j) [: w8 @* o8 g: I
      sel = new Selector(Class.forName(name), method, false);
  _- h! R& V, [9 A7 B8 g( r1 _    } catch (Exception e) {4 B4 r+ c! x3 `' a5 h7 X/ v
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 A. A" j- ~8 ]% K3 {( H% [      System.err.println(name + "." + method + " returns " + e.getMessage());
% W  U% Z6 h) P2 n& S      System.err.println("The process will be terminated.");
+ R( S* J% Y5 o3 Q1 [4 o      System.exit(1);/ Y( e$ `4 I1 {4 f
      return null;
! d! Z$ u. \. ]6 ]" G1 z9 @    }
; H* M- t* ~  l9 _6 B    return sel;
/ k  u. D# r/ F' S( q4 Z  }
. ~+ S: ~5 L/ P" f' Q! n$ a! V, x( @, b) j
  public static Selector getSelector(Object obj, String method) {, s+ A1 U% |8 @& C6 r! n6 k1 W
    Selector sel;: Q1 |) E- I9 h6 j$ S
    try {
# c5 d( V* X6 u0 a      sel = new Selector(obj.getClass(), method, false);. }9 v7 E- L  ?# x4 L: B) E- e
    } catch (Exception e) {) c# Q& `! c! n% b: J6 Z
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 V" a) k; n. @1 b9 S. H          + (obj.getClass()).getName() + ".");
# n. e+ T9 I" q$ R8 `  R5 W      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
  L$ e! g+ ^, S, v" q! v      System.err.println("The process will be terminated.");& e& @2 w7 Y# a& g6 F
      System.exit(1);
* ^3 i" D+ Q; k& _9 H4 J, i  \# L      return null;
# m5 G0 u$ _9 y. a7 c    }1 ?) I, e8 r, o( ]9 x
    return sel;
+ p4 N/ x0 J- i1 ~7 A0 E" m# A0 z& f  }; Z8 }& z" \! m" p' p. K
}

评分

参与人数 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, 2025-6-27 08:19 , Processed in 0.017983 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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