设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10583|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
* o' Z, n3 ~! L. s9 U" Rsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行& _& e) z* Q5 ~* L2 w7 S
: K4 K0 l- r5 j( d* a2 B
似乎缺少了一个SwarmUtils的类,不知道怎么回事
9 K  {. l  s( u7 o
( \/ ~: I! I7 {+ N- L8 P! V) e朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
+ o/ f1 @/ K1 e% S) S7 W* Q7 V) w. d& e: t5 W$ E; E+ `
public class SwarmUtils {8 Y( c' \$ {& h
  public static Selector getSelector(String name, String method) {
# z9 g1 F) L' ~+ i9 p; j8 f3 S4 Z    Selector sel;
0 [+ v% g& y/ K/ g    try {& |) r5 ~/ I! @; r
      sel = new Selector(Class.forName(name), method, false);
) G% V/ L4 b. d" _3 Q# m% G  a    } catch (Exception e) {
& R: H, L- m0 J& _      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) W; ~, X, T3 Z3 m8 x' c6 |* v      System.err.println(name + "." + method + " returns " + e.getMessage());; s2 T- g3 S5 h% r/ P1 `8 y  S
      System.err.println("The process will be terminated.");
0 T: L$ J& l- L. d5 L      System.exit(1);
2 l6 n* }2 u8 Y$ F- Z9 [      return null;
! Z1 Z( `3 S- Z* N/ G" S( _9 A    }
8 X8 y2 c2 g5 r8 I, {$ A) |3 n    return sel;
; l: i, s& v1 V  }
" M9 _$ _* B  `5 U* @! x
  {+ [7 e) K3 ^( t; V  public static Selector getSelector(Object obj, String method) {. Z! y0 \9 t# u) O
    Selector sel;
& ]; c. T# a! A7 T    try {
4 b5 j, g  T. A/ ]! q) I# k. k9 g      sel = new Selector(obj.getClass(), method, false);
8 |5 I* e- e( }    } catch (Exception e) {0 V4 z3 _; v  C% s& J
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 n, h' q/ ?/ b; m  q0 }' C
          + (obj.getClass()).getName() + ".");
! p- V# ?5 m% M$ c      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());: k) ^0 f% K, A' v( |# H
      System.err.println("The process will be terminated.");
: [& d# I/ K: O" x+ l      System.exit(1);
; A3 @: L3 l4 i. T3 m      return null;, ^. X7 o+ G3 @% @8 E4 n
    }
3 v8 h. T% v& p    return sel;2 D: D) F1 [9 h3 V
  }7 f9 D1 [7 r) p  D" N
}

评分

参与人数 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-9-5 18:56 , Processed in 0.019654 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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