设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9636|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
- c0 e5 d; [! M; y( w& ksel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
# g% _' f8 \/ @' {+ U9 x$ X$ x- l. W( F! `) F
似乎缺少了一个SwarmUtils的类,不知道怎么回事 & r# ]+ l$ H5 R
9 U5 d: }6 ?/ l% T0 O8 W
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;1 L6 a2 C) L4 a; z0 ]
, B- x6 g* ?% B/ @* d  T7 v3 d9 F- `& u
public class SwarmUtils {
6 q$ V- f8 w& F1 n  public static Selector getSelector(String name, String method) {, g; s/ S, |$ L3 `5 f, Y, Q2 }
    Selector sel;' Q" F/ d1 M6 Q' L8 @# A: C* f3 O
    try {
9 j0 Z9 W( A; }. b( n      sel = new Selector(Class.forName(name), method, false);
1 u% C7 ^3 Q8 d0 [1 B    } catch (Exception e) {
+ x+ g' ^. a$ M+ z0 _) `; Y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" ?7 S3 S5 s1 a6 d: p1 |! i+ \      System.err.println(name + "." + method + " returns " + e.getMessage());
+ _+ S2 L& o8 ]& X. a      System.err.println("The process will be terminated.");
" c1 m) B) T* {7 t" `5 B, Z8 [! o8 k      System.exit(1);
4 w: r% N7 Q0 G. F. Z( A      return null;
* s% j3 c( g$ T3 P" r: V" a4 f    }. ^* x$ z) w- K/ }: L
    return sel;
. r: l; x" y+ f  G$ N  }- c, t/ V+ e! K* Q" d8 F* C
+ H% i- D% K* K
  public static Selector getSelector(Object obj, String method) {* w* t6 i+ d  ?0 F9 A8 P" W
    Selector sel;
  c  s4 U. w5 [, f5 Z$ q3 ?    try {
" }2 o( D7 p" V+ X# t      sel = new Selector(obj.getClass(), method, false);
, C; G- [+ s; n    } catch (Exception e) {
  {6 R( P2 r% a  i6 U      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" ~* A  Q/ u9 Z7 I" p  O          + (obj.getClass()).getName() + ".");
, n! f$ W) M8 G      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! D9 _) d9 u' w$ f) H
      System.err.println("The process will be terminated.");1 x3 s; I& v& J' r/ P0 U
      System.exit(1);
! \& a) z( ]3 L      return null;
: y: j0 A$ c3 ~5 c( v    }
7 x( n' O0 ?- g, ]/ S/ {    return sel;  d: F3 g% ?% F0 }# t0 C1 w3 ~# M
  }
' }/ D7 a1 @. o4 |. Q9 Z* {+ P}

评分

参与人数 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-16 08:44 , Processed in 0.019337 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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