• <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ì)很努力

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



            package ui;


            import java.awt.AlphaComposite;

            import java.awt.Color;

            import java.awt.Cursor;

            import java.awt.Font;

            import java.awt.FontMetrics;

            import java.awt.Graphics;

            import java.awt.Graphics2D;

            import java.awt.RenderingHints;

            import java.awt.Toolkit;

            import java.awt.event.MouseAdapter;

            import java.awt.event.MouseEvent;


            import javax.swing.JPanel;


            public class BusyPanel extends JPanel implements Runnable {

            private static final long serialVersionUID = 1L;

            private static final float PI = 3.1415f;

            private String info;

            private boolean stopped = true;

            private int step;

            private int radius;

            private int barWidth;

            private int barHeight;

            private Color defaultColor;

            private int startIndex = 0;

            private int delay = 300;

            private int darkBarCount = 5;

            private int fontSize = 40;

            private float alpha = 0.2f;


            public BusyPanel() {

            setOpaque(false);

            setStep(15);

            setRadius(150);

            setDefaultColor(new Color(100, 100, 100));

            setBarWidth((int) (radius * 0.6));

            setBarHeight(10);

            setDefaultColor(new Color(50, 50, 50));

            info = "Default Information";

            setFocusable(true);

            handleEvent();

            }


            public void run() {

            try {

            while (!stopped) {

            repaint();

            Thread.sleep(delay);

            }

            } catch (Exception e) {

            e.printStackTrace();

            }

            }


            public void start() {

            if (!stopped) {

            return;

            }


            stopped = false;


            Thread thread = new Thread(this);

            thread.start();

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            }


            public void stop() {

            stopped = true;

            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

            }


            /**

            * Set the string that will be shown in the panel.

            * 

            * @param str

            *            is will be shown.

            */

            public void setString(String str) {

            info = str;

            }


            public String getString() {

            return info;

            }


            public void setStep(int step) {

            if (step == this.step) {

            return;

            }

            if (step < 4) {

            step = 4;

            }


            this.step = step;

            }


            public int getStep() {

            return step;

            }


            public int getRadius() {

            return radius;

            }


            public int getBarWidth() {

            return barWidth;

            }


            public void setBarWidth(int barWidth) {

            if (barWidth == this.barWidth) {

            return;

            }


            if (barWidth > this.radius) {

            barWidth = this.radius;

            }


            this.barWidth = barWidth;

            }


            public int getBarHeight() {

            return barHeight;

            }


            public void setBarHeight(int barHeight) {

            if (barHeight == this.barHeight) {

            return;

            }

            if (barHeight > 20) {

            barHeight = 20;

            }

            this.barHeight = barHeight;

            }


            public void setRadius(int radius) {

            if (radius == this.radius) {

            return;

            }

            if (radius < 10) {

            radius = 10;

            }


            this.radius = radius;

            }


            public int getDelay() {

            return delay;

            }


            public void setDelay(int delay) {

            if (delay == this.delay) {

            return;

            }


            if (delay < 100) {

            delay = 100;

            }


            this.delay = delay;

            }


            public int getDarkBarCount() {

            return darkBarCount;

            }


            public void setDarkBarCount(int darkBarCount) {

            if (darkBarCount == this.darkBarCount) {

            return;

            }


            if (darkBarCount < 3) {

            darkBarCount = 3;

            }


            this.darkBarCount = darkBarCount;

            }


            public void setDefaultColor(Color color) {

            if (color.equals(this.defaultColor)) {

            return;

            }

            this.defaultColor = color;

            }


            public int getFontSize() {

            return fontSize;

            }


            public void setFontSize(int fontSize) {

            if (fontSize == this.fontSize) {

            return;

            }


            if (fontSize < 8) {

            fontSize = 8;

            }

            this.fontSize = fontSize;

            }


            public float getAlpha() {

            return alpha;

            }


            public void setAlpha(float alpha) {

            if (alpha < 0.0f) {

            alpha = 0.0f;

            }


            if (alpha > 1.0f) {

            alpha = 1.0f;

            }


            this.alpha = alpha;

            }

            private void handleEvent() {

            addMouseListener(new MouseAdapter() {

            @Override

            public void mousePressed(MouseEvent e) {

            Toolkit.getDefaultToolkit().beep();

            }

            });

            }

            @Override

            public void setVisible(boolean v) {

            if (v) {

            requestFocus();

            }

            super.setVisible(v);

            }


            @Override

            protected void paintComponent(Graphics g) {

            Graphics2D g2d = (Graphics2D) g;

            int width = getWidth();

            int height = getHeight();

            int centerx = width / 2;

            int centery = height / 2;

            // Draw the information string.

            Font font = new Font(g2d.getFont().getName(), g2d.getFont().getStyle(),

            fontSize);

            g2d.setFont(font);

            FontMetrics metrics = g2d.getFontMetrics();

            int stringWidth = metrics.stringWidth(info);

            int fontx = (width - stringWidth) / 2;

            int fonty =(height / 2 - radius) - 20;

            g2d.setColor(Color.RED);

            g2d.drawString(info, fontx, fonty);


            // Fill the semi-transparent background.

            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,

            RenderingHints.VALUE_ANTIALIAS_ON);

            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,

            alpha));

            g2d.setColor(g2d.getBackground().darker().darker().darker());

            g2d.fillRect(0, 0, width, height);


            // Draw scrolling bars.

            g2d.translate(centerx, centery);


            int startx = radius - barWidth;

            int starty = -(barHeight / 2);

            int arcWidth = barHeight;

            float deltaAngle = PI * 2 / (float) step;

            startIndex = (startIndex + 1) % step;


            g2d.setColor(defaultColor);

            for (int i = 0; i < step; ++i) {

            g2d.fillRoundRect(startx, starty, barWidth, barHeight, arcWidth,

            arcWidth);

            g2d.rotate(deltaAngle);

            }


            Color color = defaultColor;

            g2d.rotate(startIndex * deltaAngle);

            for (int i = 0; i < darkBarCount; ++i) {

            g2d.setColor(color);

            g2d.fillRoundRect(startx, starty, barWidth, barHeight, arcWidth,

            arcWidth);

            g2d.rotate(deltaAngle);


            color = color.darker();

            }


            }

            }


            =======================================================================

            package ui;


            import javax.swing.JFrame;


            public class MainFrame extends JFrame {

            private static final long serialVersionUID = 1L;

            BusyPanel glassPanel = new BusyPanel();

            MainPanel panel = new MainPanel();

            public MainFrame() {

            getRootPane().setContentPane(panel);

            setGlassPane(glassPanel);

            glassPanel.start();

            glassPanel.setVisible(false);

            }

            public void setBusy(boolean busy) {

            if (busy) {

            glassPanel.stop();

            glassPanel.start();

            glassPanel.setVisible(true);

            } else {

            glassPanel.stop();

            glassPanel.setVisible(false);

            }

            }

            }



            posted on 2009-05-26 16:41 逛奔的蝸牛 閱讀(2329) 評(píng)論(1)  編輯 收藏 引用 所屬分類(lèi): Java

            評(píng)論

            # re: Java: 半透明的正忙的Panel 2009-05-31 13:41 暗金裝備
            public void run() {
            try {
            Thread.sleep(100);
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            while (!stopped) {
            setVisible(true);
            repaint();
            Thread.sleep(delay);
            }
            } catch (Exception e) {
            e.printStackTrace();
            } finally {
            setVisible(false);
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            }
            }  回復(fù)  更多評(píng)論
              

            精品久久久久久久久久中文字幕| 久久综合给合综合久久| 色综合久久无码中文字幕| 久久国产免费直播| 久久精品国产亚洲av水果派| 成人久久精品一区二区三区 | 亚洲综合久久综合激情久久| 国产午夜福利精品久久| 亚洲国产成人精品无码久久久久久综合 | 亚洲色婷婷综合久久| 97久久天天综合色天天综合色hd| 久久精品国产亚洲欧美| 亚洲а∨天堂久久精品9966| 91久久精一区二区三区大全| 久久久久亚洲国产| 久久免费视频观看| 香蕉久久夜色精品升级完成| 国产福利电影一区二区三区久久老子无码午夜伦不 | AV色综合久久天堂AV色综合在| 狠狠色伊人久久精品综合网 | 伊人久久大香线蕉AV一区二区| 国产精品一久久香蕉产线看| 国产成人无码精品久久久性色| 亚洲国产成人久久精品影视| 久久国产精品一国产精品金尊| 久久青青色综合| 久久久99精品一区二区| 精品综合久久久久久97超人 | 久久久久久噜噜精品免费直播| 久久精品国产亚洲AV无码偷窥| 伊人久久大香线蕉av不变影院| 欧美久久一区二区三区| 久久精品亚洲欧美日韩久久| 久久最新精品国产| 久久精品国产精品亚洲精品| 亚洲国产精品久久久久婷婷软件| 国产精品久久国产精品99盘| 好久久免费视频高清| 久久婷婷久久一区二区三区| 亚洲国产成人久久综合一 | 伊人久久大香线蕉av一区|