设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10323|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
7 N& v. v2 z9 d2 N; Asel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行  S8 T: W9 b) C) J4 }  K' m# V
/ \5 t4 H5 i: J) t+ |* |: f/ u
似乎缺少了一个SwarmUtils的类,不知道怎么回事
8 t/ s* c. Z/ X  l6 _1 n  `
2 ~- B) N$ V8 D5 ]. u% E朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;, E6 U- g+ Y2 E$ ^' h1 V
( a. M2 u1 B! R6 U; U
public class SwarmUtils {
6 O* m& j- \" i3 R8 u& r$ O  public static Selector getSelector(String name, String method) {% U' B4 |1 Y3 x, y. w6 @. s& s
    Selector sel;
, n% B/ z0 v, x+ l( f    try {
, J& \  M8 [. N. o% U' @      sel = new Selector(Class.forName(name), method, false);
* `& t. E( C7 q8 `3 H7 ]& W, j6 r    } catch (Exception e) {6 i' k! w7 t) ?7 A1 l1 s$ E
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 |/ }! T/ M. v4 T7 S+ Z- t5 i
      System.err.println(name + "." + method + " returns " + e.getMessage());3 Y7 F5 ]1 ^" A2 Z& F
      System.err.println("The process will be terminated.");/ E! o1 O8 _+ Z
      System.exit(1);, ?$ t$ A0 u0 ]
      return null;# i. B. u/ ?: \% ^! g
    }
+ g3 W% A, D- T: O    return sel;
: h8 v7 @6 i4 v( Q& V2 n  }/ j+ H+ ?/ @6 }  G
0 [- i7 b0 P! t
  public static Selector getSelector(Object obj, String method) {  }; M5 }' @) [2 ~, }
    Selector sel;" W. }* w5 ]4 y4 ^5 p: p; Y
    try {
+ _, l+ g6 r' b4 N9 k" W9 A      sel = new Selector(obj.getClass(), method, false);
* T2 N$ }4 U% f' J* F    } catch (Exception e) {
7 r9 K6 t0 y) J) L# D9 r4 m% Z      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "0 U- ~6 c1 ^) V, A
          + (obj.getClass()).getName() + ".");2 R  W# w0 `2 x* T  q$ ^5 n
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 b. b' g) e3 u, p/ [      System.err.println("The process will be terminated.");1 P0 D) [- @0 V# A3 {
      System.exit(1);0 s4 e- ?  j+ ^- j
      return null;
+ g7 s& J% f- S7 G8 `: L6 y- e; s% G: g    }
' L, t  w1 s; T* a    return sel;
& `9 I" k6 E; d2 X; X  }" `9 R. H4 K2 V9 n3 B
}

评分

参与人数 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-2 03:29 , Processed in 0.021157 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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