设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10556|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行# i2 O: A. \5 z# Y& d
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
/ Z" ~1 y! O  E% B- n5 Q1 _. P, e
* L9 v. L# D, Z" ]! |$ h似乎缺少了一个SwarmUtils的类,不知道怎么回事
9 _6 w. P/ R3 ?4 M- d4 q% ~4 E% g" R2 o
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
# i- q- w8 M/ J! K, R. U5 k0 N9 Z, R' S3 @' `; q) F# l
public class SwarmUtils {
5 r) |$ x3 ^# M1 g9 f  public static Selector getSelector(String name, String method) {3 K2 o6 [# d+ I& K% T& q6 Z
    Selector sel;
) m. |& L$ K. T4 |    try {
2 _- l& V4 D( L; |) ^; b* \0 ~      sel = new Selector(Class.forName(name), method, false);$ K, L* @& r: K" H  s- C$ F
    } catch (Exception e) {# d: L' z; u+ n6 G0 j7 S& I9 ]$ y" `
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
/ w) l2 @) W& h8 u      System.err.println(name + "." + method + " returns " + e.getMessage());  J, p2 e: s& a) C
      System.err.println("The process will be terminated.");2 Z6 P! L- d" y  z' W+ W4 e* I4 k
      System.exit(1);8 A3 Z( w. k# F: a( U6 d
      return null;6 Y9 r5 P6 x  H2 d
    }
. g  a: V9 W9 }2 k+ f    return sel;0 G- E) M; z% k
  }
& X# Q1 d. D$ @9 P6 \0 e  ^
8 c( V+ x  ?: @  public static Selector getSelector(Object obj, String method) {
+ e! z% a, t0 z* x8 V    Selector sel;9 F% w. v5 `5 h5 _5 }
    try {+ v+ H$ r- W( E; j- W- M
      sel = new Selector(obj.getClass(), method, false);# F; X( f) _& a
    } catch (Exception e) {$ l2 j" \2 I/ D0 v) E$ y! p
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% s# D. n# f$ A$ ~8 E
          + (obj.getClass()).getName() + ".");* @* _0 C6 W6 ^8 a# Z3 w, z, ~
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
; h" G! I! A' h3 }) k" ]) T      System.err.println("The process will be terminated.");
, o' X8 o( U- V# ~  l0 o: P. c      System.exit(1);
* M9 P' C& N( s% v( s# [      return null;# q/ y7 B3 _" \! A0 j" O: {) e# x
    }
6 D3 ]0 {/ X1 K9 u6 {; Z6 d    return sel;2 o4 L% O; _# Y7 U# b* b" G
  }* @3 ^) v2 |8 R' @1 w
}

评分

参与人数 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-9-3 03:42 , Processed in 0.033656 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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