班哥的专栏

班哥就是班加罗尔,但班哥没去过班加罗尔。

陈先波ID:turbochen
189908次访问,排名371好友0人,关注者0
turbochen的文章
原创 79 篇
翻译 0 篇
转载 23 篇
评论 145 篇
班哥的公告


Locations of visitors to this page
最近评论
ninolilin:hen hao zheng shi wo xiang yao de
qqj007:很感兴趣,正在学J2ME,能否发一份给我,我邮箱:0775x@163.com 谢谢~^_^
yangzhenYZ:流氓?现在问题是你买了内裤人家确把你小鸡鸡的大小尺寸,规格形状(可能还有图片^_^)传到人家数据库里了。

这个贴切的很啊 !!!!!!!!
wangpancom:班哥,你好,小弟最近正在学习BeahShel,由于上网不方便,不能经常上,你能给我发一份你学习时的总结吧?先谢了....QQ:413819965
wangpancom:班哥,你好,小弟最近正在学习BeahShel,由于上网不方便,不能经常上,你能给我发一份你学习时的总结吧?先谢了....
文章分类
收藏
    相册
    等待图片
    深圳反日大游行
    文章插图
    五子棋游戏画面
    Framework
    Hibernate
    Struts
    开发工具
    Ant
    Eclipse
    JBoss
    Tomcat
    实用组件
    BeanShell
    JasperReport
    JDom
    JFreechart
    友情链接
    IBM DeveloperWorks
    Java.net
    JavaLobby
    JavaOne
    Java憩园
    TheServerSide.COM
    榕树下
    黎明时空
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 Java的秘密:Swing的实用工具收藏

    新一篇: JAVA的秘密:AWT机器人Robot | 旧一篇: 设计模式:利用Command模式实现无限次数的Undo/Redo功能

    Swing提供了许多的在Swing组件内部使用的实用工具,SwingUtilities类就是其中一个。它提供了许多的涉及计算、转换、访问控制、布局等方面的方法,这些方法已广泛的应用在各种Swing组件当中。当然,我们也可以把它拿来应用到我们自己的程序当中。


    下面我们就来了解一个这些实用的功能.


    (1)转换方法
    MouseEvent convertMouseEvent(Component source, MouseEvent ourceEvent, Component destination)
    将一个鼠标事件从一个组件转换到另一个组件上。
    Point convertPoint(Component source, int x, int y, Component estination)
    Point convertPoint(Component source, Point aPoint, Component destination)
    将一个组件上的点坐标转换成另一个组件上的坐标点。
    void convertPointFromScreen(Point p, Component c)
    将一个屏暮坐标点转换成一个组件的坐标点.
    void convertPointToScreen(Point p, omponent c)
    将一个组件上的坐标点转换成屏暮坐标。
    Rectangle convertRectangle(Component source, Rectangle aRectangle, Component destination)
    将一个组件上的矩形坐标转换成另一个组件上的矩形坐标.


    (2)计算方法
    Rectangle[] computeDifference(Rectangle r1,Rectangle r2)
    Rectangle computeIntersection(int x, int y, int width, int height, Rectangle dest)
    Rectangle computeUnion(int x, int y, int width, int height, Rectangle dest)
    int computeStringWidth(FontMetrics fm, String str)
    boolean isRectangleContainingRectangle(Rectangle a, Rectangle b)
    上面这些方法计算两个矩形之间的差集、交集、并集,还可确定一个矩形是否包括了另一个矩形,以及计算一个字符串的像素宽度.


    (3)鼠标按钮信息
    boolean isLeftMouseButton(MouseEvent anEvent)
    boolean isMiddleMouseButton(MouseEvent anEvent)
    boolean isRightMouseButton(MouseEvent anEvent)
    以给定的鼠标事件来判定按下了哪个鼠标按钮。


    (4)访问控制方法
    Component findFocusOwner(Component c)
    取得给定组件的焦点组件.
    Component getLocalBounds(Component aComponent)
    取得给定组件的范围(Bounds)信息.
    Component getRoot(Component c)
    JRootPane getRootPane(Component c)
    取得给定组件的根窗格.
    Window windowForComponent(Component aComponent)
    返回一个组件的视窗Window.


    (5)组件绘制
    String layoutCompoundLabel(FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap)
    String layoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int rizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap)void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h)
    这两个方法用于重新布局swing按钮和标签上的文本和图标.
    void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h)
    void paintComponent(Graphics g, Component c, Container p, Rectangle r)
    在任一个图形上绘制一个组件。

    要了解更多的SwingUtilities中的方法,请查阅JDK文档javax.swing.SwingUtilities.

    也可以进入Turbo Chen的技术专栏,看更多的Java的秘密系列技术文章.

    发表于 @ 2002年05月22日 10:19:00|评论(loading...)|编辑

    新一篇: JAVA的秘密:AWT机器人Robot | 旧一篇: 设计模式:利用Command模式实现无限次数的Undo/Redo功能

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © 班哥