设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9901|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
) C6 ~2 i1 |% Csel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
( Y  T6 `: ]9 N: _! {, }
0 n6 G; e: W% e$ I( h似乎缺少了一个SwarmUtils的类,不知道怎么回事
+ T7 Y2 u) G  f+ d( G+ E
. v7 a, O& n! k/ c/ w* T7 k朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
1 j3 H! b8 P# F: A8 W+ d' a3 z" q' w
public class SwarmUtils {  a+ d, M  g) a5 \5 z; n
  public static Selector getSelector(String name, String method) {
# ~6 X6 R8 A  C( S+ r    Selector sel;
  G5 b# l" a9 e6 Z5 }! q7 z    try {- t6 n# |' }" a% i2 g
      sel = new Selector(Class.forName(name), method, false);
2 }  N4 H  {3 e5 y" z; ?    } catch (Exception e) {# m2 Q, g, L& I( ~* d9 p! l5 H: r+ ]0 J
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
5 A# S( F/ i" J6 n: L      System.err.println(name + "." + method + " returns " + e.getMessage());& _7 Q7 Q6 a' F+ j" e8 N) [
      System.err.println("The process will be terminated.");
% F- N  Z0 ^/ p. T) |2 K% F; Y# p: X      System.exit(1);  ?9 P  b# K3 p. w3 w0 Y
      return null;% [6 z  y* n6 w1 T1 ~7 e8 k! M
    }
7 n( i, L) W3 E3 K1 d2 z    return sel;" d( J& \% ]! z5 j) w( |
  }4 L, r( X( m8 ~

: [- }5 s! |+ K. m  public static Selector getSelector(Object obj, String method) {
% t! y- H! b* M" D3 L- g$ V    Selector sel;6 x3 _8 [5 a. ^- B
    try {3 K+ O. l  N8 w
      sel = new Selector(obj.getClass(), method, false);
3 n  n* F" i: w5 {7 D    } catch (Exception e) {$ v" S% K) H! g9 [1 g. J
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 e% P2 ], l. M% v' Y, r
          + (obj.getClass()).getName() + ".");
  U+ q+ ?* I3 I- `! Y9 A% B. |      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
; F) ]6 W; n$ w      System.err.println("The process will be terminated.");+ T4 {. ^# g% o7 m4 Z
      System.exit(1);& G) L% E' a" ^! N5 z
      return null;" }: u) j3 N2 r" y& V
    }( q0 G) t# T. X5 e+ K& a' @
    return sel;3 _5 t3 D  @% c/ |
  }
6 M' n. y: Q4 w4 o}

评分

参与人数 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-23 23:49 , Processed in 1.337218 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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