<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
    可以實現點劃線的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 閱讀(927) 評論(0)  編輯  收藏 所屬分類: Java Newbie

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

    常用鏈接

    留言簿(1)

    隨筆分類(13)

    隨筆檔案(13)

    文章分類(4)

    文章檔案(5)

    相冊

    Developer

    Favorite blogs

    搜索

    •  

    積分與排名

    • 積分 - 22588
    • 排名 - 1626

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲无限乱码一二三四区| 免费一级e一片在线播放| 亚洲国产成人无码AV在线| 中文字幕亚洲综合小综合在线 | 99精品视频在线观看免费专区 | 免费无码又爽又刺激高潮| 午夜在线a亚洲v天堂网2019| 免费高清A级毛片在线播放| 国产精品二区三区免费播放心| 不卡一卡二卡三亚洲| 亚洲黄色在线观看| 色视频在线观看免费| 免费国产一级特黄久久| 一级特黄特色的免费大片视频| 99久久国产免费-99久久国产免费 99久久国产免费中文无字幕 | 啦啦啦完整版免费视频在线观看| 热re99久久6国产精品免费| 亚洲欧洲日韩不卡| 免费国产在线精品一区| 久久影院亚洲一区| 97公开免费视频| 国产亚洲真人做受在线观看| 国产精品亚洲lv粉色| 亚洲一区二区三区无码影院| 精品亚洲永久免费精品| 亚洲宅男天堂a在线| 永久久久免费浮力影院| 男女一进一出抽搐免费视频| 日韩精品免费一级视频| 亚洲JLZZJLZZ少妇| 精品国产_亚洲人成在线高清| 9420免费高清在线视频| 99亚洲精品卡2卡三卡4卡2卡| 亚洲色精品88色婷婷七月丁香| 午夜影院免费观看| 亚洲色自偷自拍另类小说| h视频在线观看免费网站| 麻豆va在线精品免费播放| 亚洲国语精品自产拍在线观看 | 99久久综合精品免费| 国产精品亚洲色婷婷99久久精品|