设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10286|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
( W' K9 Z8 p1 M9 Qsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行( U/ m, z, q# w: W. e

5 l/ t9 t  \9 q6 ]似乎缺少了一个SwarmUtils的类,不知道怎么回事
, H* [' V6 G' y& L) w7 w8 d/ L) K3 c$ a
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;4 k  K7 g. b6 i( G- x
/ w* i+ t/ I( z) {4 i% H6 k6 A
public class SwarmUtils {
. k4 y3 z; Z/ ?9 e4 `) c  public static Selector getSelector(String name, String method) {  a! Z5 c) ], A+ @) J
    Selector sel;4 ^6 S# c  ~5 P+ ~; k3 S6 z) p
    try {" {9 q7 a2 |% E2 G* ?+ p
      sel = new Selector(Class.forName(name), method, false);
  K$ M. R0 {" J( ]! ]4 h7 ~9 C8 ]    } catch (Exception e) {+ _3 k+ g9 N, p* B
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
0 I( B( x- Z2 ], c1 G- R2 G      System.err.println(name + "." + method + " returns " + e.getMessage());2 \% t4 B7 d8 A+ b& h* e8 N; A' |
      System.err.println("The process will be terminated.");
6 `) K* @5 c- S! ?      System.exit(1);
7 I& P3 D( f7 V% Y1 x  ]% T      return null;- M; W% q# p$ m# b
    }
' j7 e* X- B5 ?  b# k$ Y    return sel;/ |- i* N7 R" U  m1 {: m! z& q6 u
  }  |) }4 }- O1 J# {+ A
( ?" V# F% O" k; k/ p% F
  public static Selector getSelector(Object obj, String method) {
9 b! O2 C0 B# }# ]0 e    Selector sel;' ~4 A! ~3 U. L, d) u6 `2 i
    try {
4 g& Q1 \, N" n  J3 B      sel = new Selector(obj.getClass(), method, false);. v1 r2 T) v+ n7 Z2 V! u' _
    } catch (Exception e) {
% l, ]# j2 u0 m! ~- S+ }* w      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ": j3 l0 N7 d9 l- D# g; N! r
          + (obj.getClass()).getName() + ".");
5 ~' U6 k9 J4 U$ x# J      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 D5 ~% S$ M$ k. Y. n      System.err.println("The process will be terminated.");
- c- _$ _+ R+ ~/ s. s: `. u      System.exit(1);/ }& a  I7 \: h1 C3 U: ?
      return null;; k! B( V+ ~" u; b4 v9 q/ Z
    }0 n3 A6 W( }) P( _" `+ W
    return sel;
2 o# d- Q; P8 m7 M7 X  I/ P  }
. B9 `. k+ a3 {8 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-7-31 04:32 , Processed in 0.017196 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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