设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8760|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
% w( E) _- C& H2 U% m7 v% Xsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行4 e, ?8 j) G7 u; F: p3 x

+ N2 S2 A" I1 m/ B0 q( q似乎缺少了一个SwarmUtils的类,不知道怎么回事
$ l0 D. S9 T1 o; n8 @4 _$ s% T! X" c2 ?3 `8 i- o4 `
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;7 L! s7 i2 g8 @$ ^+ ^/ h

, e% w9 V( S& Lpublic class SwarmUtils {3 G9 c5 O$ D9 [  `
  public static Selector getSelector(String name, String method) {
  u4 u( r6 r; d/ V4 ^7 H7 S: K3 Z    Selector sel;3 L7 X: L; h7 p# H
    try {
8 K  d( j) v' I% @6 V      sel = new Selector(Class.forName(name), method, false);
( ~8 W& @3 v8 i5 \$ x    } catch (Exception e) {1 z4 x& k: g! e$ t
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 g% b( I( }3 R! b- k5 c* u8 [
      System.err.println(name + "." + method + " returns " + e.getMessage());  ?! d! y! m4 f* z0 t. D
      System.err.println("The process will be terminated.");
' c, p( F) S1 N      System.exit(1);0 I6 j$ \( S, _& F1 v
      return null;& G2 e; J/ O! q: O) r5 M) T
    }% ^# T; N' }( V0 m& P% Q% `, L! e
    return sel;& P# _% R" \. u1 {' v9 Q5 e
  }' P2 O7 i  T, R+ t: }

" I% a9 M; K# \& H7 a5 h5 `  public static Selector getSelector(Object obj, String method) {) T7 s7 Q  r' S
    Selector sel;
: K( T" h: N4 h9 H    try {! h: ?5 t: l' @2 A, h5 W3 J
      sel = new Selector(obj.getClass(), method, false);" I$ j* i: |0 D" c' T3 C6 q
    } catch (Exception e) {% r  v* B4 O: T8 m5 D8 j
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
4 c" e  W0 I& ~) D; V  Y          + (obj.getClass()).getName() + ".");+ P* n" B9 a" Y+ `$ y  c
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 z7 E% J& S1 n
      System.err.println("The process will be terminated.");
) Q8 t, P$ ]2 i- y4 o& T( z      System.exit(1);
1 J7 d  i( G1 E. ^& |7 D      return null;  s& T, M/ q" A4 O3 A
    }; B% M6 c% g/ F' z2 G* N$ f4 A
    return sel;* j3 q+ R. t8 H; I
  }
" J5 ]6 p0 }* Z: A}

评分

参与人数 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-1-23 11:19 , Processed in 0.021730 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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