zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package PbuliClass;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.Serializable;
 
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;
 
/**¸ÃÀàÓÃÓÚʵÏÖÓÒϽǵĵ¯´°ÌáÐѹ¦ÄÜ*/
/*JWindow ÊÇÒ»¸öÈÝÆ÷£¬¿ÉÒÔÏÔʾÔÚÓû§×ÀÃæÉϵÄÈκÎλÖá£
 * ËüûÓбêÌâÀ¸¡¢´°¿Ú¹ÜÀí°´Å¥»òÕ߯äËûÓë JFrame ¹ØÁªµÄÐÞÊÎ
 * */
public class PopWindow extends JWindow {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    public PopWindow(String text) {
        addMouseListener(new MouseAdapter() {// Ìí¼ÓÊó±êʼþ¼àÌýÆ÷
            public void mousePressed(MouseEvent e) {
                dispose();// Êó±êµ¥»÷£¬ÔòÏú»ÙÕâ¸ö´°Ìå
            }             
        });
        this.setBounds(100, 100, 300, 200);// ÉèÖô°Ìå´óС
        BGPanel panel = new BGPanel();// ´´½¨±³¾°Ãæ°å
        // ÉèÖñ³¾°Í¼Æ¬
        panel.setImage(Toolkit.getDefaultToolkit().getImage("image/tip/tips.jpg"));
        getContentPane().add(panel, BorderLayout.CENTER);
        JLabel textLabel=new JLabel();//ÉèÖÃÌáʾÎÄ×Ö
        textLabel.setText(text);
        panel.add(textLabel);
        
    }
    
  
}
 
class BGPanel extends JPanel implements Serializable {
    
    private static final long serialVersionUID = 1L;
    private Image image; 
    public static final int HORIZONGTAL_FILL = 1;
    public static final int VERTICAL_FILL = 2;
    public static final int BOTH_FILL = 3;
    public static final int NO_FILL = 0;
    private int iconFill = NO_FILL;
    
    /**
     * This is the default constructor
     */
    public BGPanel() {
        super();
        initialize();
    }
    
    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize() {
        this.setSize(new Dimension(300, 200));
        this.setLayout(new GridBagLayout());
    }
    
    public Image getImage() {
        return image;
    }
    
    public void setImage(Image icon) {
        this.image = icon;
    }
    
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);// Íê³ÉÔ­À´¿Ø¼þÍâ¹ÛµÄ»æÖÆ
        if (image != null) {// ¿ªÊ¼×Ô¶¨Òå±³¾°µÄ»æÖÆ
            switch (iconFill) {// Åжϱ³¾°Ìî³ä·½Ê½
                case NO_FILL:// ²»Ìî³ä
                    g.drawImage(image, 0, 0, this);// »æÖÆÔ­Ê¼Í¼Æ¬´óС
                    break;
                case HORIZONGTAL_FILL:// Ë®Æ½Ìî³ä
                    // »æÖÆÓë¿Ø¼þµÈ¿íµÄͼƬ
                    g.drawImage(image, 0, 0, getWidth(), image.getHeight(this),
                            this);
                    break;
                case VERTICAL_FILL:// ´¹Ö±Ìî³ä
                    // »æÖÆÓë¿Ø¼þµÈ¸ßµÄͼƬ
                    g.drawImage(image, 0, 0, image.getWidth(this), getHeight(),
                            this);
                    break;
                case BOTH_FILL:// Ë«ÏòÌî³ä
                    // »æÖÆÓë¿Ø¼þͬµÈ´óСµÄͼƬ
                    g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
                    break;
                default:
                    break;
            }
        }
    }
    
    public int getIconFill() {
        return iconFill;
    }
    
    /**
     * ÉèÖñ³¾°Öظ´·½Ê½
     * 
     * @param repeat
     *            Öظ´·½Ê½
     */
    public void setIconFill(int iconFill) {
        this.iconFill = iconFill;
    }
    
}