设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8828|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
; \# |, \1 C1 G2 P4 W) n  e& [sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
, U+ O6 X0 l% }" j
4 q+ l- O$ }. [+ |$ b- H似乎缺少了一个SwarmUtils的类,不知道怎么回事 + H- g6 Z2 ?. A9 v

: a9 v* o  ]& @- F" J! z! H朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
* R1 |# Q2 S, f7 V3 i7 L, e6 H5 `( P
public class SwarmUtils {
8 S! U! i9 `8 I- u' k7 f: Z8 w  public static Selector getSelector(String name, String method) {, S5 P( U' D! @3 g3 ?  O
    Selector sel;
2 x3 U2 h8 a1 c# a' t    try {
0 S4 Q$ l" W. K% M# N% I! {      sel = new Selector(Class.forName(name), method, false);, J+ C/ F( N5 X/ d
    } catch (Exception e) {2 p) `) z! [; s& ]/ R/ m
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# G* A" u) T8 U) I      System.err.println(name + "." + method + " returns " + e.getMessage());
) O9 E1 l5 v* ^% X      System.err.println("The process will be terminated.");: M3 i8 b# m& `- [
      System.exit(1);0 p) F2 K: v" f5 L2 {4 [
      return null;4 M/ Y" H8 A- e: @# e( M" J; }  B
    }
1 j" @0 ?0 j* J4 e! Z7 G    return sel;
3 \) V! R1 A4 k0 |# z0 X% }$ {  }) T4 m0 x) E% v- f9 e7 k
8 I7 @  R7 j4 R; B: T
  public static Selector getSelector(Object obj, String method) {6 `  ]' G8 A* A4 [6 \' p
    Selector sel;
8 H1 G0 c) D- d# D" x! i    try {2 w! F! n$ B' c
      sel = new Selector(obj.getClass(), method, false);
; M* N( F8 g8 `    } catch (Exception e) {' K* N/ e! T, _" L! V1 ?1 U% B
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% K  S$ S+ g; Z& K! a8 C
          + (obj.getClass()).getName() + ".");
5 S# [, ?1 q( h2 N1 V) [3 v5 R& M) S      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
3 r! J0 ~' z# |      System.err.println("The process will be terminated.");
% }+ v9 C9 d" ]# g: j      System.exit(1);
0 {8 d! U2 {6 v2 @4 p      return null;
' R) E1 g& _; b* N6 ]. C    }
0 D2 n# k$ t" }& ^5 h7 _    return sel;
5 Y7 b  p: n% H: T9 {- b" g1 T  }
5 X. y. g2 c( W% ^- s: @}

评分

参与人数 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-31 23:01 , Processed in 0.017166 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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