设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8775|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
/ w2 a+ }  x4 ?sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
/ b, p! v$ e( {: m3 {; a% K9 P, ~: m7 R" D" M3 p0 b+ s5 a
似乎缺少了一个SwarmUtils的类,不知道怎么回事
; L% P7 m. q8 z1 T
, G( K! P) @9 o8 c/ b7 I- D1 ?朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;  N. _: F" x% v. e5 i  U
. q4 t& t9 m. N/ O5 a: I2 i
public class SwarmUtils {
/ ?4 @/ X! U! Y. X6 C$ u  public static Selector getSelector(String name, String method) {
! G. X! `1 [* b    Selector sel;
% O1 @! |/ w+ i0 E6 U    try {1 B4 I6 G, Y3 U& S) l$ ~
      sel = new Selector(Class.forName(name), method, false);
5 C! t( b7 c$ t- h8 u) j- Y    } catch (Exception e) {$ ~" @# |3 q! t3 Z  i) q/ ?
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 W8 }5 B& r$ \+ a5 O) x9 }4 j      System.err.println(name + "." + method + " returns " + e.getMessage());
' b( ~% S+ j$ ]# d" J2 K! u1 Z      System.err.println("The process will be terminated.");
1 y3 x' x& C1 q9 \- x      System.exit(1);
5 Q  C" f- g  O# A# j6 n      return null;
6 E9 Y, @6 E" C4 o& h+ O    }2 e* e& _) T( v. t7 b  L" C
    return sel;
' B0 k# R" ~! }5 ?8 ^2 D* L  }
2 ~3 G' u* `1 C# Z$ i7 y
$ y6 H+ A9 M- d  h' [# `  public static Selector getSelector(Object obj, String method) {
& |; k( R& @5 H1 c( F) e' o% Q    Selector sel;2 z" Z! C) C: V' Q# {# f
    try {
: p- b& {3 T$ l' X' b- ?2 L      sel = new Selector(obj.getClass(), method, false);
* p& W5 o2 s$ {# x, W" t1 l    } catch (Exception e) {
: O& {- M8 W7 R# m      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' M5 B, a/ M9 Q2 K# {9 c          + (obj.getClass()).getName() + ".");
5 _& @( K* L& P. d6 V* f      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% f* Y2 w- W  k. \
      System.err.println("The process will be terminated.");  M2 Y  M# y7 J" f- r0 P& c8 K
      System.exit(1);
3 h  q  z& u' ?! k+ M$ |( Q( O      return null;
3 ?2 d5 k4 P# D0 e# W% P$ P    }
9 Y/ Z" Q' G) E7 ?9 \    return sel;6 G- ^) o* K# t! K* {0 S8 l/ b
  }1 F( A3 C4 H: _# }; `4 _/ F
}

评分

参与人数 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-1-24 20:45 , Processed in 0.017826 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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