设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9341|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
3 Q: A! w; A6 s& S% @# Qsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行+ e: b  e3 l: I2 O) u

6 s( ?  g! U* I/ p, w: n; H似乎缺少了一个SwarmUtils的类,不知道怎么回事
4 {* t* g' i% G- }* f7 q5 s! f+ C9 t7 U7 U2 O2 d
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;, J$ `8 K8 n" _
3 F# E/ U5 Z2 m
public class SwarmUtils {; @& r/ j: y; S, {. G: W; j
  public static Selector getSelector(String name, String method) {5 G. [% [$ D4 S; n; m
    Selector sel;4 r# x3 e3 V- f8 W; Q
    try {
& ~; }9 [( N7 U      sel = new Selector(Class.forName(name), method, false);
4 k2 @2 T& i) B# f2 J/ D    } catch (Exception e) {8 e' j1 W9 G8 V5 M/ o7 p
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 p! W1 O/ L$ s' A% I      System.err.println(name + "." + method + " returns " + e.getMessage());+ r) ~8 k' D1 D2 ~: ~
      System.err.println("The process will be terminated.");
! M2 T& V- _, F, H7 r2 q: r      System.exit(1);( {4 |$ J- H: B5 T2 _
      return null;
9 n* [/ T8 v' P    }
9 g" V. |, c6 r. t    return sel;
5 o/ [0 s4 @0 p" d9 Z+ H; S3 ]: z  }- n0 B( p: _. ~3 m& u* o

* o) h. H' D( r5 j# r  e. m  public static Selector getSelector(Object obj, String method) {
+ @4 H$ Z# u  X/ X* q# M2 Q    Selector sel;
5 Q4 A$ w! s) h, U    try {
( i1 m) H# m3 T) s      sel = new Selector(obj.getClass(), method, false);" V2 C' ]! d" j1 [. W; f5 E) p
    } catch (Exception e) {" `7 A+ b6 j3 z0 x1 r: ~
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
! l% ]8 P: _/ n) o) e          + (obj.getClass()).getName() + ".");/ B' q. X& X! n, s( H0 A) `2 S
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: S6 u& C1 e% s      System.err.println("The process will be terminated.");
+ j. n6 N3 l. T: f4 |6 `9 H- g      System.exit(1);
8 U& a; v4 X8 ~      return null;
9 u( n0 w  ]& H  o- S    }  \" n8 M% u' v- T7 [! b( _. Y* H& r
    return sel;
& ]5 @! e+ ^) o# f9 m  }0 @7 f5 \* s1 Q1 ]+ u
}

评分

参与人数 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-12 03:50 , Processed in 0.029196 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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