设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9719|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行' J5 N: y/ }, Y* [& w, I
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行" S& ^+ b( N  L2 `
" C9 D: M1 M1 w5 G. J: Q2 {
似乎缺少了一个SwarmUtils的类,不知道怎么回事
) n2 {4 z% x2 L& L3 @. x" t0 u) Y2 s6 r* V, Q) ~; y/ ]- M
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;% U: x' k$ J2 Z$ Q' m: B

0 n; y2 G7 a/ f" N' i- Y) cpublic class SwarmUtils {! m! q5 ^1 ~0 {. K: F: I& Z
  public static Selector getSelector(String name, String method) {
! d( Q/ R- k6 K3 W) `" }& h    Selector sel;# W+ i$ u9 H1 e, k5 C
    try {1 B3 h  T% v$ S9 x' M) _
      sel = new Selector(Class.forName(name), method, false);% V( x1 E  M% S6 R- m, A+ a
    } catch (Exception e) {: u- c2 |; q, A3 l  v
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
% ~6 M, j& P6 m' b* O      System.err.println(name + "." + method + " returns " + e.getMessage());
+ ?. o; ]3 [- C, _" |; f      System.err.println("The process will be terminated.");3 R, V$ B1 b9 Y
      System.exit(1);* k$ _$ J7 l6 C& U% t
      return null;
9 M7 m/ i+ q- ~/ s; }" K    }
; V# e) o- T% |: c0 A, w5 i    return sel;9 U# b6 r! m/ ?5 o
  }5 p6 ~& G  p  E& r& C9 o2 ?
5 ?$ m- e; X1 I2 x. F$ m( ]
  public static Selector getSelector(Object obj, String method) {
& ~, E2 a& M; J    Selector sel;
8 B, I( g- c3 a; o, S7 v    try {4 C# C8 Q; {1 c$ o# d
      sel = new Selector(obj.getClass(), method, false);/ S" s& P1 B3 k7 J2 S$ l# ~% j' a9 Y
    } catch (Exception e) {
) b/ G# c# c) g8 h% H4 I      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 G; d  p2 S1 \, h. m2 M          + (obj.getClass()).getName() + ".");
% l3 G% T7 D% z      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
' R- v) [8 b% C  J. c" v      System.err.println("The process will be terminated.");
  e5 W1 I8 C( g4 d( _) x' o      System.exit(1);6 v1 U. k! U( D- L7 z9 a# o- ?  G
      return null;
; C$ c0 F9 n9 u* W6 B7 u    }
+ I$ q) g1 s3 x+ s# e    return sel;
! m9 e* k$ v6 a1 L" y0 P/ p  }
* N  g- j5 ?# o6 w4 }7 }0 R; p7 h& a3 m8 R}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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