设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9848|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行" l9 e# E) C7 W) _; u
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行+ X# H8 x. P$ B# H- g# N8 }+ U
" q# G- ~8 x9 }5 l$ V* W
似乎缺少了一个SwarmUtils的类,不知道怎么回事
. O! M$ F- @7 Z
! m/ {) X, J3 \7 S% I朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;1 Q* f0 u- B' \- n' K
- t- m6 p7 S" W* V2 V4 f& P  Y8 ^
public class SwarmUtils {8 Y+ j* n# a  p" ]
  public static Selector getSelector(String name, String method) {# Y8 ~) A" C5 }# D+ C+ l( ]* J
    Selector sel;
" \# L, G3 H- ^    try {
+ L/ X5 T3 t( K) W      sel = new Selector(Class.forName(name), method, false);9 V: ^* H7 y/ ~& B$ n
    } catch (Exception e) {
# c' F2 j0 @' ^0 f7 m8 E4 A      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");6 x. \, v+ I. Q) g# C2 d
      System.err.println(name + "." + method + " returns " + e.getMessage());$ Z  I6 j  O+ W$ n7 C- ]
      System.err.println("The process will be terminated.");
$ z9 |" s/ s; d' V. A. O& l      System.exit(1);, V, O7 D% ^7 ]
      return null;
& H4 M& i. V/ n( }7 G    }3 X9 R/ Z1 n7 w$ R1 j
    return sel;1 T7 [% r3 V0 g4 w
  }
! b, w, {: ]% C" Y# ^4 W
7 c/ a# g: Y1 l- D# N% h  public static Selector getSelector(Object obj, String method) {. O& @! F3 q. D' n6 b
    Selector sel;
. y1 g) E/ P" C7 Q2 b5 H2 r! ?& `    try {- T9 a/ K1 _2 _9 B) N
      sel = new Selector(obj.getClass(), method, false);/ ?: l: X0 Z' |4 ]! Y
    } catch (Exception e) {
: d7 o8 I+ [/ S; ~, r  H1 g      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& Z6 o1 M; E" S" ]/ w! j          + (obj.getClass()).getName() + ".");
4 r& \; k2 ^+ L2 G" {% C      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( v3 P/ f1 b- g& i      System.err.println("The process will be terminated.");
+ X4 G9 A* N2 T1 v7 z" \6 J      System.exit(1);
" N, `& |  ?6 }8 Q: G      return null;; U; a5 j. H  _6 m
    }& Y2 f& A# A9 Q& M9 U
    return sel;4 A0 J+ x- ^/ V" r0 c9 |
  }
& ?" w4 }2 ^3 ?! }, e! 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-15 12:12 , Processed in 0.013994 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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