设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9947|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
5 q9 n( {' h5 k, Csel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行* Z# k! Z2 L6 e5 K
5 P% {2 r& g, `% n* h
似乎缺少了一个SwarmUtils的类,不知道怎么回事
5 g; x' q0 I+ G4 y4 P+ Q; {6 g  r1 v$ T
% V5 e- k$ Y; @, h) I朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
8 p: E0 e* D7 Y$ ^) L9 ^
# y1 y) Z1 D& \% m% [public class SwarmUtils {
7 q2 M' M# T& {$ M/ ?, S7 I  public static Selector getSelector(String name, String method) {
, \/ B5 i0 O+ j5 {    Selector sel;  [* p" i1 k3 i% E+ `3 ~
    try {4 C/ s% }" Q) Q5 k8 J0 ?2 ~
      sel = new Selector(Class.forName(name), method, false);) E/ G8 o- i2 o8 k9 X: j
    } catch (Exception e) {; k9 `, ]  _4 ^, c' s
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: h% F8 s1 [( i/ s      System.err.println(name + "." + method + " returns " + e.getMessage());" k4 R# [8 L. d" E" Q: ?! t
      System.err.println("The process will be terminated.");1 d8 b/ s, U/ }
      System.exit(1);- a( F- b; V2 }: t. Z
      return null;0 I' g! A9 e% m- u* C; G- Z2 H
    }
( B, A) E8 U9 Q% v. y/ R    return sel;
' M/ s( A9 y% a  }! G, y' ]$ T. _, ?
$ v& s+ `( E) b% N! V; c
  public static Selector getSelector(Object obj, String method) {% }  T- E; W4 ^1 \; x# |0 z2 B% ^, Y) Z" ]
    Selector sel;$ ?. }9 q& o! y4 L6 H, u6 e" e2 Q- Y
    try {
% b! b- \- n% ?) c- L3 T      sel = new Selector(obj.getClass(), method, false);
+ c3 r! V4 j4 |    } catch (Exception e) {
1 ]( R& p6 s/ D' ]      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
% z4 `7 n1 K: p; ^' K+ |. K          + (obj.getClass()).getName() + ".");
- G7 v! M1 I3 l( ^! L: L! J$ a" P+ l      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( {  m% O8 P% l      System.err.println("The process will be terminated.");' Y6 `4 s. G/ J) O8 w) p
      System.exit(1);# V0 N, ^% P9 [# y; h( G/ l8 V
      return null;9 y# A9 Z7 Q! I8 o7 [! m
    }" Y7 j8 s+ J& i4 p
    return sel;7 Z0 x9 {3 U, C) a7 V/ i
  }
  U2 U& }, Z5 d" V% S}

评分

参与人数 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-6-29 22:59 , Processed in 0.012723 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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