设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10108|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
' Z8 C' g7 m5 U9 d* c# ?sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行/ R5 c( E5 J' U

7 S- t& c3 s9 g6 q9 f; l似乎缺少了一个SwarmUtils的类,不知道怎么回事 $ j% s* ~" B- f5 @# K2 z% B

7 h: |( G- O+ P5 B' h: E朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;* m6 f( ~! L' @2 e5 S5 N( U
0 ?9 @2 x" ?; h3 _; {
public class SwarmUtils {! S0 ?- E( Y' B" j: b6 T
  public static Selector getSelector(String name, String method) {$ I3 A0 ~# K% I7 ]. f8 G% G* Q
    Selector sel;2 H$ H, x  Q4 {2 ]# I; r
    try {
1 {/ Q8 d$ I- J7 v1 m" O  ^      sel = new Selector(Class.forName(name), method, false);
6 j9 Z3 J! e2 W    } catch (Exception e) {
7 _6 k% A$ _, m) H$ ^; Q) O' x; R* L$ e      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: M; i/ _0 B. A" P  h3 E      System.err.println(name + "." + method + " returns " + e.getMessage());+ K1 z. l* k. d# ?0 ~( c
      System.err.println("The process will be terminated.");& z1 f, S* Z% J$ y
      System.exit(1);, m, A) Z  `0 r7 o; i  s) C
      return null;
5 g' K* Z0 m0 _. _/ G2 S1 i! f    }9 n) k0 V8 y& e+ u/ ]: M$ F
    return sel;
: }9 _# \' h! k% ?' F# k1 ]  }7 e) J' }3 l% t1 O5 X6 }! K

; Y5 V$ ]  [9 Q9 p- N  public static Selector getSelector(Object obj, String method) {
; D0 N, V4 W0 |4 ?$ F; v    Selector sel;+ X0 J" h; a" }/ I# ]' U6 {
    try {
9 N1 T2 A) ~7 r' Q+ b      sel = new Selector(obj.getClass(), method, false);
8 j( T9 n, G7 c, W" f    } catch (Exception e) {
/ H, Z: j, g5 M0 `8 m      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 r$ i, [/ j3 ?  J/ M# L9 ^          + (obj.getClass()).getName() + ".");* P- k6 @7 k" S7 @# Y
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" l- d  ^( m7 [- t- k* P8 Z
      System.err.println("The process will be terminated.");* j# u  h* L. ~' D( y) F1 a1 q% r
      System.exit(1);
* w3 A3 W% u$ g      return null;
! T  i3 E9 n: B2 T4 b9 O    }
! o% C$ F0 [9 i3 ~  G    return sel;4 h6 [: Z* d2 i
  }' h7 y8 C+ h$ j, F5 z
}

评分

参与人数 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-7-16 20:52 , Processed in 0.014853 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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