设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9464|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行; {3 M0 d% ]' o  m/ p1 e
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
+ |+ p; w& C0 N+ U' l/ l/ a
  e! s, t! F) a: e$ J似乎缺少了一个SwarmUtils的类,不知道怎么回事 4 ?/ W( p6 @/ E
7 q, k9 c9 X0 b2 E" b
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;, q% O8 |4 r$ W. E" P! V
; P% D1 J  t" d% l
public class SwarmUtils {  V3 f1 L9 }+ @3 g9 S# P
  public static Selector getSelector(String name, String method) {
2 J/ {' H) Q4 p8 R, o; d0 ]* a; {0 |    Selector sel;
3 R& z- [2 Q% Q5 D  j' G. E; W    try {# Y' |8 K/ n& n2 N
      sel = new Selector(Class.forName(name), method, false);
) M0 I9 w, [& X" A( p( ~; V    } catch (Exception e) {
1 B! @) Z+ \% r' z  z& A      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! y/ ]* S; _3 Y9 L      System.err.println(name + "." + method + " returns " + e.getMessage());
( D; A8 n5 u  R' D3 S1 f* K: g      System.err.println("The process will be terminated.");
5 }' P( p4 |, z      System.exit(1);
& Y- v; _, a9 o0 ~, x* X      return null;" M# a. x3 i: |6 `' v8 ^% t
    }6 X5 ~  l3 V5 L, J0 g  Q/ B, H
    return sel;* f' Z. S3 s- y. n& C! P3 V
  }
/ I& v( c% C! \: ~) K8 G' k" R/ `4 U! L
  public static Selector getSelector(Object obj, String method) {
0 H# G# z$ X% z7 Q. ~3 N$ p    Selector sel;4 m" r- t* |( d2 M
    try {# L3 @# r5 J) y, i
      sel = new Selector(obj.getClass(), method, false);
0 l) [' ?; W4 l/ f3 L    } catch (Exception e) {
/ s% Y+ r  T) w      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 Y6 ]+ k0 |9 p5 K' z. }3 [6 g          + (obj.getClass()).getName() + ".");$ S* G& j' c6 Y+ w  _9 V
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. W1 g8 d* {+ G: b/ R' A9 H  ?
      System.err.println("The process will be terminated.");
! a+ P' M+ d) U      System.exit(1);7 I' d# ?6 P0 B. Q
      return null;
0 C* z+ s) v: Z2 H5 _5 g    }
( x) s8 G. x% A/ M4 D8 E    return sel;
! ]5 c7 G1 l: Q" }6 b  }  n7 m: h! z) D. ~  U
}

评分

参与人数 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-4-28 03:56 , Processed in 0.018609 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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