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

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

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

    小試大刀(Border:我也能這么漂亮!!!)

    第一.當(dāng)然是效果圖啦;


    package ImageBorder;

    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.awt.*;
    import javax.swing.border.AbstractBorder;

    public class ImageBorder extends AbstractBorder {
        

        Image top_center, top_left, top_right;
        Image left_center, right_center;
        Image bottom_center, bottom_left, bottom_right;
        Insets insets;
        
        
    public ImageBorder(Image top_left, Image top_center, Image top_right,
            Image left_center, Image right_center,
            Image bottom_left, Image bottom_center, Image bottom_right) 
    {
                
            
    this.top_left = top_left;
            
    this.top_center = top_center;
            
    this.top_right = top_right;
            
    this.left_center = left_center;
            
    this.right_center = right_center;
            
    this.bottom_left = bottom_left;
            
    this.bottom_center = bottom_center;
            
    this.bottom_right = bottom_right;
        }

        
        
    public void setInsets(Insets insets) {
            
    this.insets = insets;
        }

        
        
    public Insets getBorderInsets(Component c) {
            
    if(insets != null{
                
    return insets;
            }
     else {
                
    return new Insets(top_center.getHeight(null),left_center.getWidth(null),
                    bottom_center.getHeight(
    null), right_center.getWidth(null));
            }

        }

        
        
        
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            g.setColor(Color.white);
            g.fillRect(x,y,width,height);

            Graphics2D g2 
    = (Graphics2D)g;
            

            int tlw = top_left.getWidth(null);
            
    int tlh = top_left.getHeight(null);
            
    int tcw = top_center.getWidth(null);
            
    int tch = top_center.getHeight(null);
            
    int trw = top_right.getWidth(null);
            
    int trh = top_right.getHeight(null);
            
            
    int lcw = left_center.getWidth(null);
            
    int lch = left_center.getHeight(null);
            
    int rcw = right_center.getWidth(null);
            
    int rch = right_center.getHeight(null);
            
            
    int blw = bottom_left.getWidth(null);
            
    int blh = bottom_left.getHeight(null);
            
    int bcw = bottom_center.getWidth(null);
            
    int bch = bottom_center.getHeight(null);
            
    int brw = bottom_right.getWidth(null);
            
    int brh = bottom_right.getHeight(null);
            
            

            fillTexture(g2,top_left,      x,            
              y,            tlw,           tlh);
            fillTexture(g2,top_center,    x
    +tlw,        
              y,            width
    -tlw-trw, tch);
            fillTexture(g2,top_right,     x
    +width-trw,  y,            trw,           trh);
            
            fillTexture(g2,left_center,   x,            y
    +tlh,        lcw,           height-tlh-blh);
            fillTexture(g2,right_center,  x
    +width-rcw,  y+trh,        rcw,           height-trh-brh);
            
            fillTexture(g2,bottom_left,   x,            y
    +height-blh, blw,           blh);
            fillTexture(g2,bottom_center, x
    +blw,        y+height-bch, width-blw-brw, bch);
            fillTexture(g2,bottom_right,  x
    +width-brw,  y+height-brh, brw,           brh);
        }

        
        
    public void fillTexture(Graphics2D g2, Image img, int x, int y, int w, int h) {
            

            BufferedImage buff = createBufferedImage(img);
            Rectangle anchor 
    = new Rectangle(x,y,
                img.getWidth(
    null),img.getHeight(null));
            TexturePaint paint 
    = new TexturePaint(buff,anchor);
            g2.setPaint(paint);
            g2.fillRect(x,y,w,h);
        }

        public BufferedImage createBufferedImage(Image img) {
            BufferedImage buff 
    = new BufferedImage(img.getWidth(null), 
                img.getHeight(
    null), BufferedImage.TYPE_INT_ARGB);
            Graphics gfx 
    = buff.createGraphics();
            gfx.drawImage(img, 
    00null);
            gfx.dispose(); 

            return buff;
        }

    }



    Main;
    package ImageBorder;

    import java.awt.*;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    import javax.swing.border.*;

    public class ImageBorderDemo {

        
    public static void main(String[] args) {
            JFrame frame 
    = new JFrame("照片邊框");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel panel 
    = new JPanel();
            JButton button 
    = new JButton("這里放個美女就更好看了");
            panel.add(button)
            
            ImageBorder image_border 
    = new ImageBorder(
                
    new ImageIcon("images/upper_left.png").getImage(),
                
    new ImageIcon("images/upper.png").getImage(),
                
    new ImageIcon("images/upper_right.png").getImage(),

                
    new ImageIcon("images/left_center.png").getImage(),
                
    new ImageIcon("images/right_center.png").getImage(),

                
    new ImageIcon("images/bottom_left.png").getImage(),
                
    new ImageIcon("images/bottom_center.png").getImage(),
                
    new ImageIcon("images/bottom_right.png").getImage()
                );
            panel.setBorder(image_border);

            
            frame.getContentPane().add(panel);
            frame.pack();
            
    //frame.setSize(200,200);
            frame.setVisible(true);
        }


    }



    posted on 2008-05-26 14:20 相信 閱讀(887) 評論(0)  編輯  收藏 所屬分類: Swing文章

    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    導(dǎo)航

    統(tǒng)計

    公告

    不顯示applet

    常用鏈接

    留言簿(16)

    我參與的團(tuán)隊(duì)

    隨筆檔案

    文章分類

    文章檔案

    新聞檔案

    相冊

    swingchina 專業(yè)搞Swing的網(wǎng)站

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 成人免费无码大片a毛片软件| 先锋影音资源片午夜在线观看视频免费播放 | 婷婷亚洲综合五月天小说在线 | 亚洲一级毛片中文字幕| 我的小后妈韩剧在线看免费高清版| 国产亚洲sss在线播放| 亚洲成av人片天堂网无码】| 亚洲人成无码久久电影网站| 午夜精品射精入后重之免费观看| 亚洲人成欧美中文字幕| 久久亚洲中文字幕精品一区| 99精品在线免费观看| 久久亚洲精品11p| 亚洲伦另类中文字幕| 四虎免费久久影院| 最近免费中文字幕大全免费 | 无码日韩人妻AV一区免费l| 亚洲毛片在线观看| 亚洲国产中文字幕在线观看| 1000部国产成人免费视频| 人人公开免费超级碰碰碰视频| 亚洲午夜电影在线观看高清| 夜色阁亚洲一区二区三区| 5555在线播放免费播放| 日本视频免费观看| ass亚洲**毛茸茸pics| 亚洲AV日韩AV鸥美在线观看| 免费看一级做a爰片久久| 日本成年免费网站| 国产免费爽爽视频在线观看| 亚洲日韩一区二区三区| 亚洲AV永久纯肉无码精品动漫| 亚洲中文字幕无码中文字| 亚洲av永久无码精品国产精品| 四虎AV永久在线精品免费观看| 一个人免费观看在线视频www| 中文字幕乱码一区二区免费| 免费国产黄网站在线看| 亚洲av无码久久忘忧草| 久久精品亚洲日本佐佐木明希| 亚洲国产精品毛片av不卡在线|