设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10209|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
6 ]7 K* ]4 ~) m0 T' Asel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
2 k3 h) j1 m& t
+ m/ }! j3 @& n/ @1 [2 D- O/ [, q. w似乎缺少了一个SwarmUtils的类,不知道怎么回事
3 b  m$ S8 V5 ?& ~9 l
/ X7 x7 i* z3 _0 Q5 _; X$ A朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
7 C9 O5 {+ B" P+ D: o2 h  G0 q' t$ g3 v4 O0 P1 E
public class SwarmUtils {
7 f  k5 e4 K, |" G7 W: X- E8 l  public static Selector getSelector(String name, String method) {7 j0 K2 W! D0 f; O7 O
    Selector sel;
" K; `6 X1 ?6 G, O1 S7 Y    try {2 r7 Z0 r; r* L9 ?4 w( R9 B7 ~
      sel = new Selector(Class.forName(name), method, false);* r" q3 o+ S. w& W0 _" Y
    } catch (Exception e) {
9 ?- c% [9 s' w) p) Z* j      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");) L+ z7 O( x' s4 v8 k/ u3 Q7 I
      System.err.println(name + "." + method + " returns " + e.getMessage());
. H% o% @+ \9 ~8 U7 e  i      System.err.println("The process will be terminated.");
- R) z" n, h$ Y      System.exit(1);! A7 e. p3 I# I% l. ^
      return null;& C6 s6 m& G/ f( B: \+ O( Q
    }. @" ]$ e7 D' W8 P6 L9 f' C
    return sel;
& T0 }" ^! r. b) O' ?0 Y  }$ V6 g& m/ J2 Z4 m8 _6 i; ^9 @5 H

' t- R7 Z; e5 E1 M3 f# W' f# _  public static Selector getSelector(Object obj, String method) {/ ?. D5 I0 f9 ^" B6 ^/ E) o
    Selector sel;
: b$ b2 p- M+ `* Z- c/ o6 Q" J    try {
+ T  j( u$ U4 q0 u% g      sel = new Selector(obj.getClass(), method, false);
# @' b1 |2 E0 Y; `) Y8 A! r+ ~    } catch (Exception e) {) ?7 y+ g% ]2 X4 \
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
4 V2 T5 M" y* r" }/ U# T0 u' r4 ]          + (obj.getClass()).getName() + ".");
$ w& m, i1 i; [& t: j& x      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
' g$ B' g: t7 s6 @: u2 W      System.err.println("The process will be terminated.");
5 s! s6 d" w+ }- X$ }      System.exit(1);
0 b9 Z6 d+ S1 G( u; i      return null;7 s5 U$ B* I6 Q, T) ]0 h' a" c
    }
+ c  c9 V- l( B/ q- f    return sel;
8 n  e; ~% D: A0 t3 \  }! G; w4 L$ t$ q9 {1 H" u! u
}

评分

参与人数 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 00:50 , Processed in 0.015578 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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