设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9033|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
$ y0 [6 R7 @2 I5 o  ]sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行1 g' i; `% n5 X% b& R: m" ~
+ M+ s6 V* r' G$ j0 `
似乎缺少了一个SwarmUtils的类,不知道怎么回事
4 w* w9 l  Y8 A
. y2 T  s0 x) ]朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
* F! U) Y5 s2 o9 I# @% h: g7 J7 O
public class SwarmUtils {
, L# f( X4 Q* b, j) z/ h) O  public static Selector getSelector(String name, String method) {
+ V  g! f0 F! b7 W- P1 _    Selector sel;) D  U  I) o2 f
    try {
+ t9 [9 S$ l- H- W      sel = new Selector(Class.forName(name), method, false);
, d  q2 W: S+ }1 b& Q    } catch (Exception e) {  h& O. D6 y" J# N3 N! j; @! [
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 t2 t$ y; E+ V0 P0 \
      System.err.println(name + "." + method + " returns " + e.getMessage());1 N( l9 l5 s! u& Y9 \- I/ y+ S
      System.err.println("The process will be terminated.");- O+ j% s/ D6 T3 `
      System.exit(1);
. H; J/ X' x; _3 B' B      return null;
' y7 u& G4 P7 m& |9 a, w# y) s" S    }, J8 O# d* I7 M4 S
    return sel;
$ }& _; [# B  v- x% K9 x0 {% K  }3 a* y5 r! n) M; K7 ]  E7 Z

  o( ~  O) i" S& r+ `4 e! z) o  public static Selector getSelector(Object obj, String method) {8 u8 z8 J3 h8 p0 e$ |9 r
    Selector sel;, i' M; B* p  t
    try {* [  ~9 [; P( L" f
      sel = new Selector(obj.getClass(), method, false);
* E  F. o7 ^2 P0 _* a. }    } catch (Exception e) {- i5 e9 F4 I& Y+ I$ b
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
  h: {, r5 G$ v* X          + (obj.getClass()).getName() + ".");. M7 q' ?8 L2 D( ?- V2 x
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());( d* o. E5 [! p$ }
      System.err.println("The process will be terminated.");2 O$ x' x& J$ N8 l* t3 O% A: b
      System.exit(1);+ X3 \% P6 s4 b- N3 b
      return null;
2 k+ t4 |2 U' Y0 L    }& }- Q* @! s/ _. E) B
    return sel;
; v  P% h1 x" R' l. a0 L* q: w  }- D1 e1 y. [) V9 E+ H+ _4 A- 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-3-3 10:37 , Processed in 0.028662 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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