设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9587|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行. c9 t* f7 H/ @& ?9 t  p7 t
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
2 O0 }5 E2 U9 Y3 u2 P8 t% S6 i/ }( P4 B& Z. L* R
似乎缺少了一个SwarmUtils的类,不知道怎么回事 5 \  d3 E7 `: H. X; o" o) i4 R

. m! b! ^1 Z6 M, k; _, }朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;0 \" W$ V+ ^2 s' i: p0 j  u

' x( @2 ?4 M; y7 J- N( Bpublic class SwarmUtils {
6 i+ d$ |) m9 l% o  public static Selector getSelector(String name, String method) {
  X  ]5 P' i: i: Y( [# A) Z    Selector sel;
8 G6 E) }) R# V    try {
- _4 `) L: n  V; `4 d7 K      sel = new Selector(Class.forName(name), method, false);
/ l# P7 a) ]9 G5 S    } catch (Exception e) {9 t8 D! t6 J5 s& ~) O
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 c. t: R  h3 u1 T
      System.err.println(name + "." + method + " returns " + e.getMessage());
& M/ b8 f' G- k7 l( U      System.err.println("The process will be terminated.");' j1 L0 D& x7 ~6 m8 T' L
      System.exit(1);
" B5 _! G$ M2 q. m6 M/ r      return null;
: q& O0 `5 @5 c+ M: `' A    }
. q6 a: R, N4 c4 |* z    return sel;- K2 s4 O9 F2 s
  }
( W9 e: ?/ S, X& `9 x& J! `3 T, u& i+ Q
  public static Selector getSelector(Object obj, String method) {8 {4 Q2 t) _' {, _; v1 L
    Selector sel;
5 F2 a8 h+ z3 y" H. f    try {& o; w! l+ F$ T/ v
      sel = new Selector(obj.getClass(), method, false);
( H6 \4 g# C( @; H/ v5 o    } catch (Exception e) {
9 S% n# X, K; c) i/ v      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ": B8 q5 z: |$ z! U" T" g
          + (obj.getClass()).getName() + ".");1 N! `& t/ o: x' O
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
/ j  f. X+ Q2 z0 `9 u      System.err.println("The process will be terminated.");
' O2 ~* q5 J. u$ ^# `; G2 `      System.exit(1);
# F) k; S* m4 E. Y8 K" S      return null;
# l" |! ^% R0 g& o+ C" K0 C  Q5 r" O. t    }. @% ?3 o. v$ e5 ~
    return sel;
3 e) K2 L8 n. J' v  }
! ~* j$ z! P7 ^6 y  a. M8 m}

评分

参与人数 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-5-10 15:38 , Processed in 0.016625 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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