设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7891|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行* J& U  f  V8 [+ c( c1 Y
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
% y1 p( q: c6 m# v  c
! _/ h' G  b( M5 @/ w6 H) ]  h+ Q( n似乎缺少了一个SwarmUtils的类,不知道怎么回事 ; n) e2 d/ @. ?: Y' z2 ?' a3 V: @

* q0 N% B3 W, [2 F朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;: U! y/ ^' q# n- y* B
) i% k+ o! ]1 W7 L2 J( W, w
public class SwarmUtils {: v9 t" ?- ]0 j0 [# Y
  public static Selector getSelector(String name, String method) {$ i& q! L" F! h* f
    Selector sel;, M+ E1 Y) i" N  o" X" U9 |4 k  D
    try {
2 j3 D% i7 _0 ^" c8 V- Q: X+ X2 E      sel = new Selector(Class.forName(name), method, false);
" G9 F0 U& h0 y    } catch (Exception e) {9 e2 o" m" T) r, z' \% v
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# q  f; Y+ G2 ]' |      System.err.println(name + "." + method + " returns " + e.getMessage());4 I1 }) n' I$ E2 e$ A/ I
      System.err.println("The process will be terminated.");
& F$ A" }: r& w8 r0 U) n, j      System.exit(1);
8 S' A. L' i( ]      return null;
5 o. o: {, t+ b3 H# y; a    }7 X+ U) H/ N" N) k. |+ Z: \; [+ I+ p0 _
    return sel;
- ^5 I* m+ q  k, b  }
7 q) H2 h% y# ~7 n4 T6 n  h4 Y3 l" l
  public static Selector getSelector(Object obj, String method) {
3 D. U2 V+ x6 b, S    Selector sel;1 ~  m5 y# T. Q. N1 K4 T" v0 X
    try {& I2 E& `' `, [9 j& W
      sel = new Selector(obj.getClass(), method, false);
: Z" D2 G* t3 r. x# D    } catch (Exception e) {, @9 a: T  E5 V/ M0 \
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' c5 U4 |9 M' m' S9 {
          + (obj.getClass()).getName() + ".");  b' o! A, q9 I4 {  m
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());6 h: K# y6 F; v+ T. g. [
      System.err.println("The process will be terminated.");
1 N4 G/ F5 T# w) J3 s# h- C6 O" R      System.exit(1);7 {2 f% [, R6 N* \7 N. O( n- L
      return null;3 M5 D  x/ O5 w/ H. v3 z- A1 O
    }
, X+ }. o" t% q% ^. j2 j    return sel;
% i1 V2 `7 s/ k9 |) a& _$ e5 s  }# {5 T- S) j! p( [4 D
}

评分

参与人数 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, 2025-8-17 23:00 , Processed in 0.015166 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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