设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9916|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
2 i* {; ^& K- n7 }0 S2 Ssel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行/ v. h4 V1 w6 U7 {4 b# A

3 g; F' ^. y# L0 P似乎缺少了一个SwarmUtils的类,不知道怎么回事 , [( C/ [- o; A* ^# J  V
4 R/ W. V1 V6 ~2 R+ W. R' ~
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
$ x( `' T2 N6 M5 E* m6 _4 L5 N6 H. |0 F5 \, D
public class SwarmUtils {9 u8 H) {) i9 l. Y
  public static Selector getSelector(String name, String method) {1 i0 Y6 W6 p: q9 R$ f- E. r
    Selector sel;
. A) e* e9 ]; v6 ?& g- g    try {. E. i% @7 W# q( \
      sel = new Selector(Class.forName(name), method, false);
9 F, \! M2 {  B    } catch (Exception e) {& R4 ^' F( K( R* J3 Y( F7 k" U
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
( W6 U0 X  Y+ O9 [      System.err.println(name + "." + method + " returns " + e.getMessage());
  r; Z  S+ m: c0 b1 M* l% a      System.err.println("The process will be terminated.");6 r; x5 E$ o9 C
      System.exit(1);" M1 c3 _2 d! Y: t" D$ E, w
      return null;# a# X# D! a1 J) X" {
    }
, k/ d$ G  @* V) ]! O    return sel;. m9 F( f, V6 `# F5 A: Y# d2 N
  }
: p( n# R1 R5 O# H& ~) R8 [: z1 Y' v. q2 v
  public static Selector getSelector(Object obj, String method) {
& L; d/ B/ {8 Z( o    Selector sel;* A/ x3 [  w9 d; [4 p* Q5 H
    try {2 u! K, N& B& k  E$ w- M: u% C* Z
      sel = new Selector(obj.getClass(), method, false);
8 R) u* l  p% Y4 V9 E* @    } catch (Exception e) {" ^/ k6 r/ e6 e, x: H
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' f7 i& b$ T1 B0 |: v
          + (obj.getClass()).getName() + ".");9 y+ {0 I/ d+ l5 E4 U
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% _9 @6 N3 ]3 x: l, c3 i1 J      System.err.println("The process will be terminated.");% g6 i! E2 t# a
      System.exit(1);- G, V" Y$ f( M' p& |
      return null;/ l# P5 x6 J2 R
    }
/ u6 G* E# @+ \7 s( a9 w- \    return sel;
/ m; G$ b; Z- C! x/ l  }  L) P/ y! }( O; c, y! n! Z
}

评分

参与人数 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-25 16:50 , Processed in 0.019531 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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