设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9643|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
% \  E) {, a2 r; \8 Z* hsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行0 z- J( X$ {: x' d  B0 k$ {

: O, u# C/ h) j1 r) d7 |% |/ m似乎缺少了一个SwarmUtils的类,不知道怎么回事
- z5 R) S5 o4 Q5 b( Y8 I1 Q$ ~1 @: g$ [
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;: F( Q0 P5 o3 W2 ]! Z" Y1 A
* g$ G3 q- \$ N' R: B+ H
public class SwarmUtils {' P7 H6 Q5 O( E1 \( X
  public static Selector getSelector(String name, String method) {
& r; Q, p1 [) o. o    Selector sel;
+ F$ _+ e) S- ^1 a5 s3 p- H    try {5 _) c$ z+ ^0 Z! B
      sel = new Selector(Class.forName(name), method, false);
" M' X: g9 S: i5 A; x$ H8 ]/ A3 L    } catch (Exception e) {
5 O( d9 A* Q" n+ D7 Y6 H      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");, [6 L' ?; G  ?' _
      System.err.println(name + "." + method + " returns " + e.getMessage());9 w# M4 w7 o# |
      System.err.println("The process will be terminated.");
' u* ]9 x) D4 W% }      System.exit(1);" x& d' i( l' W2 n; r- o8 L. y
      return null;
# g' ?- n2 G: Z/ t& Q7 u- R0 m; y    }$ O' w1 |  v9 l8 |" |+ f& x; w
    return sel;
% }& l. w# ~6 F, I4 ^* t7 `' s  }+ Y4 {5 m" T( k5 E9 C
5 u) Y- z9 O! s
  public static Selector getSelector(Object obj, String method) {
$ _# S- W. N: p) ^) x    Selector sel;
6 t: t- m% x3 @) G    try {
$ g) p% [, w% ]! n/ M% l      sel = new Selector(obj.getClass(), method, false);' V0 n: Z' L' F. S
    } catch (Exception e) {" O! U7 }1 j& A  J7 J
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% }( M9 J+ V1 i- o% K
          + (obj.getClass()).getName() + ".");5 j# q& R8 r4 ]" e. ^
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 l, r4 a$ v/ D* z/ q, T      System.err.println("The process will be terminated.");
* X; c! v' J) t( k1 p      System.exit(1);6 ^% }2 F, V9 c$ y
      return null;
! c7 {5 }- ^0 H* O5 b* y    }! @% q6 ]  ]; v7 }( w2 O: d
    return sel;# l7 z/ R3 X- \' F+ j9 {
  }
, U/ U" P" s% a- 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, 2026-5-17 12:05 , Processed in 0.020699 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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