设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9730|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
0 Z% Q, v% R7 A0 [! Nsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
; O3 x0 y) O, h* p+ E' R
# |7 U3 g8 A* G' m2 J5 x9 N! P似乎缺少了一个SwarmUtils的类,不知道怎么回事 0 [' D% t* E7 Y4 U
8 \9 N) G+ ?0 |- P+ y+ X
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
* z' r0 _, P% E  c2 E% h' h$ {  U
6 {# f! _# _' r2 D9 T9 ?2 `public class SwarmUtils {
( Q) J0 a5 a5 y  public static Selector getSelector(String name, String method) {
6 e! j! y7 u/ o, I    Selector sel;
: G5 b0 Y: c5 W5 d    try {
: _0 e. {9 V( D1 Z0 @) P1 f! G6 ?5 v      sel = new Selector(Class.forName(name), method, false);3 E5 n0 |3 g$ M) l
    } catch (Exception e) {
. O0 X  _- {7 p5 Z' w' C4 ^! o  X      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");3 I- ]. T  Z5 L9 D, e2 u
      System.err.println(name + "." + method + " returns " + e.getMessage());
% H/ O  D8 J) N9 z! z: ^3 y      System.err.println("The process will be terminated.");8 R7 l7 }& H' L( x  x  w
      System.exit(1);
) n" Y* W* F  ~5 z( _4 h7 k5 u' b      return null;: K: Q2 p" H. k3 t+ v1 j
    }
; i/ _+ n, \4 G1 g    return sel;
0 ?& m  E+ J+ r1 I: Q  }3 O+ C% M( H' N

/ Q& o8 W) R/ P: I  public static Selector getSelector(Object obj, String method) {5 e+ s0 L- c1 v/ j0 d
    Selector sel;# t3 Z( Q9 d: j/ ~4 O, J
    try {- A* e% u/ R. e9 e
      sel = new Selector(obj.getClass(), method, false);& q8 l8 w* D* S; h7 ]) L" j
    } catch (Exception e) {
% E* W( h/ ]  i& n4 X2 ^  _      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) h2 C' H+ Q! p% @$ E          + (obj.getClass()).getName() + ".");
- O; Q: Z  m7 R& j, c9 j( F0 T      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());/ I* P& F; t2 G6 G% b3 L' q
      System.err.println("The process will be terminated.");
7 j6 N+ {3 @8 {0 s      System.exit(1);
" Y4 P5 s, H& j: y8 E  N! s      return null;& b5 J( s! D3 K; G+ i& l3 C+ O  n
    }
* c1 T+ h. P# E    return sel;
; n) D% g$ W& J# R  }
' ?- ]7 `) P! y1 R  d0 ]$ J}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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