设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10430|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
$ {& |$ X, i5 F. d+ i+ F* Z# tsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
; t7 w2 K, ?9 u# M8 ?. v  e0 E2 O1 J6 D, m
似乎缺少了一个SwarmUtils的类,不知道怎么回事
* n( d+ L) [" }1 v1 w) P) U# H3 @  w" [" _  u8 g6 o/ s0 K) Z
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
# K7 a$ L( S; y5 H9 }
8 Z( Q. @4 U" L, d' N& ?$ v4 rpublic class SwarmUtils {! `% A  s' S- t2 t6 k
  public static Selector getSelector(String name, String method) {+ T+ e; j" L, H# f& X8 E
    Selector sel;8 l* l. U) y. y
    try {
- Z9 |( N; R* a; D* `& x; |9 ^      sel = new Selector(Class.forName(name), method, false);* C0 P3 r3 s: l! t8 ^! P) f7 P" {  w/ M
    } catch (Exception e) {6 l; g2 z3 Y5 ^  R
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");$ v0 a: k1 k, p+ L, K: o& R) b& R( N
      System.err.println(name + "." + method + " returns " + e.getMessage());
, a9 g7 [' w: W# {1 J) A! q      System.err.println("The process will be terminated.");0 f6 B3 |, |# `0 t, E% _
      System.exit(1);2 A2 O# Q8 i5 O
      return null;6 X$ u% B+ S) c( v% g
    }1 U9 ^. S% c8 G: |) m
    return sel;4 ]/ n! ?! Q: G9 p8 U1 R. k) n5 t
  }
5 v; J  w5 C4 I
6 {3 M" c" N2 v( o1 {  P1 y  public static Selector getSelector(Object obj, String method) {2 c* s! k6 c8 Y" ~0 j
    Selector sel;
/ |9 B$ H" E: S2 H+ q    try {
& `4 \6 U+ i/ g7 X! j& n      sel = new Selector(obj.getClass(), method, false);
+ O  Q' d2 C7 Z6 m3 w9 k/ ]9 `    } catch (Exception e) {+ j$ u0 {# a( A2 @& J6 O& D
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ W3 `6 y- l8 h( a: O/ T1 J          + (obj.getClass()).getName() + ".");
( X, e; s9 G  J# ], |      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" @* r1 O8 W# S
      System.err.println("The process will be terminated.");) d: f& X. h8 J1 }# l7 G$ o9 Q
      System.exit(1);9 V0 @! B, ]# y% j+ l9 M  ]! s( C# x
      return null;
- q) l# ]# n- {2 P+ g% K    }7 D0 B" K3 i7 z; ]
    return sel;
0 ~2 L8 b& P! X4 s& @$ c  }5 p3 h. ]6 e- f, \
}

评分

参与人数 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-16 04:43 , Processed in 0.018115 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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