设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9762|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
( c, @( z% h( v$ z0 z( A; ]" Isel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行8 s9 h# O* K, z4 J" V

) l* X) T1 |# W2 l似乎缺少了一个SwarmUtils的类,不知道怎么回事 $ d" C5 s, b: A+ b) q

, `0 O5 N4 u2 u  i( d' f& M- F朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;& }- I, `( y+ l; {6 ^2 @* I8 t0 Q
4 o0 w% T3 G+ \" s& b
public class SwarmUtils {' ^- ^+ R/ D  h. d
  public static Selector getSelector(String name, String method) {6 y/ D. r+ g" R8 F1 W7 }' h- H
    Selector sel;
  S; q. A' ]: h0 c    try {
6 S( @! ?0 c: v* [" M( z      sel = new Selector(Class.forName(name), method, false);9 k5 b" t4 R  A" ?) b+ }
    } catch (Exception e) {/ h1 [& q9 e1 t
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 y0 \: }- X0 \, [      System.err.println(name + "." + method + " returns " + e.getMessage());
1 g' f+ @9 g# S/ j6 m% L4 [      System.err.println("The process will be terminated.");
1 e1 R7 _. s# x      System.exit(1);
! R$ S5 [* G( U! e4 H9 L      return null;
' {5 B) i2 P2 J% k6 A! n- h    }( ~0 h& E3 |! B0 N3 u: X* t
    return sel;" ~  p! Z9 H: C4 H5 x# V& n1 ]$ ?" r
  }
* K# L! N) _- }# q+ M* u1 R/ v8 x: G" `2 ]' B
  public static Selector getSelector(Object obj, String method) {
2 |# i: h' y# `8 `9 R% J! Q8 @5 }    Selector sel;
$ u; E% y4 O: w" y) q    try {
: G# F" m& f' n      sel = new Selector(obj.getClass(), method, false);2 t: u/ i8 ^5 M$ P
    } catch (Exception e) {, X- [* G* B8 E4 y! c6 L8 w8 }
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "" _/ \$ K" a. @4 D* f" t7 K$ n: f8 h
          + (obj.getClass()).getName() + ".");
! t& O, ]+ `! z0 M. r$ u      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% d+ u9 r- ]  ~: I6 B/ Y" Z      System.err.println("The process will be terminated.");; {0 ]3 F0 f/ @0 y
      System.exit(1);8 b+ [- s7 l) j& W7 }: G. k
      return null;
( f( s* f8 |1 Y& a' p( {6 i    }' V" v! y# }2 D8 t- ?" {5 H$ y
    return sel;( d6 {4 `2 X% @. ?- C
  }( J' ^2 |1 ^9 N" b' M
}

评分

参与人数 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-4 02:08 , Processed in 0.015480 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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