设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8462|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
, `+ M( P/ O, }sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
/ n; N4 i- y: K% c/ H2 q/ [. S3 v2 T1 |2 d$ K( t
似乎缺少了一个SwarmUtils的类,不知道怎么回事
! ^+ D4 \- j* }" @. `1 c0 t: a  f- L5 ^7 }$ t7 {
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;# p# g/ c+ v3 l& n4 d' K, `
0 M2 {. a5 b. }9 ?3 x4 k2 e
public class SwarmUtils {
% u, }) r# ^4 f9 E  q& f4 }  public static Selector getSelector(String name, String method) {8 N$ m$ L$ {0 C- t$ m/ d
    Selector sel;
3 g5 a- s+ v: S7 F4 J6 }    try {
' V, V8 ^: `% }- y& B+ p; f! O      sel = new Selector(Class.forName(name), method, false);# x' b* w3 a8 r  t$ O+ i' T6 W
    } catch (Exception e) {
1 b2 T( }8 ?; L8 Z5 a      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");% ?$ ]5 Q( v& ]) E# H( ?
      System.err.println(name + "." + method + " returns " + e.getMessage());
( q3 @: F  [  Q) v4 z      System.err.println("The process will be terminated.");2 \( b7 y4 L1 w. ?
      System.exit(1);
- U+ W2 U4 @4 t; p6 s      return null;
- c, g* W; ?' b$ e* [) R9 R    }
& V' p! {1 a8 Z( h& U2 \    return sel;3 q* Q+ J- S9 t/ M
  }
; W: k; {/ O: F: o6 J! |/ v' I" D$ c& T  K' N8 @
  public static Selector getSelector(Object obj, String method) {
9 C; I8 G3 C" o) F. h" C( r$ m    Selector sel;
; Z; k6 G9 \8 Y% X    try {* Q8 e6 O0 u+ W: X! ]: ?
      sel = new Selector(obj.getClass(), method, false);
7 J1 s9 E% J# b/ N, J: S% r% k! I    } catch (Exception e) {
9 B5 B4 Y' x0 N$ ^: E3 q      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
2 h; K( r1 Y" G# j/ g; l          + (obj.getClass()).getName() + ".");
5 H. }2 \! y- ]' S9 [      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
6 U1 c' G$ c/ g; x4 W      System.err.println("The process will be terminated.");9 b: |' W5 ~8 x& u. u* m+ U
      System.exit(1);
' p$ P. t6 d3 w$ P      return null;3 B4 _5 U0 y& n. T
    }2 C  T+ L  a: H1 s
    return sel;! I4 X  S' D' G; `; D
  }- B6 `+ q! S& ]- Z1 B9 i8 _# _
}

评分

参与人数 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-11-24 10:51 , Processed in 0.018767 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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