设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7995|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
0 g# c3 X" E% M: Wsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
- Z5 O! ~8 s5 e- h* k" g3 |' ^6 P# ~7 p. X7 H: V7 k) j; o
似乎缺少了一个SwarmUtils的类,不知道怎么回事
- P# i, b4 z1 I2 S9 ?: ]' C; p
) e; _* s5 b* m$ f3 d) d朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;7 m8 S9 q" f5 {% x6 H! q& O5 r$ b" y

: p& Y7 a5 J2 ]6 P1 m. F/ ipublic class SwarmUtils {
4 o/ T6 q8 m$ g% O  public static Selector getSelector(String name, String method) {
+ W: O- {2 R# j! ^3 }$ w    Selector sel;
! A$ |$ K4 z% M4 E: c, b+ z, H    try {
2 f- m/ G! q) [" t6 C+ g# \5 I      sel = new Selector(Class.forName(name), method, false);
6 R3 P8 d8 w- g$ \    } catch (Exception e) {& P( Q* o, s' A: ^  e$ C" M) s* H9 Q
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
3 N# C" X2 p2 J, Z      System.err.println(name + "." + method + " returns " + e.getMessage());; b9 ]' ~: H' c0 V& H
      System.err.println("The process will be terminated.");
1 w: c+ I) I( E0 f! {      System.exit(1);' h9 C' }. i( i' o
      return null;
: j4 v0 F3 Q4 s    }
3 s; \- a5 O7 n$ B* O1 f3 P' `    return sel;2 E0 @2 A* _5 x) \% P0 q
  }3 b$ H$ o4 ^9 R2 X) J% T
$ O, u3 U" |+ {  f3 Y6 s* l+ `
  public static Selector getSelector(Object obj, String method) {4 ?# S$ g7 j6 L6 h
    Selector sel;
3 @7 I* j( k: B4 z; v    try {
$ k( R, a2 _  I+ W4 f$ B1 X      sel = new Selector(obj.getClass(), method, false);6 u/ G6 Q7 O0 w! ^2 X/ f$ P
    } catch (Exception e) {% u- B1 S, d: N4 o4 w
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 ?' S' X- x: u0 f! C  Y! X9 }          + (obj.getClass()).getName() + ".");
. S# [+ ]9 r+ b  Y6 e      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
  S- T" `" Y: B& N      System.err.println("The process will be terminated.");
4 n6 |9 v! Q" K3 X7 W      System.exit(1);
' }% q, Q2 t, E      return null;
+ O6 W' B' w9 j2 [    }/ A2 c& a7 O2 E5 _: E; s5 A4 e
    return sel;$ u  k) }7 S; C" P0 v+ W( w$ R% R
  }
" r' C4 `. Q$ P" O}

评分

参与人数 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-5 07:07 , Processed in 0.015343 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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