设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8076|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行% k( H9 `' v1 S
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行5 v: m1 f1 N8 R+ T
) O" \- W8 i* T$ p+ _9 Z
似乎缺少了一个SwarmUtils的类,不知道怎么回事 / ]  d5 `4 {4 C: t- X4 _9 o' c- a
* H; q" Q, H/ `/ I9 `
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;% ~* W, h7 z) C  e+ ?5 o! L+ y
2 M" C: b0 f  s* H6 f- [
public class SwarmUtils {' y4 S, r* W: ?1 ^) H' ?
  public static Selector getSelector(String name, String method) {! ]+ r; h! s2 o! S
    Selector sel;
( T; q# |1 F# A    try {/ n$ a4 O4 h. w$ V  s9 D8 R
      sel = new Selector(Class.forName(name), method, false);
, J6 x, C2 @- r# h4 X5 d    } catch (Exception e) {' p% f( B, \2 @
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ \: ^3 ^- k# k7 z% I) }      System.err.println(name + "." + method + " returns " + e.getMessage());
! H& o7 {0 A2 i/ n1 m. M* L" Y      System.err.println("The process will be terminated.");
1 |) D' ~  c$ h6 g2 y, b- t      System.exit(1);. x2 W7 c- u' p; m$ C( c% E) x3 _
      return null;
) Z$ }: ]0 E+ O    }
" q+ i& k  q5 Q5 I# M8 [    return sel;
0 Q) t. K6 R" m& N& y  }; a7 j* k. E8 r2 v3 e7 S8 j
, }- o! V8 M  s5 D
  public static Selector getSelector(Object obj, String method) {
- k  Z6 n/ D( I7 q1 ~) b2 g( Y# Q    Selector sel;+ K% [) k) M# U0 P7 q
    try {2 y9 U5 K  a2 e
      sel = new Selector(obj.getClass(), method, false);
9 [+ X! [7 b: d" t$ ~6 U  g2 c    } catch (Exception e) {7 A! c5 m! p, `* h1 B' M6 G/ P
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "" `( _- x& d, U: Q' Z
          + (obj.getClass()).getName() + ".");* m+ i! o; y$ q, b0 u" o8 C
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());; q+ e' ^$ l* G
      System.err.println("The process will be terminated.");
7 ]3 _# d) v2 _# z' n      System.exit(1);  e+ x8 K/ `8 H+ L% p% r, }
      return null;$ ^+ i) m3 {1 s' U
    }/ U- D/ D2 N2 r/ n1 a/ X  I  a
    return sel;
% d; i6 d* t, B) U  }! y2 u( W, F# E' B+ e9 R! i4 ?  ]* _
}

评分

参与人数 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-9-18 10:42 , Processed in 0.015008 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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