设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9673|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
6 {9 g6 d. }8 T9 S, Hsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行  w# z; W$ i; v' T2 @3 l4 b1 F

+ _0 J& ~' O* y  m2 z似乎缺少了一个SwarmUtils的类,不知道怎么回事 , s3 z. |$ f% B# s) V; |0 R3 H
; E) l) T9 y. t* H  K- E' e9 B
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;. q& O5 O% {# J; x4 |; \% T8 z
5 K/ }9 B* X0 G2 Y' q; h2 u
public class SwarmUtils {8 H# k/ P5 [4 g' x% s$ u  Q: T
  public static Selector getSelector(String name, String method) {& p: e3 p% N) x' P9 h1 g" k
    Selector sel;  Q: m+ ?' N; G
    try {! P' N* L' r& V6 u4 }
      sel = new Selector(Class.forName(name), method, false);
- I( q1 g% `6 f. @    } catch (Exception e) {" b9 B' S9 x) b' A
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! `0 U6 G+ Y: t4 h+ l) f# f9 @      System.err.println(name + "." + method + " returns " + e.getMessage());, Y9 ^, Z. D, Q0 z
      System.err.println("The process will be terminated.");
+ ?8 p7 f6 g- y      System.exit(1);+ z/ d* L! m& J
      return null;
: z1 \6 B2 A- r4 P0 W    }2 @) ?2 r1 ~/ x* _- V4 g
    return sel;
9 L' H, N! `3 v- ?. n  }. O6 f1 R; m% E# K; s9 E2 _

2 b8 G6 G; z+ N" R" Q4 `  public static Selector getSelector(Object obj, String method) {  s5 v. l; m- y1 P  \. d" C
    Selector sel;8 t! ]' b+ p5 v  d5 o
    try {, C7 w6 C% W$ a9 s* i
      sel = new Selector(obj.getClass(), method, false);
, V: {) k6 n. c4 m* T2 X    } catch (Exception e) {
9 z2 \0 E( o+ N1 z      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" H) e, s6 q9 b( I& y1 z  }          + (obj.getClass()).getName() + ".");0 x  n& w( e) Z8 S
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: ]% I5 E5 X% d, n; @, n+ V      System.err.println("The process will be terminated.");
5 |. N# o' O2 m      System.exit(1);
. B) A7 x& R9 {9 b# S& P3 R      return null;
. w  Z( Y: U. A& H3 R    }
+ Y" Y8 Y! L8 ]    return sel;
5 p! p* g1 h* K3 b+ J: p8 u  }
5 X4 L. b+ C# e: V4 h}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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