设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9750|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
' N; ~7 O7 k9 X) |, ]' n" |sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行6 W7 o2 v6 O0 k* k, j6 ~6 `
7 _) j, z% |4 y& z
似乎缺少了一个SwarmUtils的类,不知道怎么回事 4 g, o, C) @1 F' S8 Q; a

9 K. `! j$ _7 P# @, h) g- v. y朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;& ?  E8 e9 P) O% R! J

% m0 W5 |. |& C" f3 B  B$ a* ?9 vpublic class SwarmUtils {( [* H8 o" N$ W; i' r6 j
  public static Selector getSelector(String name, String method) {
& L2 i5 S  A* c; B9 A% v8 {0 ^    Selector sel;
7 I/ [; V1 R) B3 S" ^& z    try {0 d" h. W# y; y# r  e. i
      sel = new Selector(Class.forName(name), method, false);
* w, q1 }$ @' @2 [1 W. h    } catch (Exception e) {
: U* V* V  O2 v: N+ d, I1 ?/ C9 e8 `! l      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");! [) I7 L; V$ x- g5 t
      System.err.println(name + "." + method + " returns " + e.getMessage());# a  Y% w% n$ n  C
      System.err.println("The process will be terminated.");
* V# n4 t4 D3 R$ P8 Q, i      System.exit(1);0 z* o& w( F3 U0 ^+ d
      return null;
& n9 O, S) X: }9 w8 B- D& i% y    }
& B5 O/ R- ], a$ M    return sel;
3 l9 ~$ X, ~* R- K7 ~* |5 c, e+ S) p  }4 v; A( |, \2 G4 b: \0 \; \

# C: s% {1 l5 p! C& I, D1 W- q  public static Selector getSelector(Object obj, String method) {
7 ?% f  i( \+ m% S4 Y& w* z9 m+ w    Selector sel;7 a' D3 ?" N2 V/ U- [0 _) u, P4 j: j! i
    try {1 K% x. `* Z+ W- u! K3 K) h" W( j$ i
      sel = new Selector(obj.getClass(), method, false);" S0 |, U. Y, E( J& ~
    } catch (Exception e) {
6 ]7 J( @7 Q* X! ^      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 r/ }: E1 ^! f" O
          + (obj.getClass()).getName() + ".");
8 ?6 C% v, v/ ^* y      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ _. Y# ?( z5 O" [      System.err.println("The process will be terminated.");
5 \2 B( Q8 G& X* P, F- N7 Z: }      System.exit(1);
) n! k( x3 ]1 }      return null;9 Y2 ?  U2 R0 h5 V7 l7 n( w
    }
" H3 H: g9 ?6 K9 W  }5 \) q: q    return sel;% ?/ h0 W1 H/ n2 `6 }9 V' p0 h+ K
  }- |% C6 {! l8 J) X! s, 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-6-3 02:09 , Processed in 0.019847 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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