设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10495|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
# D6 z3 ^. B8 X( C$ h; z  @sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行9 f& H+ |3 `- C$ ?! J

  F( C$ x8 ]7 l5 k7 k似乎缺少了一个SwarmUtils的类,不知道怎么回事
% i3 \& l" q8 B) P+ o+ k" d7 |. v2 U' Y4 n. ?5 X
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;1 C& ^0 c7 x3 ~; @
( }0 }1 h4 Q- t; P/ d% @& h# Z. W0 }
public class SwarmUtils {9 q- [# A) N9 u+ @2 H* V, _
  public static Selector getSelector(String name, String method) {
; v% D; _/ c  K$ g; J  z$ p$ q2 O+ s    Selector sel;9 [  l' v. h+ B3 p/ e  g
    try {
" e# |8 W- R1 Z, B3 P& ?, G      sel = new Selector(Class.forName(name), method, false);0 s" t3 S2 M( J4 \0 _1 @# |
    } catch (Exception e) {
1 I" p  H! b" O      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; T" b9 V9 m, S( ~+ }% P
      System.err.println(name + "." + method + " returns " + e.getMessage());( g$ Z# o, F/ U
      System.err.println("The process will be terminated.");7 A& }8 q  M7 _1 R: Q7 X
      System.exit(1);
1 p5 B" A' e4 g5 |/ K3 ]      return null;. C2 k" j: C- R0 J4 J) y. P5 u
    }, X. J( w+ H: M: b( x/ n
    return sel;2 o# K4 x2 F+ E6 F
  }
; Z, l; |, k& ^% E3 p& h5 Q  P( w$ h2 J
  public static Selector getSelector(Object obj, String method) {
5 w: T3 h7 t2 S; r9 q3 N    Selector sel;/ l/ r7 l/ P2 E; `+ A  q5 X. l% W- u
    try {1 w3 B6 G' |/ H& s
      sel = new Selector(obj.getClass(), method, false);6 z2 [, b/ \2 t4 r& z0 T  H
    } catch (Exception e) {( f- i0 W- Z9 T0 d; Y  ~
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 H5 ^: v# ^9 G: ~) o          + (obj.getClass()).getName() + ".");
/ ?- a, |" D( _      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 c8 R2 W& n- n0 U0 D( I3 l
      System.err.println("The process will be terminated.");. Y8 a5 X% L% r
      System.exit(1);
; d8 p; b- f6 Y      return null;
1 L* `8 ]( S9 q    }
5 z/ J+ h* |/ p1 }9 u" i    return sel;3 E  ~  j1 z% n1 m" i: F
  }
, R% e( s# t, q$ X% j}

评分

参与人数 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 23:51 , Processed in 0.018956 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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