设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9994|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行( c! J, W5 e0 z; _
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
: }5 }% ?' N7 ^* S3 X+ y
  P# d: I0 Z' J+ d5 V, @# \2 P似乎缺少了一个SwarmUtils的类,不知道怎么回事
4 u5 \1 q6 u& I
2 J9 D7 D6 w+ {3 A1 m. I朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
$ z* D3 v' N( I8 K0 |/ N  @6 T3 N) v9 ]* o( Y/ j. g
public class SwarmUtils {, }- J; W$ w# P: n" t
  public static Selector getSelector(String name, String method) {
: m7 J$ s0 z# S) e    Selector sel;* n  K; X5 d; x$ m) K& I
    try {
8 w2 u7 N( ^6 ^$ s8 [1 O7 i! l/ a+ @      sel = new Selector(Class.forName(name), method, false);
5 F! e2 S) F: o3 m  |4 M' M) q    } catch (Exception e) {
4 T7 n* y% w  [  D      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; ^, o/ F+ |; G! K4 k4 z      System.err.println(name + "." + method + " returns " + e.getMessage());
: a  m  |+ _3 J, X      System.err.println("The process will be terminated.");
2 v: r& n. ]/ H+ y* V/ x0 ]* h      System.exit(1);
: H# v7 S  _& {& e/ t3 D, G6 H. w      return null;
  M+ T3 P6 i  K0 f3 `$ }8 X    }
, g, H! Q$ \* z    return sel;5 L9 d0 }1 s1 a/ u7 ~4 g$ L
  }
) Y( v2 g# g0 A* B5 X" V. T  B+ |7 Z0 b( l# s. L2 b
  public static Selector getSelector(Object obj, String method) {
  i8 J3 C1 T6 i9 y* P8 h! `* U4 `    Selector sel;' O! h1 M' p# T
    try {
0 T) T  Y& @, {      sel = new Selector(obj.getClass(), method, false);/ q- _( [5 }7 j/ X1 p) s6 Z+ }! {
    } catch (Exception e) {
% l% Y8 s7 l2 \! ?; {      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "2 p3 V" |. p( B! Z
          + (obj.getClass()).getName() + ".");
  X6 L. E1 Y' K3 c+ H  E0 L      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 Y8 z( n+ d" C" l. r$ H
      System.err.println("The process will be terminated.");4 ~8 V7 c1 G+ w7 L4 }
      System.exit(1);! X/ s7 }9 _0 n' L  q2 x( Z% m+ m
      return null;" [, a8 d8 j3 n' @1 v) N9 B
    }
( o  l% M" w6 Z  P/ u+ a    return sel;! l! @. H0 \5 _2 i3 @
  }- N$ i8 _  y" S0 n" m( 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-7-6 06:30 , Processed in 0.015267 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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