设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9813|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
9 r/ L- a. F- c2 Bsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行; D$ p9 c1 N( \( Z( }+ X) ^& ]5 P& R8 h

& n8 A7 F, y, `1 F) s, M$ H/ K7 e似乎缺少了一个SwarmUtils的类,不知道怎么回事
1 e! ~" f% Z8 B% K& J
; e! v( j7 W1 `* V朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;; E  S: k( Y: K; J5 v5 o
0 Z; @/ d% Y: l  r+ _8 `& O
public class SwarmUtils {
$ M. O- N# `8 L6 z! Y+ j  public static Selector getSelector(String name, String method) {
6 M$ i  K- h) ~+ B, D6 c    Selector sel;
: |( R5 I6 Q4 `' C9 l3 z# g* j9 C    try {
( v0 n7 T% E  m/ T8 `2 G      sel = new Selector(Class.forName(name), method, false);) o5 J9 @* O) T" P$ I: l  T
    } catch (Exception e) {: @. J9 ^8 o; r; {$ h
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. J' Z( L( t6 R# f" ]9 b! r* o. N      System.err.println(name + "." + method + " returns " + e.getMessage());
( |- T4 S1 A# x      System.err.println("The process will be terminated.");
3 H. L2 f0 X# g) X! Q( r: ?* a      System.exit(1);
3 u- R  Q, [( }2 m- F" a      return null;
8 C) [' h& B8 Z2 s' d. c6 V  r    }4 v* M5 C1 I; k: r; B
    return sel;
4 I* u: i; j$ R# i3 B  }
4 r. W5 a) z4 _. l* x
1 ~1 ^' w( I- N* X. L3 [% \- x2 y  public static Selector getSelector(Object obj, String method) {
" J; N& r4 u: S2 l    Selector sel;# H4 }9 b/ d3 N8 }# x: ?7 D
    try {; P1 t7 X: ?) l- T
      sel = new Selector(obj.getClass(), method, false);, _; u+ O$ E. w: n% B$ ^3 o
    } catch (Exception e) {. V5 X3 Z* e/ M- O% P
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& Y- t' z4 \$ M
          + (obj.getClass()).getName() + ".");
# |2 I2 y) Y) t; [7 w      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());$ E- q5 D1 z- q
      System.err.println("The process will be terminated.");" U# e/ h4 L1 }+ }$ O( g
      System.exit(1);0 J  O3 I# I$ A" d! @2 k
      return null;
8 L# Q* w7 A. c7 P2 j    }
9 i1 V% l  y. u    return sel;
. s/ o. [+ N& K7 b' H  }
( |- g/ o9 l0 o4 k& ]}

评分

参与人数 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-6-10 20:48 , Processed in 0.016986 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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