设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10129|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
5 f! V# C+ L7 M) [. G' ]( usel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行* D) q1 S8 W/ w( y
3 K8 H+ m; |5 |/ L
似乎缺少了一个SwarmUtils的类,不知道怎么回事 6 o( U- f. H4 n* a2 p% D

% c0 B4 L9 i/ @1 }朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
" r$ |/ i; b8 T# N! K9 N7 j4 i8 |+ B
public class SwarmUtils {
: ~4 w# S, v! U1 w  public static Selector getSelector(String name, String method) {
$ W7 R+ W4 f( `3 y- [2 i1 X    Selector sel;, H+ r! R2 _+ ^8 ]# n# C
    try {
7 d; h0 k/ c8 Z      sel = new Selector(Class.forName(name), method, false);
( q8 B8 V6 e# s: |# B, U9 N    } catch (Exception e) {
7 Y. ?8 d4 O9 E      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 e: W, V. k" a/ e  Y7 _) H: e      System.err.println(name + "." + method + " returns " + e.getMessage());
& x, o# g1 H; d/ W  l      System.err.println("The process will be terminated.");( X1 K. K# ?. _3 i
      System.exit(1);
6 }0 v* T! |  M5 U+ p8 w8 e( c5 X      return null;
, G0 R; ~! |6 |' Y0 u" S! j7 Z- z    }
' k7 g3 H$ q9 t$ Z5 t; h( |    return sel;) \$ X% v7 o# ^( d# o: Y$ Y
  }# ]" a9 Y' l. {  j4 _

9 m7 c6 Q* C, C3 \  public static Selector getSelector(Object obj, String method) {. `# H6 {. K) {+ ^. D
    Selector sel;9 i5 l. W, I) F$ x' h& a
    try {
4 C# `: h; E/ j8 C7 ^+ U! ?      sel = new Selector(obj.getClass(), method, false);
  {# ]+ V  J5 ]+ E; Z. O/ k8 \2 P    } catch (Exception e) {  |2 v% F( J5 L8 C( O, t: a0 ]
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 g( O3 [' w& b( ^+ E
          + (obj.getClass()).getName() + ".");* W: V3 U1 @# h9 r4 R8 [
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 C8 w( i! u/ H. \7 \5 J      System.err.println("The process will be terminated.");
( {1 @8 C) D1 D7 c7 t0 y% d9 g      System.exit(1);
. f( u' p1 @# X' [& n# J      return null;
5 M# W. u' T  D9 F4 ~2 i$ ]8 O    }
7 d# A+ [2 u: Y    return sel;! ?. m8 s8 W1 x& Q* Z- p" z, H& f
  }
% Q7 X7 `4 w) X0 S/ U}

评分

参与人数 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-18 05:48 , Processed in 0.022635 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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