设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10664|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
3 p+ s1 Z' N6 p8 E( Q* esel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
/ s) \! @3 Y, _2 S2 w+ K$ _1 U) Z
! p# G) O" H8 q; A+ V似乎缺少了一个SwarmUtils的类,不知道怎么回事 - G2 ^& g' J6 F. v  c8 C

! }( K" O2 D% A朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
% P- a& \) `2 Z  o3 b" y, d2 e9 {: j, Y9 M: a$ Q. i0 y
public class SwarmUtils {" y5 }8 X! {9 f% N& @; k  M: U
  public static Selector getSelector(String name, String method) {# k7 R9 a( n3 B6 T
    Selector sel;
/ U& v3 y) C6 p4 `6 A    try {* K. S- O* y  o- P. G& x  s$ ]: r
      sel = new Selector(Class.forName(name), method, false);
' @' p4 p. P; I1 U    } catch (Exception e) {
7 B( K9 T$ \1 @/ d! C( Q7 i0 `      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");# i2 G( j9 f2 |9 \& q
      System.err.println(name + "." + method + " returns " + e.getMessage());
0 t$ c+ b+ j  k  P" s' Q      System.err.println("The process will be terminated.");7 w& U- G/ k. J7 V1 ?
      System.exit(1);
- ?. Q8 J6 ?  m      return null;, T2 x3 y& a  {. C, B$ d9 U
    }( |5 \3 D" s$ T' o/ x
    return sel;
% u, W* I* E3 i% R3 M" s+ l7 ?  }4 c( c! _5 `9 [& m

5 o8 i7 m, A. S# [! ]  public static Selector getSelector(Object obj, String method) {# j3 b4 s9 W, W# [
    Selector sel;. F7 g. `  j$ _+ r. N& I- g
    try {
/ x& d5 w# a& q8 p# q      sel = new Selector(obj.getClass(), method, false);
( P! `( I9 ~2 z* Y" t# X; Y    } catch (Exception e) {: N0 W& h5 W; x. c7 _
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- J4 \& {) }: d. D; t( m6 ~8 G          + (obj.getClass()).getName() + ".");6 N# D4 ]$ f1 S7 Z
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" W5 k3 v+ `+ O6 x- [0 a( b
      System.err.println("The process will be terminated.");
. Y! r2 F* |) _1 D) k. }7 r      System.exit(1);
2 f2 w! p0 H" w# s: y3 O      return null;
8 w0 L, t' \7 K! V" p0 @    }
, m% z4 V/ p3 D. K2 R/ G    return sel;
' y: ^  X8 M9 A4 [9 r$ U: n7 x  }
; ]/ O* R8 h! e4 E  |9 m5 x; 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-9-15 11:54 , Processed in 0.019008 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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