设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10529|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行" {. B  V& [* _! Q
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
: h+ v/ m3 r8 M; e+ a$ g9 C- h4 {& d* D5 j
似乎缺少了一个SwarmUtils的类,不知道怎么回事 " F% ^3 l8 U0 y5 _

* x+ Q/ [! r. m; C, m朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;  A: o! O! s4 P

, _9 x7 b' H1 L  S1 Opublic class SwarmUtils {6 F6 _7 X- A4 w- }9 x# N
  public static Selector getSelector(String name, String method) {9 O# d& h% b9 U
    Selector sel;" Y: Z4 |- [! d
    try {
7 L6 W$ ?+ F+ S4 D      sel = new Selector(Class.forName(name), method, false);: q; W- d/ ~* s
    } catch (Exception e) {
/ o  p( t7 c0 i9 S/ w5 X      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& i6 D0 n5 j) B, N' }- b' X
      System.err.println(name + "." + method + " returns " + e.getMessage());
4 Z: s, A) ~8 J1 H: Y: e      System.err.println("The process will be terminated.");! A- m7 B% H7 U. x: M
      System.exit(1);7 Z" k8 L: d7 B) c4 R, t- z: u  {
      return null;( R' X+ T# Q, |6 B6 O
    }( H! G" u- |; f, I4 X, d
    return sel;
, x  P; g! c) w5 V$ p5 f3 k" {  }
: O/ I& z$ V- [  e7 k: C+ L! N6 ^4 j
, U$ i2 Y/ z" ]. `: d* y7 Q  y  public static Selector getSelector(Object obj, String method) {
2 E' C5 B0 J+ v/ o3 S8 \    Selector sel;) X! u  K- |4 b# `& O6 f' ]& M
    try {, s0 ^- C9 u' p3 f  r3 A% Q8 T
      sel = new Selector(obj.getClass(), method, false);
' ~) a/ [3 X. f% z    } catch (Exception e) {
2 @; x  h. n2 n# @) B9 ?# i      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& Z: u1 u) ^2 v+ y/ K- L. F          + (obj.getClass()).getName() + ".");6 i) w* N+ q7 j+ g7 F- @$ k
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* ^  Q$ M, R. y* h
      System.err.println("The process will be terminated.");
& M5 J6 z8 }  i; x+ t& Z      System.exit(1);
- F: h  r) G" k5 q      return null;
+ U8 p& D% `! X+ |6 D* y    }
2 ?1 n- G# ?8 K: w) R    return sel;
, _$ b0 _8 }/ X  n) a9 \  }
" |. y8 _0 v; i7 {) k. E}

评分

参与人数 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-8-30 13:03 , Processed in 0.023403 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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