设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9533|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
+ ]4 @) ~* ]; W4 a2 b4 u9 Tsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
% D* i$ P/ ^$ ~$ \# P* h; F' t! y3 l! s: }, ^
似乎缺少了一个SwarmUtils的类,不知道怎么回事 7 }3 q+ _. p3 b* k5 c  o

# [$ @8 k+ @: H* j& t9 ?6 l朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;, S! m* {1 N% }4 o
' L' j5 i, w0 p1 H& d2 d; h4 {
public class SwarmUtils {" T4 T% r0 P, |5 `
  public static Selector getSelector(String name, String method) {( q$ t# L$ y7 e' a+ u
    Selector sel;7 |! v* y( ?8 [# l, K1 q* }9 o$ w
    try {
( r7 g- v# F) H3 V- K8 u2 f      sel = new Selector(Class.forName(name), method, false);
( I3 @9 A( b# P0 R    } catch (Exception e) {& E3 _" `3 p: F/ D7 {
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' @6 R9 l  G& ^5 p  J# r0 o$ t      System.err.println(name + "." + method + " returns " + e.getMessage());0 ~/ L- q/ f" {3 G
      System.err.println("The process will be terminated.");
, Y/ D' z4 m, e2 d      System.exit(1);
* {% b' n/ a* O9 Y" R( Q      return null;3 ]$ ^5 y0 s' R8 j) ]! R
    }
7 m/ q' p# N% X  f    return sel;
% ]" j) h) F, a5 C  }
5 n) W5 e: B- A
: @$ z+ z4 ^- }6 P  public static Selector getSelector(Object obj, String method) {
) N( _/ g8 `# k" t& O    Selector sel;
2 v, ]: H; A! h. G+ Z7 g3 E    try {
3 |/ U: ?! F! x- t2 `: \1 i: s      sel = new Selector(obj.getClass(), method, false);
% y0 ^1 Y+ `. e3 Y! ?    } catch (Exception e) {
2 K( W7 z& M6 c! m1 V( {. `      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 e: @. j! g2 X% \$ Y          + (obj.getClass()).getName() + ".");% w9 v  P& N- {* S8 F! _
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- ^) _( V3 ?6 Y, U, l# r      System.err.println("The process will be terminated.");
+ J2 d% Z* J  x9 l, H/ Z      System.exit(1);
) e5 j3 P, I4 Q# Q7 _7 ^: n      return null;
# d1 d9 {3 K$ u: ~- d, c( W, Y    }  C2 r; T1 N" l! @3 m
    return sel;
* T1 M) z) {% V/ P  }
- ?* C% @! K6 }9 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, 2026-5-5 12:53 , Processed in 0.017792 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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