设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10564|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行4 H3 Z. F/ t* G4 q4 v
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行( \! z1 K9 p& j4 `( |4 K* w9 S& g
0 Q( p* [( L! o8 ?5 w! k3 G
似乎缺少了一个SwarmUtils的类,不知道怎么回事
8 f; V0 |% O- y+ }7 l! I7 t) C2 W9 t* T6 z( a5 E9 _
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
3 i& k! ?! N" P: z* Q5 X1 x, Z5 o& x) Z. ?0 x
public class SwarmUtils {. V7 z: B0 y8 C& t: y8 @3 m
  public static Selector getSelector(String name, String method) {
0 e" ?2 L8 l; `0 K% A    Selector sel;8 I: [% X  y$ h  }, I
    try {5 p5 ~1 g* j9 V1 @7 q! p5 }
      sel = new Selector(Class.forName(name), method, false);
( x2 }2 W9 \& b4 I' p    } catch (Exception e) {
, s8 m7 S$ K1 h/ \$ c      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# C# p7 P  F4 U4 ]      System.err.println(name + "." + method + " returns " + e.getMessage());4 |7 E  {) H7 i8 l7 }( U
      System.err.println("The process will be terminated.");8 f! S% S3 v' e+ G9 u; N
      System.exit(1);
  G" ]% ~1 i. _- Y" r      return null;7 W3 @8 x4 M+ k3 l7 t& [" Z7 z% I
    }
( p2 p# j8 g9 [$ Y- R7 c    return sel;
1 T# _1 J3 H$ x; P  }2 x; H8 [, `) B" {

9 w; o/ N- Y# Q6 f% O- r  public static Selector getSelector(Object obj, String method) {
9 Y& r0 ]0 n5 ^) `- l) u. s" [    Selector sel;
, G2 E8 N9 e/ k6 c. f    try {
) ^" u& {0 y! {1 E$ _, j      sel = new Selector(obj.getClass(), method, false);
- {; [0 f+ f1 a# w0 z. @    } catch (Exception e) {4 r' D. B5 S3 N
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "" i" Z8 d( ?3 W8 {2 |8 v
          + (obj.getClass()).getName() + ".");
; B4 H) R3 b$ G1 }, _* j: G      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());2 `; @! R1 u* ~- R$ g, o
      System.err.println("The process will be terminated.");+ E7 r8 m; }3 a+ p7 H  \0 x: }
      System.exit(1);! ^4 {! c$ e) e! R  a6 A' U
      return null;
) q& G6 o  R- F4 z, t$ P. g    }
& r% d0 ?1 C4 k) _    return sel;
% p4 j" j( A$ |' \5 [, A  }
- q  O( x# x; ?  i}

评分

参与人数 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-9-3 16:26 , Processed in 0.017049 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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