设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9885|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
) X. u: R" ?  S( q5 Osel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
/ l) N/ a. o/ ~) X9 s, x- b+ |
似乎缺少了一个SwarmUtils的类,不知道怎么回事
0 e6 ?2 Q* d; [7 {' z) i- s; t7 U" q# Y3 j/ S7 t9 Q
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
" c( m' J0 ^$ r  H& g2 A  [" l: Q6 ~
public class SwarmUtils {
) b; A% }) k6 H6 n% w" {/ q  public static Selector getSelector(String name, String method) {
7 p# v) ^0 m% E# o0 E9 l    Selector sel;
( |! g  |4 N, ~0 |1 K+ |- x    try {1 b0 s3 o0 T% W; c+ g5 g
      sel = new Selector(Class.forName(name), method, false);) }3 F2 K+ U: G: W# r
    } catch (Exception e) {6 @" y+ k3 R, i! B# U/ D0 a
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
( O8 l7 _/ ~& ?! H( b% v4 H) ?      System.err.println(name + "." + method + " returns " + e.getMessage());
4 i( E0 u. \& ^1 U7 q6 k      System.err.println("The process will be terminated.");8 @: B7 @0 E, v7 Q  p0 [1 t
      System.exit(1);. h- c4 i1 |. D6 Q! q
      return null;
1 @" j( ?1 G0 {+ a    }
1 F& X! c* X# f- j- r. m    return sel;
% Q$ V& N; K. Q# |/ x. K& r7 F  }
4 t( d% f: E4 [' n/ ?- x, n. w0 W- f4 n" ?# O) [) y6 n
  public static Selector getSelector(Object obj, String method) {
* u+ U. v/ ^( {: e1 ?% c& U    Selector sel;
; v. K2 P8 Q9 N3 E( X    try {% |' @2 R4 `# n3 ]9 A; a( w8 ?: x7 ~& n  O
      sel = new Selector(obj.getClass(), method, false);
* ?  w' u2 ^& {6 D    } catch (Exception e) {* `5 I/ d8 o& a2 {. Q0 G
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 r1 S( V  Y7 C* }% ]4 P+ T# V4 a
          + (obj.getClass()).getName() + ".");
) E6 O* f; @$ J9 w, a. W9 V6 t      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 Y( j3 u/ O% X$ Z8 w+ \
      System.err.println("The process will be terminated.");
9 O" o! u+ ?0 t$ F& y1 ^      System.exit(1);0 i/ a1 y& D# {$ K: b) F
      return null;
+ P* [3 _% e7 E8 v% A0 S4 t6 \    }1 v$ `/ G8 L9 N" c: A
    return sel;' O+ h( w6 o( {' f! s
  }
6 J* g* M- z, L$ g- l}

评分

参与人数 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-6-21 03:01 , Processed in 0.016187 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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