设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10436|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行" ]' d7 k% I# q: f* x( P3 W& |
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行8 f5 j3 j( C( \* q& k" @. z
, X. J* B/ C: ~
似乎缺少了一个SwarmUtils的类,不知道怎么回事 : X# G1 F3 I* C9 }

/ a: Z) H9 r5 n$ b& Y4 f朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
9 L& j' H7 ]* U9 h" |( n: I) b7 W9 x
6 K$ m- U1 X) x. H9 Y/ N- m9 ], ypublic class SwarmUtils {
- \& p$ H. ]  O  R% a2 T  public static Selector getSelector(String name, String method) {* E) t+ Q4 t4 g8 _" ]6 F- U# C
    Selector sel;
  U# v0 m! }' Z( A6 S2 K  Q2 I5 `    try {" a& m: ~) v3 h6 c) {5 z1 Y
      sel = new Selector(Class.forName(name), method, false);
( v' j5 N/ I" b8 Q) a    } catch (Exception e) {
$ T: m0 R% e, Z2 c      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");" C  q: N2 q- v& y5 r- _
      System.err.println(name + "." + method + " returns " + e.getMessage());
: o  C+ O' \4 w0 T6 U# F- k( e6 F      System.err.println("The process will be terminated.");
! B( T9 q8 [9 R- g      System.exit(1);; `+ p4 C; R& \% P* ~* T! ~4 D
      return null;$ O- N* m+ T8 {& Y
    }* u2 l2 f+ l4 g! g1 m% e2 K& W. ]0 i* B6 J
    return sel;5 p$ v! \7 S2 K1 j4 g6 X2 y' @
  }% `* T- s' t6 {. `; s' r. M6 i' k
0 c* S  c3 Z0 M- L! O" R6 ]% F* N
  public static Selector getSelector(Object obj, String method) {
: Q0 s4 C) B. W/ W" N: M    Selector sel;: T) q5 N8 _$ I8 v- s7 X( G2 X3 X
    try {# Y8 b! u; t4 b2 W+ u
      sel = new Selector(obj.getClass(), method, false);2 n& K8 W2 Z( A2 o* \& H
    } catch (Exception e) {9 ^5 U( g6 F2 {. \' r# u! h
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 d) E% R/ r+ L0 b5 w2 k2 q
          + (obj.getClass()).getName() + ".");
+ g8 T9 H3 d3 b: D- Y# E      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
6 d5 h4 I* }0 L0 x# `$ V      System.err.println("The process will be terminated.");* q" W, c' E: z6 M
      System.exit(1);
5 r- s# O+ X5 c1 H" t; }8 t: H      return null;
0 M$ h; Q# E8 f' \/ O, b3 Y    }# @- V& o! y& q9 c, @2 V9 P9 a  T
    return sel;$ {+ a% s0 `$ i; }$ C! i, q9 C. E
  }, S5 E) \& y5 `, o; g3 Q
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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