设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9737|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行5 N5 Z$ s. f2 K+ w
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
( |/ _2 \  m" z3 E) e5 z' k. B. x
5 X4 |  R% \  A似乎缺少了一个SwarmUtils的类,不知道怎么回事
  C; W; D# a9 a) B4 \, l
5 {# C& P: u4 ?! K( T朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;% y3 s0 t. r4 b6 r. ]  Q

, l7 m  n+ i4 h- J* S+ B* N' m- jpublic class SwarmUtils {
; @% B- p& Q) f1 r  public static Selector getSelector(String name, String method) {
5 k/ o! T9 K. K' F5 |5 v6 }    Selector sel;* b) \, j- z5 Y* w
    try {6 @1 L0 g- t0 h# z
      sel = new Selector(Class.forName(name), method, false);
+ i3 O+ S3 P" Z! C+ e+ G+ B    } catch (Exception e) {
, J5 [  j& g$ u      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 a2 t7 I' T8 X
      System.err.println(name + "." + method + " returns " + e.getMessage());+ a5 J6 o0 F& H* {7 V
      System.err.println("The process will be terminated.");
0 M5 J6 B! n( W  D4 h$ z      System.exit(1);
, D4 \" X3 l& t8 i) z% Q) S) c9 F      return null;
9 w" S$ U/ X* ?4 e' n1 h" F2 G: R" w    }4 e* `0 J2 Q$ w5 d# \% r
    return sel;  u  l1 w7 e# e* [' [! j  h
  }
7 B  z6 `2 G) W- Z$ T2 B
8 [3 i$ v8 k7 x2 C. \# ^  public static Selector getSelector(Object obj, String method) {! q+ @- ^+ K& S8 y
    Selector sel;
, y% b& _" `6 \% v/ i: o4 @    try {
6 M$ d' I( e4 V      sel = new Selector(obj.getClass(), method, false);' t1 J# S2 y8 R- H
    } catch (Exception e) {
& W. a+ {  D* _+ y6 {' Q      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "2 X6 F0 X  ^4 M9 h6 O
          + (obj.getClass()).getName() + ".");& b( {: O/ k# m  U
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* C: V6 u2 m0 g7 d5 p
      System.err.println("The process will be terminated.");
( M9 C$ j* r/ g3 y7 F$ c      System.exit(1);
) W+ f4 T- s) P/ [- N      return null;
+ N. c2 b' Z0 q. i2 n    }
& K  r6 }- P. N0 I    return sel;
% d4 `' t+ ^9 X7 p. Q$ `) _& @  }0 W; m3 H) `. n3 j* i
}

评分

参与人数 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-1 20:15 , Processed in 0.015021 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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