设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9633|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
7 k9 l; W+ x; T2 @+ o0 V4 n5 ]: }sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
1 F) R5 H+ v- m% j* z7 n$ n) y) c( w5 a% s0 d
似乎缺少了一个SwarmUtils的类,不知道怎么回事 3 T7 x" j8 ~& a4 t, D2 R$ h

* r% Z3 ^8 O( d' H6 C$ H朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
, r+ {2 u9 v* ?0 K; q1 s# y6 o3 X
/ z; g) D% {! m. s1 |, W& d  Z5 D8 Epublic class SwarmUtils {
% l9 r  p, |0 B) L+ w  public static Selector getSelector(String name, String method) {- J) i, }; U  L0 T* D' M
    Selector sel;
+ L( X2 e. @1 X& e+ Y    try {
& r3 R7 R1 c9 i) ^6 i) K$ y      sel = new Selector(Class.forName(name), method, false);6 f5 t- j$ j2 v- G3 f5 F
    } catch (Exception e) {
; b& [2 {  w; u7 j. N      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");5 E) I" w! B: a  ~9 s9 {* J- i
      System.err.println(name + "." + method + " returns " + e.getMessage());/ H2 f7 \4 a/ h# I, R
      System.err.println("The process will be terminated.");
5 P( U+ I( A1 \# Z$ ~      System.exit(1);
& ?3 w: _/ t$ }. l6 f' c3 P      return null;; i6 n2 M: ?) y( ]# J5 \- {
    }
, B' c/ l" ~8 t  H8 b" ^7 G    return sel;: B7 j1 t. N( ~' W" u2 v+ U; b" j- X
  }# k6 w: V- S( z$ g: G% g
/ L. h7 I1 a  C9 Q6 a0 R
  public static Selector getSelector(Object obj, String method) {5 B( v+ |! H# A5 Z% _
    Selector sel;
$ h* w% Z, e- C    try {
# r9 ]6 O: l/ x% v7 T7 @9 u      sel = new Selector(obj.getClass(), method, false);4 W$ r9 j& r8 T3 s2 Q/ {, O
    } catch (Exception e) {
3 B: |9 o5 L9 r0 c% Z! u6 A1 X      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- [4 r6 n1 Q  E8 M# n8 w          + (obj.getClass()).getName() + ".");
! z1 a, H, F3 }- D$ S5 b5 @4 _' Z      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* C. V0 T: X& _+ }! p$ D
      System.err.println("The process will be terminated.");0 U5 @2 v0 X. M' Y
      System.exit(1);6 g6 I& p0 ^: X1 o. y0 B2 L# i/ j. d
      return null;3 M: `3 W# p" s& Z  H
    }
0 i+ g8 @) G6 j% b8 S8 W! D! ]    return sel;
! H, [5 \' {& b3 ~7 t7 T( n4 P  }. C$ v; B  q  F; O
}

评分

参与人数 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-5-15 19:24 , Processed in 0.014729 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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