设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9495|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行2 W2 i7 v4 s6 t2 }0 U) \7 U
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行0 Z! |7 U, k1 m" C% G0 ?

) I. Q; [/ j" A5 M8 v2 u7 X似乎缺少了一个SwarmUtils的类,不知道怎么回事 % P% t  Q2 [% z4 E

* k! {& G* l* P3 Z, e9 q( s朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
! T0 ]# r" ]9 b$ K4 X; I
% }" v2 d; _3 c/ V# k4 L% Hpublic class SwarmUtils {0 |) t6 A7 {0 k
  public static Selector getSelector(String name, String method) {
( s; Y  X  Y9 R$ O; d) r. X5 h    Selector sel;
& }) Z% ]8 B# A4 ?1 q/ v/ S" M2 b    try {
, [9 Y# I; e& ]+ ^      sel = new Selector(Class.forName(name), method, false);
9 F% m+ `& D& D: R/ p; l& w    } catch (Exception e) {
2 A2 i, |0 t4 |9 c      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 n3 Y2 c6 _- ]  j/ @/ ]1 w  p& G$ o      System.err.println(name + "." + method + " returns " + e.getMessage());. X  c9 R: O+ G' Z4 i: x3 P
      System.err.println("The process will be terminated.");
. H; w6 ~0 K: Z5 l! H' y7 Q      System.exit(1);+ m( k6 m6 a: P8 x
      return null;6 q) e! ?5 v' f4 b5 m
    }  ?6 R( g+ y2 m4 U0 M0 h& I  G; V
    return sel;4 D5 c' ~) s7 I7 i9 O/ u
  }
; t% I- u: E4 J' z' j  _+ U- @/ T7 Q
  public static Selector getSelector(Object obj, String method) {
6 F3 n6 x5 t2 }3 K. m    Selector sel;
, R7 u1 m! O" [7 n8 R    try {- F8 N3 Y1 V9 ~
      sel = new Selector(obj.getClass(), method, false);
2 V% Q% i. h( o- C- H    } catch (Exception e) {
! n- @: ^  r3 t( S# v! s8 [; H3 z      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
% ]- x& [, K: p+ f2 }, s          + (obj.getClass()).getName() + ".");0 x0 N7 s2 l5 G' _6 Y& Z  e
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 \. F5 z; V! o4 d
      System.err.println("The process will be terminated.");# F8 U7 q3 Y) w
      System.exit(1);
; Y, u1 u1 O0 q6 Y      return null;
$ \  q( n' s  ]0 F6 e: W: G. k    }
& u: d# T6 I& V& a    return sel;
! G$ X7 F2 `( D) H6 b2 N- d  }
# @' {/ T* x' i0 Y+ I8 P2 ?) H}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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