设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10579|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
7 C, Y* Z, A- e2 A+ ~' {3 E1 bsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行2 s6 F4 e9 n5 H$ D3 W6 n; I
  [. K7 c9 Q- N8 b1 `: Z/ \
似乎缺少了一个SwarmUtils的类,不知道怎么回事 , J0 Q) j+ H# G4 Y% o# S3 l

$ Z; u, n3 ~$ O6 r& a$ V朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
9 a1 {8 B8 ^$ H9 l- C6 h- x& ]3 h& G4 R- t
public class SwarmUtils {
2 }% b3 b) U! L  public static Selector getSelector(String name, String method) {
( X2 [1 N+ q4 A; b/ w6 D% K' S    Selector sel;
7 [" J+ q  ]& e/ `9 S! o( j0 a    try {$ _7 h" ]/ R/ W/ z! P6 ^  @9 Y
      sel = new Selector(Class.forName(name), method, false);
. z1 u" c2 J+ A& ]8 p    } catch (Exception e) {
. g/ q9 ^9 j5 Y6 n& U      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
, {1 _: V% d! W8 m8 q      System.err.println(name + "." + method + " returns " + e.getMessage());) o; X, A0 C+ l0 [' u; l
      System.err.println("The process will be terminated.");
$ O1 r6 O  E- H" H      System.exit(1);
2 _$ i3 i2 }# V1 V" t      return null;
( B+ S# N$ t: S; u8 m$ F& L* u    }
7 P, R6 E2 ]+ O0 [7 M    return sel;. i% H/ x4 g, l$ O
  }
  j2 E2 Q# e. f) F  [5 l0 d: e& g/ I+ E# H# f$ T) e# D9 Q
  public static Selector getSelector(Object obj, String method) {- }' ~& S) q$ E0 o& r$ }- S4 K2 b
    Selector sel;
% X% x! |! E9 W. w    try {
9 i  {! P- w' Z, M8 q' B: \      sel = new Selector(obj.getClass(), method, false);. r) y1 e1 c5 _' M# D5 \
    } catch (Exception e) {
. v1 d# b+ Z( [- M      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "+ ^% i* ]+ O( p
          + (obj.getClass()).getName() + ".");
( W9 r, f, S* H' m4 k- U      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
/ [3 K7 O! P) e# C- |  X      System.err.println("The process will be terminated.");2 U! j# P+ t! t( @
      System.exit(1);, o& R( m$ E  d* O  Q
      return null;. l5 ^7 B5 t0 [
    }
# @. ]: l" A" }  A4 U+ y- x& G    return sel;/ G- N+ N6 a1 r  y
  }4 i# r; v  [+ l# \0 H# }
}

评分

参与人数 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-9-5 07:03 , Processed in 0.016490 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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