设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9829|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
4 p  ]; Y( M4 u2 ?sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
5 w, |- d+ F# x" x8 h/ G
' x5 F7 h2 n# r/ b似乎缺少了一个SwarmUtils的类,不知道怎么回事 + L+ b% {$ o$ A+ ?* U" [

8 I3 R$ _4 ]' L1 x" U* z朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;3 U  I/ Q+ t" K6 \$ ]2 r

! c1 w# O) ~- i+ i$ apublic class SwarmUtils {( A/ ~/ {" G* S4 t7 [% q: j; `
  public static Selector getSelector(String name, String method) {
8 O: v+ b2 m4 s$ l! T5 O, Q, ~+ V    Selector sel;
4 b1 u, B6 r! J, l" q    try {: Y5 e& z" `% a  q  s* {
      sel = new Selector(Class.forName(name), method, false);# ~' u/ ^- J: \
    } catch (Exception e) {. B: N" G9 z, M. }6 Q
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");6 ?$ d$ A9 w6 z* \
      System.err.println(name + "." + method + " returns " + e.getMessage());# D9 P0 S7 A. I
      System.err.println("The process will be terminated.");0 [9 @) Z2 |6 c  Q  @; ^
      System.exit(1);
4 X) B- [2 G- e) O  y# s$ m' G3 @      return null;
! F' k1 R4 M! r" V    }* X% k, j% j' X' J1 Z; p
    return sel;* y) o3 S. j& }- \* V! G
  }
  `  s: v( z. V
$ ~6 y0 _, [6 v2 f2 t+ H/ S: h  public static Selector getSelector(Object obj, String method) {8 c7 G, c+ u4 F5 M! l
    Selector sel;
) z; G4 P! q$ e  D2 M8 M    try {
; Q& y# o3 A( @1 q% c      sel = new Selector(obj.getClass(), method, false);
& m9 x) j$ J  \7 N; f    } catch (Exception e) {
3 }5 r6 G( z% I  p1 @/ q; \* }: g      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' B$ G* }- N( j% Q( d# v          + (obj.getClass()).getName() + ".");4 V) K# Z6 J* L8 [; J* G6 l
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# n0 Y) _7 i, B) O      System.err.println("The process will be terminated.");
# G) G5 _% {/ S, O1 e* l2 r      System.exit(1);& y! \$ ?3 J! r- w6 L( n; u7 S
      return null;
1 v/ c# ]; q8 j6 ~; d    }2 d& r7 k- q6 a( z" [% s
    return sel;" k8 t1 f3 {& Z; |( w& \+ o0 V7 d
  }
6 m# Y  i) A1 T" m# j}

评分

参与人数 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-6-13 11:02 , Processed in 0.015967 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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