设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9126|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行& m2 |+ E% `5 h- b7 X
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行/ `- s% ~7 R& `7 ]/ D

- l. ~! s! m7 s似乎缺少了一个SwarmUtils的类,不知道怎么回事
! w# o% Q& m7 ~  W2 L: {; s
! r0 ?" X& [; i0 u8 p6 ]朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
- g5 u' V/ [; H( A8 R( H: C6 s. i: F# L% O' h6 p) T2 X8 z
public class SwarmUtils {
8 ^* l2 d% \1 U1 z7 x; s: G' q  public static Selector getSelector(String name, String method) {" \, |4 a" ^2 e+ Q4 z5 N8 z4 C
    Selector sel;
( x( ]. b, u0 b9 A& \    try {
; D) q% r, u4 B1 h9 l8 t) R      sel = new Selector(Class.forName(name), method, false);% @( I5 P/ p% @. h
    } catch (Exception e) {
& f% d# v7 X+ v4 f+ F+ G% D; [      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");' ]4 z9 N) y1 _( V) |2 t, I
      System.err.println(name + "." + method + " returns " + e.getMessage());
3 e! s  R/ v9 h) a* X) S      System.err.println("The process will be terminated.");0 s7 Z+ Q7 C7 p/ K1 ^
      System.exit(1);" d* n! i' j8 k, m! m" }0 u
      return null;
) `, O. s6 F" t    }
  A% F) [% o) I- M! x9 q    return sel;
& c6 X  M# V- A0 ?) R  }$ e5 l( U/ _- n, `& O
+ @6 {5 c( x- `: S
  public static Selector getSelector(Object obj, String method) {* W: b$ }! l1 @0 a. Z4 N
    Selector sel;. @8 h* B( Y( |( |) n7 x/ r
    try {  K  y7 H6 e: Z
      sel = new Selector(obj.getClass(), method, false);
3 a) M. E* M6 Z, V4 h& U    } catch (Exception e) {
. w9 k( m+ v& Y$ y  D: f. x% B- T      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 ?& J9 F" Z; @2 q          + (obj.getClass()).getName() + ".");
  g) v! N) m+ f' b4 s0 m6 A      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
. C8 T9 c+ |" i+ I" ]2 H1 I& e9 @      System.err.println("The process will be terminated.");
+ n! Z' \: d% {% f# B$ O! _      System.exit(1);
( L) l% H  D5 D* f8 E      return null;( v" P% P5 I. z1 b3 D$ K
    }
" w, e, g7 R! F: X' V. G5 _    return sel;+ W1 [% I, E# V! y+ U% k( w
  }
; R* v$ U( q4 ^+ x; X' Q}

评分

参与人数 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-19 04:08 , Processed in 0.020543 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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