设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7636|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
9 O5 @3 T; z  k3 c8 N9 r1 Wsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
4 n' j% F/ `: H" ?0 v& V7 n- A" z$ G+ r: c: x7 K% r  q
似乎缺少了一个SwarmUtils的类,不知道怎么回事 7 J) @- K! b5 ^2 {& l- S5 C' e) I
) [$ Q+ T& m1 \, E9 [
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;% K* C. x, d% i6 V- E0 r( o* Y8 t% F
* G+ {( p5 d4 |0 \! ~7 C
public class SwarmUtils {: S0 m3 F1 e8 W1 {9 d
  public static Selector getSelector(String name, String method) {
$ Q) ?7 v$ [! P5 Z! J" F7 a    Selector sel;
7 q5 c$ P5 P8 U& {, n9 ]    try {
# l* E5 n+ @0 c* Y      sel = new Selector(Class.forName(name), method, false);2 \: R# x/ D# A* I" |
    } catch (Exception e) {! C6 A4 T4 u9 d) i$ A- Q# l
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");3 T8 r, Y. \; e
      System.err.println(name + "." + method + " returns " + e.getMessage());
# A" Z2 W% G8 V      System.err.println("The process will be terminated.");
0 M% B. B+ F: ~1 g      System.exit(1);
  ^% d1 Z$ r+ `      return null;
- @: D' J* C+ t9 Y8 H    }$ |) p% J; X1 k# }" D6 G
    return sel;
# Q; S: k8 Y  ?9 S" t  }
. R6 i& l3 p3 B% N) z; h" M5 W- o* }6 l. h! z( h# k4 V
  public static Selector getSelector(Object obj, String method) {; N( d! D, R2 v+ o3 f- X: k- Z
    Selector sel;
9 P) f! A# w5 d* n; L3 X    try {
2 ~0 C2 w" S& P      sel = new Selector(obj.getClass(), method, false);
9 x1 d& Y. M3 Q+ O) R5 o2 ~. u, O    } catch (Exception e) {
) Q4 E' H/ e: l/ `, N      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: ]  {4 e" S9 ?0 Z          + (obj.getClass()).getName() + ".");' r  V) B* f- A4 L* v) o+ r
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ U! }" ?9 B. Z9 J5 t/ z/ o7 J: y      System.err.println("The process will be terminated.");# ^2 W( V9 y  O
      System.exit(1);
8 ]0 q7 C: s* w5 T: N9 n% |' v      return null;+ d* a  M/ R6 H8 c, a2 t
    }- {4 [# `- t5 ~7 u* E
    return sel;. F5 A% ?7 N# E  T
  }
! `% ?' x9 h6 {* r8 N1 ]/ 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-7-4 09:52 , Processed in 0.015619 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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