<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Pudgy's World
    posts - 13,  comments - 16,  trackbacks - 0
    一個(gè)Custom Border
    可以實(shí)現(xiàn)點(diǎn)劃線的Border.
    代碼如下:

    import java.awt.*;
    import javax.swing.
    *;
    import javax.swing.border.
    *;
     
    /**
     * DotDashBorder is a java.swing.border.Border implementation 
     * that draws a dotted and/or dashed line border.  The dot/dash pattern is 
     * defined as an array of ints, with every two indices defining the number 
     * of pixels for each dot/dash and space.  E.g.: 

     * { 1, 1 } == 1-pixel-dot, 1-pixel-space, 1-pixel-dot, 1-pixel-space, etc.

     * { 4, 2 } == 4-pixel-dash, 2-pixel-space, 4-pixel-dash, 2-pixel-space, etc.

     
    */
    public class DotDashBorder extends AbstractBorder {
        
    /**
         * Defines a dotted line pattern:  
    . . . .

         
    */
        
    public static final int[] DOT = { 11 };
     
        
    /**
         * Defines a dashed line pattern:  
    - - - -

         
    */
        
    public static final int[] DASH_SHORT = { 44 };
     
        
    /**
         * Defines a long dashed line pattern:  
    ---   ---   ---

         
    */
        
    public static final int[] DASH_LONG = { 1010 };
     
        
    /**
         * Defines a long/short dashed line pattern:  
    -- - -- - -- -

         
    */
        
    public static final int[] DASH_LONG_SHORT = { 6333 };
     
        
    /**
         * Defines a long/short/short dashed line pattern:  
    -- - - -- - - -- - -

         
    */
        
    public static final int[] DASH_LONG_SHORT_SHORT = { 633333 };
     
        
    /**
         * The dot/dash pattern.
         
    */
        
    private int[] pattern = DOT;
     
        
    /**
         * The border thickness
         
    */
        
    private int thickness = 1;
     
        
    /**
         * The foreground color.  If not specified, the component's foreground 
         * color is used.  
         
    */
        
    private Color colorFG = null;
     
        
    /**
         * The background color.  If not specified, the component's background 
         * color is used.  
         
    */
        
    private Color colorBG = null;
     
        
    /**
         * Thicken border pattern relative to thickness flag.  
         
    */
        
    private boolean thicken = false;
     
        
    /**
         * Create a new 1-pixel thick DotDashBorder using the component's 
         * background color.
         * @param  pattern  int[]: the dot/dash-space pattern
         * @param  fg  Color: the foreground (dot/dash) color
         
    */
        
    public DotDashBorder(int[] pattern, Color fg) {
            
    this(pattern, 1,  fg, null);
        }
     
        
    /**
         * Create a new DotDashBorder using the component's foreground and 
         * background colors.
         * @param  pattern  int[]: the dot/dash-space pattern
         * @param  thickness  int: the border thickness
         
    */
        
    public DotDashBorder(int[] pattern, int thickness) {
            
    this(pattern, thickness, nullnull);
        }
     
        
    /**
         * Create a new DotDashBorder using the component's 
         * background color.
         * @param  pattern  int[]: the dot/dash-space pattern
         * @param  thickness  int: the border thickness
         * @param  fg  Color: the foreground (dot/dash) color
         
    */
        
    public DotDashBorder(int[] pattern, int thickness, Color fg) {
            
    this(pattern, thickness,  fg, null);
        }
     
        
    /**
         * Create a new DotDashBorder.
         * @param  pattern  int[]: the dot/dash-space pattern
         * @param  thickness  int: the border thickness
         * @param  fg  Color: the foreground (dot/dash) color
         * @param  bg  Color: the background (space) color
         
    */
        
    public DotDashBorder(int[] pattern, int thickness, Color fg, Color bg) {
            
    for(int i = 0; i < pattern.length; i++) {
                
    if(pattern[i] <= 0) {
                    
    throw new IllegalArgumentException("Pattern cannot have values <= 0.");
                }
            }
            
    this.pattern = pattern;
            
    if(thickness <= 0) {
                
    throw new IllegalArgumentException("Thickness cannot be <= 0.");
            }
            
    this.thickness = thickness;
            
    this.colorFG = fg;
            
    this.colorBG = bg;
        }
     
        
    /**
         * Get the insets for the border.
         * @param  Component c: the component the border is for
         * @return  Insets: the insets for the border
         * @see  #getBorderInsets(Component, Insets)
         
    */
        
    public Insets getBorderInsets(Component c) {
            
    return new Insets(thickness, thickness, thickness, thickness);
        }
     
        
    /**
         * Get the insets for the border.
         * @param  Component c: the component the border is for
         * @param  insets  Insets: the insets
         * @return  Insets: the insets for the border
         * @see  #getBorderInsets(Component)
         
    */
        
    public Insets getBorderInsets(Component c, Insets insets) {
            
    return new Insets(thickness, thickness, thickness, thickness);
        }
     
        
    /**
         * Check if the border is opaque.
         * @return  boolean: true if the border is opaque
         
    */
        
    public boolean isBorderOpaque() {
            
    return true;
        }
     
        
    /**
         * Check if pattern will be thickened by thickness.
         * @return  boolean: true if pattern will be thickened by thickness
         * @see  #setThickenPattern(boolean)
         
    */
        
    public boolean isThickenPattern() {
            
    return this.thicken;
        }
     
        
    /**
         * Set if the pattern should be thickened by thickness.  If true, a 
         * pattern of { 1, 1 } and thickness of 5, the pattern would be expanded 
         * to { 5, 5 }.  This allows setting a pattern based on small pixel 
         * measurements that grows proportionally with the thickness.  
         * @param  boolean t: true if pattern should be thickened by thickness
         * @see  #isThickenPattern()
         
    */
        
    public void setThickenPattern(boolean t) {
            
    this.thicken = t;
        }
     
        
    /**
         * Paint the border.
         * @param  Component c: the component the border is for
         * @param  Graphics g: the graphics object to draw on
         * @param  x  int: the border y position
         * @param  y  int: the border x position
         * @param  width  int: the border width
         * @param  height  int: the border height
         
    */
        
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            Color colorFGX 
    = c.getBackground();
            
    if(colorFG != null) {
                colorFGX 
    = colorFG;
            }
            Color colorBGX 
    = c.getBackground();
            
    if(colorBG != null) {
                colorBGX 
    = colorBG;
            }
            g.setColor(colorFGX);
            g.fillRect(x, x, width, thickness);                
    // top
            g.fillRect(x, y+height-thickness, width, thickness);    // bottom
            g.fillRect(x, y, thickness, height);                // left
            g.fillRect(x+width-thickness, y, thickness, height);    // right
            g.setColor(colorBGX);
            
    // top/bottom
            int cx = 0;
            
    // get real pattern
            int[] realPattern = new int[pattern.length];
            
    for(int i = 0; i < pattern.length; i++) {
                
    if(thicken) {
                    realPattern[i] 
    = pattern[i]*thickness;
                } 
    else {
                    realPattern[i] 
    = pattern[i];
                }
            }
            
    for(int i = 0, j = 0; i < width; i++, j+=2) {
                
    if(j >= realPattern.length) {
                    j 
    = 0;
                }
                cx 
    += realPattern[j];
                g.fillRect(cx, y, realPattern[j
    +1], thickness);                // top
                g.fillRect(cx, y+height-thickness, realPattern[j+1], thickness);    // bottom
                cx += realPattern[j+1];
            }
            
    // left/right
            int cy = 0;
            
    for(int i = 0, j = 0; i < height; i++, j+=2) {
                
    if(j >= realPattern.length) {
                    j 
    = 0;
                }
                cy 
    += realPattern[j];
                g.fillRect(x, cy, thickness, realPattern[j
    +1]);                // left
                g.fillRect(x+width-thickness, cy, thickness, realPattern[j+1]);    // right
                cy += realPattern[j+1];
            }
        }
    }
    posted on 2005-08-27 10:19 Pudgy's World 閱讀(918) 評(píng)論(0)  編輯  收藏 所屬分類: Java Newbie

    <2005年8月>
    31123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910

    常用鏈接

    留言簿(1)

    隨筆分類(13)

    隨筆檔案(13)

    文章分類(4)

    文章檔案(5)

    相冊(cè)

    Developer

    Favorite blogs

    搜索

    •  

    積分與排名

    • 積分 - 22439
    • 排名 - 1627

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲精品国产福利片| 精品一区二区三区无码免费视频| 亚洲无人区视频大全| 日本亚洲国产一区二区三区| 97在线观免费视频观看| 久久免费美女视频| 免费国产污网站在线观看不要卡| 亚洲国产成人精品激情| 久久精品亚洲综合| 亚洲一区二区视频在线观看| 在线a毛片免费视频观看| 18禁美女裸体免费网站 | 精品无码人妻一区二区免费蜜桃| 日韩在线观看视频免费| 亚洲AV无码一区二区三区性色| 亚洲国产日产无码精品| 亚洲国产精品自在线一区二区 | 一级毛片免费播放视频| 日韩欧美亚洲国产精品字幕久久久 | 久久亚洲精品中文字幕无码| 国产亚洲视频在线播放| 亚洲精品人成无码中文毛片| 日本特黄特色免费大片| 免费高清在线爱做视频| 毛片免费视频在线观看| 一个人在线观看视频免费| 69免费视频大片| 亚洲视频在线免费播放| 99在线在线视频免费视频观看| 美女被cao网站免费看在线看| 国产无遮挡色视频免费观看性色 | heyzo亚洲精品日韩| 亚洲av日韩av欧v在线天堂| 啊v在线免费观看| 深夜国产福利99亚洲视频| 免费国产a国产片高清网站| 免费成人午夜视频| 亚洲男人的天堂在线va拉文| 亚洲熟伦熟女新五十路熟妇| 亚洲无码高清在线观看| 亚洲女同成av人片在线观看|