<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
    一個Custom Border
    可以實現(xià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 閱讀(917) 評論(0)  編輯  收藏 所屬分類: Java Newbie

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

    常用鏈接

    留言簿(1)

    隨筆分類(13)

    隨筆檔案(13)

    文章分類(4)

    文章檔案(5)

    相冊

    Developer

    Favorite blogs

    搜索

    •  

    積分與排名

    • 積分 - 22408
    • 排名 - 1627

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 一级视频在线免费观看| 亚洲欧美日韩综合久久久久| yellow视频免费看| 亚洲成aⅴ人片久青草影院 | 亚洲欧洲尹人香蕉综合| 99免费观看视频| 亚洲精品网站在线观看你懂的| 十九岁在线观看免费完整版电影| 亚洲图片在线观看| 亚洲免费在线观看视频| 亚洲国产中文在线二区三区免| av无码国产在线看免费网站| 亚洲乱色伦图片区小说| 免费人成在线观看网站视频 | av永久免费网站在线观看| 亚洲AV无码久久精品色欲| 中文字幕免费高清视频| 激情亚洲一区国产精品| 天天摸天天操免费播放小视频| 精品韩国亚洲av无码不卡区| 亚洲欧洲自拍拍偷精品 美利坚| 一区视频免费观看| 亚洲国产精品久久久久| 综合在线免费视频| 精品特级一级毛片免费观看| 国产美女亚洲精品久久久综合| 免费A级毛片无码A∨中文字幕下载| 亚洲专区一路线二| 国产成人精品123区免费视频| 久久精品成人免费观看97| 亚洲国产精品一区二区久久| 成人奭片免费观看| 国产成人自产拍免费视频| 337p日本欧洲亚洲大胆精品555588| 日韩吃奶摸下AA片免费观看| 国产成人精品亚洲一区| 亚洲AV第一页国产精品| 免费看大黄高清网站视频在线| 9i9精品国产免费久久| 亚洲一区中文字幕| 亚洲永久无码3D动漫一区|