设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9462|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行7 q! Z- F, n) Y! i2 B
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行1 K; N# o% Y) u1 z

( T+ j! d* p& ~& y似乎缺少了一个SwarmUtils的类,不知道怎么回事 2 w, W) ~% z* {7 z# }: b- N2 c$ x2 D

. ~# f9 Y. ]  q朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;& w/ O# e% h8 m; {" }. E
( U% F# `: Z, {" ~3 n
public class SwarmUtils {
6 L. I( @* k4 q2 W, `8 Z7 t  e9 \  \* @  public static Selector getSelector(String name, String method) {
8 D4 S% v% e% P: ^$ J( e    Selector sel;
( x& f/ p( _  R9 \! e7 ~3 r    try {6 `; {8 w" V* R" R* G9 U
      sel = new Selector(Class.forName(name), method, false);
9 ]4 s3 n. N: b+ _: Z    } catch (Exception e) {
+ U9 V0 G4 v! t) C) W      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
% _8 q8 e& [9 `      System.err.println(name + "." + method + " returns " + e.getMessage());
: W4 D: q% w! ?3 S2 O- t  O8 X" S      System.err.println("The process will be terminated.");
9 C) [4 o! C! W  Y6 i6 ~      System.exit(1);
0 W4 K5 l7 N, v  S      return null;
; ?$ c/ N/ [. u" l. u& f    }
2 e& W# v9 {) T% F: u    return sel;% o- y) S1 X" B8 `) r; _( O3 }
  }+ k) _4 ?  {+ O+ |: I2 ~" a7 l, D; `

: _" H8 }6 h! K; ~# [0 {. }  public static Selector getSelector(Object obj, String method) {
3 ~+ W* h% w% W5 f% F! x/ C    Selector sel;, f& F7 `8 g  I5 Y- d' I
    try {
0 x3 O- b# p7 x" N/ q' }: K0 Q      sel = new Selector(obj.getClass(), method, false);
. C) N+ k' E$ A. o- ?8 L5 H    } catch (Exception e) {# z0 k: c3 g" z9 R* p  B2 _
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "2 M3 C+ ]0 W9 B
          + (obj.getClass()).getName() + ".");* L: J6 ?& S* O& d9 O+ B
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
& l# [) L6 h4 W  U9 C. u& O      System.err.println("The process will be terminated.");4 L* ^  v$ L' d4 X# Q$ z( c; e
      System.exit(1);
5 d9 r+ C6 l5 w( ]) F5 i      return null;
- j. Y9 o+ q, G    }
! s' M' a# F. h" }2 z( N% N    return sel;7 d. ~# }! i2 n/ o2 I; E& x0 K  e
  }
4 L5 X0 x0 l  f# @! r# p( b; 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-4-27 16:10 , Processed in 0.025241 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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