设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9243|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
# U5 F9 k" t0 r8 Ssel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
* b; `1 ]  a/ k3 P+ K5 l* I/ C- D, q+ b" z
似乎缺少了一个SwarmUtils的类,不知道怎么回事 2 r2 h# Y0 B( E$ U

+ H1 j- x. G* k& ^朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
3 y  s! X3 B/ ?" k# M3 e; c. p+ U$ G# j) @/ O% w$ \# y0 d
public class SwarmUtils {
1 O: Q: o, [) n' c  public static Selector getSelector(String name, String method) {
* n% ^# C. R& f9 h    Selector sel;! N8 z) G9 w4 D# w1 g( D
    try {# S" [  U9 J1 |: M, V" F
      sel = new Selector(Class.forName(name), method, false);, w4 v+ T) P- @* `7 N, _
    } catch (Exception e) {
1 p7 o, `( d& ~' J/ `" F; G      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* A; C2 S. h- x3 ], w
      System.err.println(name + "." + method + " returns " + e.getMessage());
6 }. b3 v8 B( v2 M* M      System.err.println("The process will be terminated.");
+ @( S9 m) @4 c* s! C      System.exit(1);1 V  L/ z& e4 s8 @6 W1 j- k
      return null;
9 f1 T' ]: X2 D- s/ o- z( a1 A+ l) i    }
' X1 e1 I; m  E' A+ j9 B    return sel;
2 q; d$ o) I: N! [) g, K# p# T  }
7 H0 e7 D. \6 u1 U
/ i2 B' G. s4 e; f# N  public static Selector getSelector(Object obj, String method) {, M6 K7 T" \" W8 t; b6 {. a1 F
    Selector sel;2 @( A, e) u  y# |
    try {8 D8 |4 j- N9 N6 a! C$ z* p) r. m
      sel = new Selector(obj.getClass(), method, false);* H  W/ c' F4 A( }9 m
    } catch (Exception e) {3 g( e) t" {+ o$ E8 }
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "9 l7 r% L. n% B$ q; S# z* d
          + (obj.getClass()).getName() + ".");
0 x1 j* q. N+ N2 }# e      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ t! f1 @/ W; ?/ Q* ^7 C8 ]. X      System.err.println("The process will be terminated.");5 |* Z3 a; m, N8 q! n. X
      System.exit(1);5 v" N, D9 R5 q
      return null;/ M4 g2 J$ a/ v% d9 y( j' g2 `
    }; i- f; k$ S, z5 k% D0 x! v
    return sel;2 W! l# g' V4 [/ m+ ?0 @
  }
6 m2 q) I  [3 v7 j% r8 p}

评分

参与人数 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-4-1 09:17 , Processed in 0.022282 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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