设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10011|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行; l/ L/ t% H$ \. I; |9 L- h6 L
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
7 O1 S9 ]' ~; Q5 S! d3 d1 L6 N7 W6 z2 w
似乎缺少了一个SwarmUtils的类,不知道怎么回事 $ H7 y# ?! Y% T% l' g! h$ v) I  D+ [
; M' z+ p5 q8 u; h9 y. ~* d
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
2 z- v% J- @+ @4 S( P. _& B4 M1 i- _% h7 r; ^6 l& ^
public class SwarmUtils {  z/ c6 ~2 S- n+ T) N5 p
  public static Selector getSelector(String name, String method) {- v$ U% b% J5 _2 a: j: ?! v
    Selector sel;- B0 W( n& J: q9 T; C# ?. `
    try {
1 v% J. ~. a6 m      sel = new Selector(Class.forName(name), method, false);
9 X. P6 U5 `. C2 _! a    } catch (Exception e) {& k' c, S. c& R/ x) I
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# X  s& [' I( w: k! U; i; O      System.err.println(name + "." + method + " returns " + e.getMessage());
+ I+ B' x9 ?* `' ^* t" h& _      System.err.println("The process will be terminated.");! F: L( E5 v4 i! |- v) Y3 R- \/ j
      System.exit(1);. K0 O1 y8 j; D" m8 \; G
      return null;
: l, N- G9 u6 G- Y  P9 p    }
% i4 f/ s$ h0 Z. E3 t3 k. C- V* x    return sel;
+ a, {0 O# n% v% d2 K$ x/ F  }% b, Y( W# @8 h! ]- r, h

+ o* |8 e; G6 t' d; n! l6 P  public static Selector getSelector(Object obj, String method) {
8 H; b8 A4 H" ?6 m- j0 }    Selector sel;- w" {6 }2 }8 N, n/ H  u
    try {
8 h7 P+ x- R. n2 m1 b  W      sel = new Selector(obj.getClass(), method, false);
, G- O( Q' t1 Z- Q+ t    } catch (Exception e) {
: D3 v, x% D% Z4 t! h; K* A) F# F      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 Q1 Q2 `' |" l5 C          + (obj.getClass()).getName() + ".");% g0 r5 ^2 r( e# F, M) T$ w% b
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());$ L# U- M  x2 L, M7 P% F% g3 a
      System.err.println("The process will be terminated.");
6 T9 b3 s0 @0 s$ F6 L$ W      System.exit(1);" W' d- @5 F& T$ j9 D7 e, [: y
      return null;# p. A* ?) h" W. i, x
    }& B& I+ p. B2 F' r2 z% p
    return sel;9 f) z0 w1 X9 N
  }
+ O  ?- {: D$ |6 r}

评分

参与人数 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-8 07:22 , Processed in 0.015085 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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