设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10415|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
( t8 y. d1 P, F) l# ^& d$ C2 Gsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行. \3 o) Y4 r8 b& c
7 j6 w" M# E. g$ ?/ C/ K* T; @
似乎缺少了一个SwarmUtils的类,不知道怎么回事
) s% f( ^& t; h+ D( x' w' B3 a# R
2 ]3 L- Q0 O6 z0 Z# z4 D朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;, E; p8 {* O+ b
3 l# n% t; S, c* Q+ l% ]0 R' ?
public class SwarmUtils {
9 d+ r2 M" u2 J1 Y  C! W' R7 P. {  public static Selector getSelector(String name, String method) {3 j. x6 s" y3 C: Y3 ~
    Selector sel;
7 H1 T" Q7 w; A4 |8 ~: O/ t    try {
5 g( s. V% i+ X1 H; r; K3 U, L      sel = new Selector(Class.forName(name), method, false);
. ^: K) D/ X' u2 d' h' D4 i    } catch (Exception e) {
8 V8 ^" P' a, w& B/ ?" V' c/ A      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");4 F3 K  F8 o6 _/ ]3 \
      System.err.println(name + "." + method + " returns " + e.getMessage());7 c5 q3 y# z+ W
      System.err.println("The process will be terminated.");
6 t2 p$ d4 i8 v* O6 {) |6 D      System.exit(1);
& ?# Z% m6 t: B1 i2 y      return null;4 y1 B5 M/ p5 Y4 d* Z5 \, T
    }0 |! ]# ~! g9 a. B0 S2 u/ p
    return sel;: c. U! T8 K6 n
  }$ j. d7 q1 P$ m+ Q
8 `2 E8 x+ p/ t5 a! L6 |, u" M0 w
  public static Selector getSelector(Object obj, String method) {0 Y" ^8 @' p8 _; P6 Z1 D: l
    Selector sel;7 w5 F% F9 u7 @* e$ f" h: D$ ^9 @
    try {$ L/ V/ i% ^* K4 q
      sel = new Selector(obj.getClass(), method, false);
( `+ A: P8 Z( Q! r, p    } catch (Exception e) {
5 M7 N, }, G: U0 Z  j      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' V# W5 `4 c6 @" d# h3 @          + (obj.getClass()).getName() + ".");
+ t/ k4 `& k: O+ c: X# J% |; w      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());8 R1 F& r: X* u6 q" f
      System.err.println("The process will be terminated.");
# y8 B4 F+ Z/ D4 _8 l" N( `$ @0 s      System.exit(1);# f  }+ D5 d, {# R
      return null;
0 }/ D% f, v. X9 M) v( L4 T    }
3 h# \. v: |, n( c    return sel;7 E! Q# A# [, C) G' e4 h  T( r
  }
, D: i  _) L: q/ e/ q& @4 Z}

评分

参与人数 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-13 21:02 , Processed in 0.017907 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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