设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8228|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行% J  ?/ U' I- w7 v+ X- G6 x
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行% V3 r" L: V" v) N
+ X( \; P& K5 F+ J8 N- r
似乎缺少了一个SwarmUtils的类,不知道怎么回事
0 y4 x, {7 Y3 W" i' H- A3 v, u
- _* }: j1 j2 F5 F6 `, W朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;+ L0 j; u' V5 r9 q! H

+ L  c1 @& B5 m9 V3 {& Hpublic class SwarmUtils {
  R4 v6 s. D, S5 p% E  t  public static Selector getSelector(String name, String method) {# `+ V( c# m. x! [0 Z
    Selector sel;+ U6 U& v4 U  K6 h6 x
    try {; j. X6 R4 V$ U* Z
      sel = new Selector(Class.forName(name), method, false);( o9 s9 r1 y1 g! s9 a
    } catch (Exception e) {7 h. g, X. U! }% I2 Q
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
  n/ A2 {- Q$ Z  w4 j& b5 f; g9 d1 B      System.err.println(name + "." + method + " returns " + e.getMessage());2 m. u7 e4 {3 q- j+ O+ a  z" Y3 e
      System.err.println("The process will be terminated.");5 m# Y9 g/ W, b" u; Y
      System.exit(1);2 u# Y, N2 O5 Q: O: r
      return null;0 [7 T4 o& A- A0 z3 R
    }
$ k8 h- K5 L: K# t) w    return sel;% l- O6 i% w1 M
  }# g5 d- S; q2 g. X$ N
5 }% K# `# Q0 f2 Z; ^% s
  public static Selector getSelector(Object obj, String method) {3 E6 N% ^. ~, R% N
    Selector sel;8 d! }, [, h) ]' _
    try {
( L8 n' }$ P) E5 F+ y4 A9 k7 y1 c) Q      sel = new Selector(obj.getClass(), method, false);% c9 G* F; x- y: F3 D* i  r
    } catch (Exception e) {5 ]% d  [  g  y0 ?% R
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ k) d  J0 F$ S8 d% N1 K
          + (obj.getClass()).getName() + ".");; ~. P: U! h6 g. a' i& |9 F. [
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, t+ H# D9 t/ }6 D
      System.err.println("The process will be terminated.");
2 T9 g0 b- j4 q& r      System.exit(1);
8 C% b, z$ z5 @% j6 q' N      return null;; ]6 u6 M& S' y. v* Z( V. |
    }
; b$ M) z$ L7 U% [9 g3 J* x    return sel;
! W5 L1 x: }: M; ^# D. D) a& I( l  }
5 t+ [/ k- w7 I, n2 W; r' U/ k}

评分

参与人数 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, 2025-10-17 07:31 , Processed in 0.018133 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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