设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9433|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
3 i' T1 C, G7 @0 o, q0 ~sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行" Q( K$ U. S& d- @" J# A3 @
0 |9 Z' T( d) f- S
似乎缺少了一个SwarmUtils的类,不知道怎么回事 1 {6 B  L$ J! x1 R) m
, P+ D7 w) G9 [
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;) h. L# r1 o2 W6 q# ]) c
7 c7 q* J/ Q$ [- G5 L- `
public class SwarmUtils {/ s0 S) J& T* q
  public static Selector getSelector(String name, String method) {
0 Q# N; q! z( o0 \) R    Selector sel;, w2 ~: m/ E( V6 k- Z, V( [" r
    try {
8 n3 L: H. f5 Q# T# q+ S      sel = new Selector(Class.forName(name), method, false);
' I5 T1 m) X, y+ j+ Z7 ^    } catch (Exception e) {
8 j' D9 T9 A! I      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");$ t: A. x  i+ S1 F4 h9 f+ o% T
      System.err.println(name + "." + method + " returns " + e.getMessage());
0 A( A* c8 _( A  n$ a/ f! T      System.err.println("The process will be terminated.");
: h* h: n3 }& ^      System.exit(1);
! C: ?" R! r6 l5 A' u1 o      return null;3 \8 ?# \1 C+ Z- S
    }. T  E- [% V: s, S, W
    return sel;0 E  [/ M# a! E! J, |% d
  }
/ N( v# k/ t6 @0 @# {& e: V3 @- P( P: o2 o/ H4 ]$ K4 t: q% J8 Z  U
  public static Selector getSelector(Object obj, String method) {% f) M2 X. U, p
    Selector sel;) Z( C4 {" Q! k3 f4 J% f, c4 Q# l
    try {
9 W5 ?; c" L* l1 N      sel = new Selector(obj.getClass(), method, false);( D- {$ _7 p/ t6 v$ T7 k$ [
    } catch (Exception e) {
! M+ Y, o7 ^# G7 Z3 d3 s      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
- b' |+ U4 ?* Y' d# M          + (obj.getClass()).getName() + ".");
5 V- W! j* C: k      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, d5 a8 ^" o/ I
      System.err.println("The process will be terminated.");
$ r" r+ x, B# p9 l6 D      System.exit(1);
; o  d" o3 o0 Y* `: z      return null;2 n7 A+ e- L/ o- A9 Y$ j# V# G  H, e
    }
) n! G  z, J" F: W  p    return sel;1 g- K2 w5 d& _5 }0 a, v& Q. s" @
  }9 F4 V6 E  H2 w1 @' R
}

评分

参与人数 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-23 19:27 , Processed in 0.022640 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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