设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9740|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
5 G; b- @, Q; Asel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行) O( `" C/ Q8 l/ b! y

; ?" f6 B) Z3 x( Q2 h+ G似乎缺少了一个SwarmUtils的类,不知道怎么回事 3 E! w/ E' V' z& l) }

; Y% k( y: f3 j9 K4 G3 K朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;6 `9 c8 n" o* G
. B' b0 F2 N5 ~& u; t% c$ W8 l7 D
public class SwarmUtils {' F! j* T3 G. G) E  S! `
  public static Selector getSelector(String name, String method) {
. k! y0 M& H& j; {. e0 E- p    Selector sel;& F% J! D7 u- H7 k& |% V
    try {
# ]& H# \5 r9 j      sel = new Selector(Class.forName(name), method, false);1 ]" Z& m! r. B6 N3 x
    } catch (Exception e) {
# K# [* w+ d; S0 k0 o" J# o: [      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ k& g2 j7 a2 G5 r      System.err.println(name + "." + method + " returns " + e.getMessage());
+ a4 n# j# V: A! |      System.err.println("The process will be terminated.");
( p% p( G7 m9 H# R- y      System.exit(1);
( A2 v% k. F, M! C      return null;
, L" y) Z9 R$ Q  f: q/ U    }- o2 `$ Z. L: ^9 m& S9 i  F
    return sel;
, @3 _- i( [% T& s6 C  }* {2 P% P3 _7 E

% p" B/ C4 S5 p9 m9 L  public static Selector getSelector(Object obj, String method) {
' X) k2 F( I2 a. u* b    Selector sel;2 {/ U( K; {. i( u" d5 e
    try {
, ?: Y1 k5 m6 ^8 U$ p1 O      sel = new Selector(obj.getClass(), method, false);9 g: T7 k/ \  m% U
    } catch (Exception e) {. F$ _" Y& \5 u# z7 g
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
. }" r1 J0 L& Y          + (obj.getClass()).getName() + ".");! G7 G/ c+ W8 W' a$ Y8 c- J0 B
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, G% _2 S  |; A* [      System.err.println("The process will be terminated.");& e) J  k0 S* I% |5 j. h
      System.exit(1);
! M4 c7 O0 _* A& E: X      return null;
; i, R& H5 g( X! z    }
+ ^+ C( D9 S7 a; G    return sel;' |# F8 M; I! V1 r) U* g% k6 [
  }
% R$ ]2 r3 r0 n% S- 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-6-2 02:25 , Processed in 0.016359 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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