设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8896|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行" W3 ^5 O& u& n1 R
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行- X4 f) I. r, _* l, q$ \; c4 K
7 Z% k6 X7 V3 _/ `/ C
似乎缺少了一个SwarmUtils的类,不知道怎么回事 " A( Y, W$ G! C2 }& s
! w* _! [) y$ K4 b7 e2 |
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
8 P1 @  G3 b$ C/ w- n1 }3 v2 ?$ g3 x4 n  I& ]; \1 s
public class SwarmUtils {4 f  x6 e# @) A% C& ]
  public static Selector getSelector(String name, String method) {+ U# m6 k/ W" A$ l* j' v
    Selector sel;
0 V% B3 S/ e  F$ p3 R: I1 j7 \    try {  L; [; K4 z4 F; {' V
      sel = new Selector(Class.forName(name), method, false);  t6 v( o4 g" r* A
    } catch (Exception e) {! L+ H  o) a. K+ V- F9 p* j
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");4 \4 x4 p: V+ G3 d& M/ f
      System.err.println(name + "." + method + " returns " + e.getMessage());) Q- @& T' ?; g+ c9 P& C" W
      System.err.println("The process will be terminated.");
' D% F/ p) T2 t( B. U      System.exit(1);3 W' _8 ^" c) L1 D$ p4 M& z
      return null;4 k$ _+ Y) H+ q; C/ a
    }5 g% ~8 w' y. i0 A4 O5 Q
    return sel;
/ C. L+ b) O. |  }1 `" i: G/ e7 U! l/ [  _8 f/ P

+ }7 X2 u% [( P% ~  g  public static Selector getSelector(Object obj, String method) {% e; c0 _, j+ A' q: Y
    Selector sel;
& K& Q( f# V6 w3 @- G5 a9 [! o    try {
" a. e/ ^0 \% k( s- R. s/ q      sel = new Selector(obj.getClass(), method, false);9 ^" _/ m# L3 y* G# ?- N! m
    } catch (Exception e) {3 ]+ s% K# G; y0 h
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 i2 [/ Z' @" t1 F' U          + (obj.getClass()).getName() + ".");
( `6 c+ `" w! @  L, W      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());$ a0 t0 U6 d8 p' U# h9 `
      System.err.println("The process will be terminated.");
- y) e. y0 t0 Q      System.exit(1);7 n! I$ L  D6 {0 q; Q$ Z6 }
      return null;
" {: w/ \0 w  I% a. f/ c    }  f3 O" w' w& g  e! l2 U( ]
    return sel;$ W. P# ~, u+ g2 G4 Z; N
  }
0 M" o$ j0 Y9 H}

评分

参与人数 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-2-8 18:33 , Processed in 0.020256 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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