设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10332|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
; L+ j5 A' J6 Psel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行: F6 d1 a$ x4 }4 b$ u9 p" V' r

( i0 C$ S3 Y& _& O2 r4 P% x似乎缺少了一个SwarmUtils的类,不知道怎么回事
9 A2 _- e1 `0 c" {1 j4 E3 Q& s) p7 {7 Z! s! K9 @
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
% F- P/ U: U$ t  x0 P& A. ~6 O/ D2 x4 o5 l# [3 z& G! \
public class SwarmUtils {
3 a7 w% O4 d4 a2 p  public static Selector getSelector(String name, String method) {
. `% R" R; t$ P5 T; ^8 i' g- G+ j    Selector sel;+ K& n* f9 K" v+ X8 B/ I
    try {9 O" d" P7 x$ |- h5 J! y; f( w
      sel = new Selector(Class.forName(name), method, false);
8 |3 `% v. t  G) M    } catch (Exception e) {
0 b; n! B. C0 F      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# A$ K" c# b2 `' i9 @      System.err.println(name + "." + method + " returns " + e.getMessage());
# f/ H+ l; X$ M9 ]4 L1 A      System.err.println("The process will be terminated.");1 R( ~  s0 e8 |7 ?
      System.exit(1);0 l( h/ O2 |( F' S
      return null;4 V; q6 h) v6 H  _' f5 g9 ?
    }
- s; V; D  L# X  d/ T    return sel;
; y; ^7 m7 }$ O/ z0 c% S, {8 r  n  }' \% `, M! S& r; d

6 j  {8 U7 u/ z& ^9 i1 o5 E) @  public static Selector getSelector(Object obj, String method) {5 e; o: l" l% W, G2 b# |
    Selector sel;
# u% o7 r' N0 j    try {
, n* `) E1 ]. e! z& p      sel = new Selector(obj.getClass(), method, false);
$ P1 A( p/ t$ X    } catch (Exception e) {4 v) m4 t; A5 K. O  w( I) N$ f4 R' m
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 R) V3 ^; c3 E( M, n          + (obj.getClass()).getName() + ".");; f3 Z) o8 n" M7 t5 W
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
5 k7 B# |' E. |( i' N- @2 o4 a      System.err.println("The process will be terminated.");% d8 |6 x- E$ j: k& e- A
      System.exit(1);# R# `: N: v2 }  y" d& k$ C
      return null;- Y$ o/ n4 L; @; L+ N! S
    }
7 X" B' w. R" V6 K  l2 S1 K    return sel;: c/ a8 a+ B9 T2 R7 @# x" E
  }. G. Y4 L" ~, r; ]9 e3 B7 X+ S# w
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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