设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10486|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
4 ?: |3 L, N, b, |% S0 hsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行2 [) s8 p3 s" M' T

6 r0 n4 }- W4 y; i似乎缺少了一个SwarmUtils的类,不知道怎么回事
. Q$ f0 _. Q5 w; n
& r5 e/ G& N+ G' z% B朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;; d* K& F' E. G1 D; h9 F

: ]% x) a% r2 ?' r+ ?' g9 W: g& tpublic class SwarmUtils {- r! L* d+ k$ T6 u8 b4 j6 B. }
  public static Selector getSelector(String name, String method) {) L$ r7 X3 f( T7 Q) j6 v+ t9 H
    Selector sel;
. S7 g  p6 f2 G    try {# R5 C/ Y  L1 E: ^
      sel = new Selector(Class.forName(name), method, false);& k  w, ~- a) S6 W- z* x( l
    } catch (Exception e) {
& Z2 i7 r' J! a# m% g* ]      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");' j& G3 q6 I* y/ N( F. Q
      System.err.println(name + "." + method + " returns " + e.getMessage());
7 B5 I7 N/ ?; N1 e/ @' M$ f      System.err.println("The process will be terminated.");1 _" _8 t8 x0 ^1 G% R& n
      System.exit(1);
3 s4 @9 @' R& p* y      return null;3 B+ z  G2 a, _% W6 m$ R0 i( a( D
    }
0 W2 J$ o( p) N5 ?7 F! q    return sel;
" w5 z5 R5 T9 X3 U# B7 e+ x  }% j5 }5 i0 i8 d# s' e% u
: y, R: ?5 u( X  _  k
  public static Selector getSelector(Object obj, String method) {
( v* j. V" y$ n; Y1 T0 q! {9 U    Selector sel;
8 [8 @( h$ ~. Y3 j( Z7 f    try {
$ `) {( p1 d/ U4 O3 m      sel = new Selector(obj.getClass(), method, false);
% _3 t, H) n2 _    } catch (Exception e) {
) L9 y5 `8 N! ]9 H( t      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
! o9 h3 z$ O& R          + (obj.getClass()).getName() + ".");
0 K$ P) P8 R$ d7 r      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% O0 O, ?2 X% d  D8 W2 s' L      System.err.println("The process will be terminated.");
0 O1 B! A' N( Q! R& O      System.exit(1);
- H( A) T% g: x/ z/ @      return null;
7 W8 J) ^) {3 [4 }    }
$ a( H; E7 V% Z8 C+ P8 w    return sel;3 q) I* L6 k! ~; f3 Y
  }
1 I9 s$ g4 v! I$ Z0 d: P}

评分

参与人数 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-8-24 00:58 , Processed in 0.020897 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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