设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9930|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
% P+ i5 z: a( Z$ u9 E$ v2 psel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
. e% E2 M6 ^8 l! M- k! u/ ]; q& K; ]& e6 _) Y* v! M) h
似乎缺少了一个SwarmUtils的类,不知道怎么回事
0 `$ a& {' [, Q  R
$ ], `3 m! ?6 X1 ?( t5 L( W朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
! T3 r- q1 [3 N) y6 C9 B& H0 v* O
5 k, y) r9 g" D( }public class SwarmUtils {
. E+ {% @* T; q' l) E  public static Selector getSelector(String name, String method) {  v3 F0 R7 p$ o" C2 ?  N+ x1 w
    Selector sel;0 o" n0 D* f; N" ]+ y: w1 y
    try {, D2 x2 ^$ v9 c1 ?. W! g8 W! |
      sel = new Selector(Class.forName(name), method, false);
$ @& b$ ?& p8 P# ?3 k% T    } catch (Exception e) {/ _6 P6 S' P# Z
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* h6 n* L- Z0 U/ v      System.err.println(name + "." + method + " returns " + e.getMessage());
" `9 i+ D) h4 R2 g2 Q- E2 W" s9 s      System.err.println("The process will be terminated.");
( y# B0 _3 r  j  S$ }7 y  K$ M      System.exit(1);
# ^* G6 L9 b9 {3 ]; f      return null;8 V4 z& a$ H8 k! l6 P! L4 E- n
    }
/ _2 q( c9 |2 e8 d$ q7 l3 {0 B) ^: \) p    return sel;
& o4 P0 f3 U6 H& q% i  }
) n+ y! G4 @. ^8 d. R( c) ]
& I2 N* N* d+ f$ \  public static Selector getSelector(Object obj, String method) {( `% q; M8 q9 P$ q- V1 L
    Selector sel;7 c2 n  W% S4 }  J" }% g/ x
    try {
; E1 u$ W4 n4 z- D      sel = new Selector(obj.getClass(), method, false);
! K  ^: x! E- n3 x    } catch (Exception e) {
# L* D1 G* |6 w3 }5 c      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 Y! t8 k2 k1 \4 z5 m4 o7 E          + (obj.getClass()).getName() + ".");! a/ _  z$ k# q4 O+ a
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());$ H0 V$ n0 \3 q% u2 L  a0 b
      System.err.println("The process will be terminated.");
& Z# O# u( i+ s4 W* \, |      System.exit(1);
5 b: |6 l1 Z0 b' A" y+ [0 K. H" V      return null;
1 G: `- r7 @& O" m( U, l- `# a    }" ^  G' Z6 Y6 H: @: |& L5 N
    return sel;9 C. Z: u) j6 y8 U& Q+ q5 b
  }& D+ C. v" E9 S; a2 X
}

评分

参与人数 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-6-27 12:00 , Processed in 0.016548 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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