设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9544|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
& |! @& \7 e) vsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
1 _+ t3 `$ j4 P* I0 Z5 s4 e, f. l8 T  _( p) I+ V' E$ X6 r7 j0 j
似乎缺少了一个SwarmUtils的类,不知道怎么回事
+ E  ^  e1 e5 i# C
  u! z$ |6 O0 U' J, S! i5 C朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
$ \* h" z7 r( E$ }
3 Y" M3 ?& w, \! Wpublic class SwarmUtils {$ g8 w% F; g; @2 X8 e$ L
  public static Selector getSelector(String name, String method) {; R" z0 k+ P" j- q: ~
    Selector sel;
5 J0 u) E# E4 s$ x5 ~    try {
; U& U/ g- ^# g5 N      sel = new Selector(Class.forName(name), method, false);) `8 a+ j" c; [
    } catch (Exception e) {
6 Z4 o0 m/ w; k  S  o% \      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");3 K/ g6 m3 |- A1 Z3 h/ _
      System.err.println(name + "." + method + " returns " + e.getMessage());. l- F' R- o" I
      System.err.println("The process will be terminated.");* ?: Z; j7 }2 R3 \
      System.exit(1);
2 y2 d3 f7 F# h, {, e0 y! l- ?& @      return null;5 w# ^/ }$ G+ t/ [7 H* N
    }- Q+ E9 O! b: Z+ ]" g) h
    return sel;
7 U' Y2 B% |( c0 E5 l  }
7 a3 ], y" g% o. C6 f7 w1 J. z0 l8 z2 p! e  F2 {( f" @7 Z1 f9 H
  public static Selector getSelector(Object obj, String method) {0 A7 f/ N. e: Z
    Selector sel;
2 B, s& m) n- c. _0 L1 B% L4 n    try {9 i+ C% ^- k! R( y" E. C
      sel = new Selector(obj.getClass(), method, false);
1 l. q) B# |% W6 m    } catch (Exception e) {4 w* l( D1 e  O, P
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 v: ?3 P6 W; ^- |          + (obj.getClass()).getName() + ".");
3 q3 e2 |6 Y6 ^! j' O& Z6 P; F      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 k0 b' j+ {0 I0 X, ~8 x- z
      System.err.println("The process will be terminated.");
3 S: O% O6 `' v5 |! W* y      System.exit(1);  p  J; v! @: p" Y
      return null;0 y7 v4 S* @8 w# i  j
    }
( \/ D  V/ q+ U4 e    return sel;. y2 _, ^  _6 ^# e/ [& C
  }9 o: B' {  q7 L2 J3 D1 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-5-6 15:38 , Processed in 0.014612 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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