设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10494|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
  c6 D* {% R2 ?" [7 zsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行7 z4 l& ^! h2 {$ e- h5 O) B
. t" K+ x" Z. p, T( b
似乎缺少了一个SwarmUtils的类,不知道怎么回事 , u9 S$ l5 v. l5 U4 X

( g! a- R8 [+ i" W/ l" Z" f+ p朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
* D. d! T/ {- p3 S* j2 [+ |2 l) Q+ u! R3 D1 y: P+ |. M8 j, `4 B% f0 V
public class SwarmUtils {
4 @; x0 @! q- {5 N) P  |2 _  public static Selector getSelector(String name, String method) {
9 c* s( O8 h! J    Selector sel;
- O6 ]0 i, w) p2 h    try {
. P" t, c: Z6 h! x      sel = new Selector(Class.forName(name), method, false);
2 L. v+ a  s% ^* u. R( O    } catch (Exception e) {: D( x- o5 V$ P+ a5 j* s
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' o6 l) F7 G& m" `. n& T      System.err.println(name + "." + method + " returns " + e.getMessage());% \: U3 b6 O) {0 O9 G" x
      System.err.println("The process will be terminated.");
3 Z  {& V5 u6 i, U6 H4 i7 ?      System.exit(1);6 H; Y3 {/ ?3 m( f6 H0 v/ M$ f
      return null;
% k4 \' ~  o: p' r' L+ N    }
# O  _! B8 s& L8 U( s    return sel;/ V7 @( {7 D. R) Y* k
  }
, i) |8 j) E, l4 M- Q
" ~( ^# i9 N* `1 ~2 S  public static Selector getSelector(Object obj, String method) {
+ N* N8 P5 F& x/ G1 g! ]% J    Selector sel;+ ?! ~. ^$ F9 H
    try {
# H$ [+ m% ^( g. s) `# \) x      sel = new Selector(obj.getClass(), method, false);' p9 F" q& L+ E& X9 W
    } catch (Exception e) {
6 S6 I* n: Z$ G, ^      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: ~& t7 V, B+ d1 F* U1 ^' o          + (obj.getClass()).getName() + ".");
: k- `2 q0 c3 W: E9 |  N$ W9 ^      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());' P7 [# d2 k! ]4 I9 R8 F
      System.err.println("The process will be terminated.");) ~4 n$ j) I! h9 A. _/ ~
      System.exit(1);) M7 ?. L) k" @/ q( Z. {3 D
      return null;
8 [% }5 V& C3 l* G    }% f5 V9 _$ x2 B/ I2 Y
    return sel;
6 y% ?& e8 N/ j* J9 c' z  }
' R1 L- q3 B1 ?% Q* w}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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