设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8940|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行( c: z5 T" f8 f( v* A
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
% x' J- R: k9 X! a! t
# _2 v: q: |7 @9 t5 ]+ n似乎缺少了一个SwarmUtils的类,不知道怎么回事 8 [! H9 j" a4 |

: R3 H/ I9 Y0 y1 Z2 l( x& ^0 W  y朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;8 U- A! l6 {- N; g  l
/ o8 v* K" I' L6 _  S4 V) ^! G: C
public class SwarmUtils {! ]! R: i6 Y/ A7 x4 v
  public static Selector getSelector(String name, String method) {+ P- V  J+ x+ k& q/ X( J3 G
    Selector sel;; U( u3 @3 l! v' e+ Z' c- J) W/ n
    try {
- O; U* Q, W, ~      sel = new Selector(Class.forName(name), method, false);
, V$ n# }4 I2 |7 V0 D( w    } catch (Exception e) {
7 k" Q2 n* k5 H8 T( B; Q- k      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; y* }9 T! M1 F" p5 x7 `      System.err.println(name + "." + method + " returns " + e.getMessage());0 w* t! V3 |: w# {( f
      System.err.println("The process will be terminated.");
% q' G+ B" _& Q; J$ K+ J      System.exit(1);4 m0 m; d3 g3 ^' A
      return null;& K/ X" A+ F% c1 W8 ?+ k1 e3 h
    }
  z' F9 b3 ?2 d- N9 M    return sel;, {/ r0 V+ f+ ]0 m5 Z
  }' z7 \8 w, L7 a+ _9 S- a
( m: m" ~5 m  t" }# E
  public static Selector getSelector(Object obj, String method) {
. _+ I% h9 Q+ p0 Y. }    Selector sel;
9 u7 e" ?9 o' ?7 [0 O& C: |    try {
( g" o* s5 M  l7 C2 |      sel = new Selector(obj.getClass(), method, false);; D( K! O$ L. t: d7 r$ x# m
    } catch (Exception e) {& X" x* }" e* ?' W/ k6 n
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ Y, ?7 A! U6 ?2 e& t, w" N5 d8 [
          + (obj.getClass()).getName() + ".");
7 }: e8 v* S2 J4 F7 [$ b6 B      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
0 Q& Y. K2 ^/ F# R4 v7 j      System.err.println("The process will be terminated.");; y. @+ c) c- [1 H# H& h
      System.exit(1);
' ^' P! u8 D( `      return null;
: ?6 ^+ s1 O, J# I) k    }2 k8 I) E$ a/ R+ ~9 p
    return sel;9 X+ z" H! D; X; }6 k1 i; g
  }5 @6 o. `) ]8 g& j, A5 L
}

评分

参与人数 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-14 01:26 , Processed in 0.019144 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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