设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8055|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行  O5 d3 ~% o" ~3 ~& }% R
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行1 j: X, k# I3 A  A0 u; J  r
" e% @) Q* ^& h% e. S& I
似乎缺少了一个SwarmUtils的类,不知道怎么回事 / F) A6 w1 v% R; d' m# Q" H' N5 R, J

# N% G, B# I' I朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;! H7 b" Q; f. l: m4 n" V! p9 f

1 ^3 K+ P/ e  H, x; B/ ppublic class SwarmUtils {& B! N( S0 |0 c2 }) J# a+ m+ c
  public static Selector getSelector(String name, String method) {
' T5 P9 d' i6 o$ V& t; D/ g    Selector sel;
0 E$ B* a( \! X" O" M    try {5 t( F4 c# R& X' D4 n& b
      sel = new Selector(Class.forName(name), method, false);
0 Z+ Z# _7 g% O; C( g    } catch (Exception e) {
+ v5 k2 O" [3 O+ |9 {) y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");. E1 _9 P9 o& C: Z3 V4 M
      System.err.println(name + "." + method + " returns " + e.getMessage());4 W* }5 p6 f& J, W* _# E0 Y
      System.err.println("The process will be terminated.");
& I) v, Y! c+ _# l( q" ?! I      System.exit(1);
, i! o5 K/ Z5 ~% u- Q      return null;
  [4 ~6 E0 C6 h! }+ N/ ]0 q    }
+ V( v. h- p: c: E, u! @    return sel;$ f# b3 o: ^* B. d! `
  }
6 {3 u4 y9 Q7 r: H' s( D% G& |
, K, ~7 m* U0 g; y. V" @  public static Selector getSelector(Object obj, String method) {
( y- [4 i5 `% O& O! u5 a, T0 i: W    Selector sel;
" A* B3 F! @/ R    try {
7 ?3 R( i8 f5 [' H& m      sel = new Selector(obj.getClass(), method, false);7 I- g6 V# x& y6 S. n
    } catch (Exception e) {
0 K; u! a* v& \' g, X. ~+ w1 R      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "* U0 h. q- L( V& L' a0 T" d
          + (obj.getClass()).getName() + ".");
: U6 Z& v& @3 b, a3 t      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, Z" Q+ i' z2 i; R; h
      System.err.println("The process will be terminated.");
$ j8 Z; A$ u/ t) J) ]7 B      System.exit(1);0 [+ x  l* r- f& z& O
      return null;: H- `; [7 T- n5 a0 P+ i/ U
    }
  J6 u& v$ P; ]. {# o    return sel;0 `" [6 t  p  @& x% ~+ H
  }3 `6 n: s" u) E; `
}

评分

参与人数 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, 2025-9-13 18:36 , Processed in 0.015443 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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