设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10216|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
* a. m4 L1 ^' Msel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行) I5 z8 Y+ b# E9 a$ s$ _$ C! \2 ?4 o
1 G/ Z$ h1 N+ r
似乎缺少了一个SwarmUtils的类,不知道怎么回事 * ~- ?9 q7 v! ]
) ?" k# k# `, ?. J5 v5 j; n
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
& o( K# _4 }. P3 T) O8 {6 p: C& Z' {+ L2 U6 s* V
public class SwarmUtils {
9 m) r! V: f! }6 `  public static Selector getSelector(String name, String method) {- u! C0 r" }: D+ g
    Selector sel;
0 r' D; j& R5 C7 j( S5 Z3 H# q: ~    try {! `* \2 T8 S1 c( A5 K( q4 a
      sel = new Selector(Class.forName(name), method, false);7 S! t( x8 O8 F( P3 z2 B" C. G
    } catch (Exception e) {+ U+ X! r6 E" ~4 S2 e) i4 A3 X. l
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");2 o9 T, y4 v1 n, K2 m9 ?
      System.err.println(name + "." + method + " returns " + e.getMessage());. B5 j, U& x6 F0 e5 E& ?: v
      System.err.println("The process will be terminated.");
" q' F7 [1 H# h. I/ f$ S      System.exit(1);
& s% y1 h# K- q  f% F6 R      return null;
! Q- L# E# g0 J, H2 {6 g    }
. _; ?3 Z0 z% r; _$ ?    return sel;4 Y, Q: n. Q* t& T# y( Q
  }
4 x6 n' `  ?- r, C, _8 J* D
7 i2 r& v6 x8 {. b5 K* g  public static Selector getSelector(Object obj, String method) {  S' @% H9 N3 i2 A* C6 |5 h4 u
    Selector sel;: m# S2 {; P5 |; n* ^' E' o! {
    try {5 x/ D$ w- Y0 D2 [% \/ k
      sel = new Selector(obj.getClass(), method, false);- G5 S, l9 E, x' ?# ?- b0 w$ `
    } catch (Exception e) {% T1 g7 a1 R3 U' k
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" Z0 V9 X* Q0 g+ M1 c& Q          + (obj.getClass()).getName() + ".");0 E4 @& r# C9 \3 z9 _2 S+ F
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());) j3 v+ n% a* c' r' a9 W' P
      System.err.println("The process will be terminated.");4 W, O, Y3 g$ F4 {- t- i
      System.exit(1);
* X' N2 O: j/ ?# ~/ q9 i4 [      return null;
/ U. b) V8 B& f. L9 b  t1 g  y    }
+ ?- t; w: n  f0 `' h    return sel;
  l/ q! _7 p% {3 r# \  }
5 ^" ]7 m2 ?9 H5 _" i+ O  B+ y}

评分

参与人数 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-7-25 20:18 , Processed in 0.019585 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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