设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9228|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
7 @; x9 P" P# w6 H0 Bsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行6 R3 H  f% \9 R

- O, j- h! T3 H8 f+ E: X/ T似乎缺少了一个SwarmUtils的类,不知道怎么回事 : x1 C7 S7 W' m. \4 E
) h- d" V' O# z  j) ]) q
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;; c3 e( e$ M6 h) \1 p, A
# S* f3 e% W3 S4 `5 t% h, k" `
public class SwarmUtils {
9 V$ C- b. R2 V2 m  r/ w" n  public static Selector getSelector(String name, String method) {- z- \8 ?$ Y& D
    Selector sel;( B  f) E/ x  v. t5 \
    try {7 q' S, ^) V) Q) j7 J1 _* h
      sel = new Selector(Class.forName(name), method, false);
! a; N8 v# T- E/ Q    } catch (Exception e) {
: ?( k& y, a3 e  t; A9 n: V4 I8 l$ v      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* W: U/ ]9 T" G2 D2 h' [& c" s
      System.err.println(name + "." + method + " returns " + e.getMessage());
2 Y; x; [+ f; x7 q8 T, A& ?& ?2 N      System.err.println("The process will be terminated.");, b4 ~: u9 h! f3 d( e
      System.exit(1);
( z: V3 R7 j" J6 j$ Y, o: m      return null;9 U8 [0 a9 G6 q' w
    }) G5 J2 k8 @: x! _3 {
    return sel;" q& A) t2 ~4 |$ S% y' Z; g
  }+ P) M! }2 q# W4 H3 M
4 z9 O" z$ S0 Q( L6 Y5 C' p' g
  public static Selector getSelector(Object obj, String method) {$ n8 m9 s0 v' H$ s
    Selector sel;
7 G7 J! V$ {4 B3 f' x$ P    try {
- t1 n5 A: h5 x      sel = new Selector(obj.getClass(), method, false);& y' A0 K$ Y$ @& V
    } catch (Exception e) {+ N! |- P% z5 f) t/ D3 Z* ?4 |
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ f3 y9 g+ q! F4 R
          + (obj.getClass()).getName() + ".");
7 a, x: a! Z8 Y1 F( {- R5 a      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, l: l. c& _& j& p
      System.err.println("The process will be terminated.");
+ s) P0 v9 I2 n1 B      System.exit(1);6 o7 a# b7 o( l4 F+ E' g0 ?" j) a
      return null;
3 v, x6 @9 p) n/ ?$ x5 G" y! t5 }; E    }0 R8 D, b! |% k# F! W
    return sel;& X% |- v' n6 H' l, V7 p/ w
  }0 d8 h  k! W# e! ?3 X
}

评分

参与人数 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-3-30 14:14 , Processed in 0.033997 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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