• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會(huì)很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::

            import javax.swing.*;

            import java.awt.*;
            import java.awt.event.*;
            import java.awt.geom.Point2D;

            public class VectorButton extends JButton implements MouseListener {
                
            private static final long serialVersionUID = 8608596863475640115L;

                
            public VectorButton() {
                    
            this("");
                }
                
                
            public VectorButton(String text) {
                    
            super(text);
                    
            this.setBorderPainted(false);
                    
            this.addMouseListener(this);
                }

                
            public Dimension getPreferredSize() {
                    String text 
            = getText();
                    FontMetrics fm 
            = this.getFontMetrics(getFont());
                    
            float scale = (50f / 30f) * this.getFont().getSize2D();
                    
            int w = fm.stringWidth(text);
                    w 
            += (int) (scale * 1.4f);
                    
            int h = fm.getHeight();
                    h 
            += (int) (scale * .3f);
                    
            return new Dimension(w, h);
                }

                
            public void paintComponent(Graphics g) {
                    Graphics2D g2 
            = (Graphics2D) g;
                    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
                    g2.setColor(
            this.getBackground());
                    g2.fillRect(
            00this.getWidth(), this.getHeight());

                    
            float scale = (50f / 30f) * this.getFont().getSize2D();

                    drawLiquidButton(
            this.getForeground(), this.getWidth(), this
                            .getHeight(), getText(), scale, g2);
                }

                
            protected void drawLiquidButton(Color base, int width, int height,
                        String text, 
            float scale, Graphics2D g2) {

                    
            // calculate inset
                    int inset = (int) (scale * 0.04f);
                    
            int w = width - inset * 2 - 1;
                    
            int h = height - (int) (scale * 0.1f- 1;

                    g2.translate(inset, 
            0);
                    drawDropShadow(w, h, scale, g2);

                    
            if (pressed) {
                        g2.translate(
            00.04f * scale);
                    }

                    drawButtonBody(w, h, scale, base, g2);
                    drawText(w, h, scale, text, g2);
                    drawHighlight(w, h, scale, base, g2);
                    drawBorder(w, h, scale, g2);

                    
            if (pressed) {
                        g2.translate(
            00.04f * scale);
                    }
                    g2.translate(
            -inset, 0);
                }

                
            protected void drawDropShadow(int w, int h, float scale, Graphics2D g2) {
                    g2.setColor(
            new Color(00050));
                    fillRoundRect(g2, (
            -.04f) * scale, (.02f) * scale, w + .08f * scale, h
                            
            + 0.08f * scale, scale * 1.04f, scale * 1.04f);
                    g2.setColor(
            new Color(000100));
                    fillRoundRect(g2, 
            00.06f * scale, w, h, scale, scale);
                }

                
            protected void drawButtonBody(int w, int h, float scale, Color base,
                        Graphics2D g2) {

                    Color grad_top 
            = base.brighter();
                    Color grad_bot 
            = base.darker();
                    GradientPaint bg 
            = new GradientPaint(new Point(00), grad_top,
                            
            new Point(0, h), grad_bot);
                    g2.setPaint(bg);

                    
            this.fillRoundRect(g2, (0* scale, (0* scale, w, h, 1 * scale,
                            
            1 * scale);

                    
            // draw the inner color
                    Color inner = base.brighter();
                    inner 
            = alphaColor(inner, 75);
                    g2.setColor(inner);
                    
            this.fillRoundRect(g2,

                    scale 
            * (.4f), scale * (.4f), w - scale * .8f, h - scale * .5f,
                            scale 
            * .6f, scale * .4f);
                }

                
            // generate the alpha version of the specified color
                protected static Color alphaColor(Color color, int alpha) {
                    
            return new Color(color.getRed(), color.getGreen(), color.getBlue(),
                            alpha);
                }

                
            protected void drawText(int w, int h, float scale,
                        String text, Graphics2D g2) {

                    
            // calculate the width and height
                    int fw = g2.getFontMetrics().stringWidth(text);
                    
            int fh = g2.getFontMetrics().getAscent();
                        g2.getFontMetrics().getDescent();
                    
            int textx = (w-fw)/2;
                    
            int texty = h/2 + fh/2;

                    
            // draw the text
                    g2.setColor(new Color(0,0,0,70));
                    g2.drawString(text,(
            int)((float)textx+scale*(0.04f)),
                        (
            int)((float)texty + scale*(0.04f)));
                    g2.setColor(Color.black);
                    g2.drawString(text, textx, texty);

                }

                
            protected void drawHighlight(int w, int h, float scale, Color base,
                        Graphics2D g2) {

                    
            // create the highlight
                    GradientPaint highlight = new GradientPaint(new Point2D.Float(
                            scale 
            * 0.2f, scale * 0.2f), new Color(255255255175),
                            
            new Point2D.Float(scale * 0.2f, scale * 0.55f), new Color(255,
                                    
            2552550));
                    g2.setPaint(highlight);
                    
            this.fillRoundRect(g2, scale * 0.2f, scale * 0.1f, w - scale * 0.4f,
                            scale 
            * 0.4f, scale * 0.8f, scale * 0.4f);
                    
            this.drawRoundRect(g2, scale * 0.2f, scale * 0.1f, w - scale * 0.4f,
                            scale 
            * 0.4f, scale * 0.8f, scale * 0.4f);
                }

                
            protected void drawBorder(int w, int h, float scale, Graphics2D g2) {

                    
            // draw the border
                    g2.setColor(new Color(000150));
                    
            this.drawRoundRect(g2, scale * (0f), scale * (0f), w, h, scale, scale);
                }

                
            // float version of fill round rect
                protected static void fillRoundRect(Graphics2D g2, float x, float y,
                        
            float w, float h, float ax, float ay) {

                    g2.fillRoundRect((
            int) x, (int) y, (int) w, (int) h, (int) ax, (int) ay

                    );
                }

                
            // float version of draw round rect
                protected static void drawRoundRect(Graphics2D g2, float x, float y,
                        
            float w, float h, float ax, float ay) {

                    g2
                            .drawRoundRect((
            int) x, (int) y, (int) w, (int) h, (int) ax,
                                    (
            int) ay);
                }

                
            /* mouse listener implementation */
                
            protected boolean pressed = false;

                
            public void mouseExited(MouseEvent evt) {
                }

                
            public void mouseEntered(MouseEvent evt) {
                }

                
            public void mouseClicked(MouseEvent evt) {
                }

                
            public void mouseReleased(MouseEvent evt) {
                    pressed 
            = false;
                }

                
            public void mousePressed(MouseEvent evt) {
                    pressed 
            = true;
                }
                
                
            private static void createAndShowGUI() {
                    JFrame frame 
            = new JFrame("Demo");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setSize(
            35080);
                    
                    Box box 
            = new Box(BoxLayout.X_AXIS);
                    box.add(Box.createGlue());
                    box.add(
            new VectorButton("Button1"));
                    box.add(
            new VectorButton("Button1"));
                    box.add(
            new VectorButton("Button1"));
                    box.add(
            new VectorButton("Button1"));
                    frame.getContentPane().add(box);
                    box.add(Box.createGlue());
                    
                    frame.setVisible(
            true);
                }

                
            public static void main(String[] args) {
                    SwingUtilities.invokeLater(
            new Runnable() {
                        
            public void run() {
                            VectorButton.createAndShowGUI();
                        }
                    });
                }
            }


            posted on 2008-03-17 06:54 逛奔的蝸牛 閱讀(2923) 評論(0)  編輯 收藏 引用 所屬分類: Java
            日韩精品国产自在久久现线拍 | 国产亚洲成人久久| 亚洲伊人久久精品影院| 久久久久国产日韩精品网站| 久久91精品国产91久久麻豆| 久久人人妻人人爽人人爽| 精品伊人久久大线蕉色首页| 久久夜色精品国产噜噜亚洲a| 久久久久国产视频电影| 日本久久中文字幕| 伊人伊成久久人综合网777| 日本五月天婷久久网站| 久久精品国产亚洲AV忘忧草18| 一级女性全黄久久生活片免费| 人妻少妇精品久久| 精品国产乱码久久久久软件| 99久久精品国产一区二区| 亚洲国产精品久久电影欧美| 国产情侣久久久久aⅴ免费| 久久婷婷久久一区二区三区| 久久亚洲欧洲国产综合| 精品无码久久久久国产动漫3d| 久久精品亚洲日本波多野结衣| 久久亚洲精品中文字幕三区| 久久久久无码精品| 午夜精品久久久久久久久| 2021精品国产综合久久| 久久久无码精品亚洲日韩软件| 久久久久久久久久久| 亚洲国产精品人久久| 久久久网中文字幕| 999久久久免费精品国产| 久久99精品久久久久久9蜜桃| 国产精品亚洲综合久久 | 波多野结衣AV无码久久一区| 久久夜色精品国产噜噜噜亚洲AV| 国产精品丝袜久久久久久不卡| 久久久无码精品亚洲日韩京东传媒| 丁香狠狠色婷婷久久综合| 午夜精品久久影院蜜桃| 久久精品国产影库免费看|