826220679@qq.com
2 天以前 ea135161eff1dd7c71c159be948e93b50fd1db81
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
package publicsWay;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
 
public class ButtonUtils {
    
    /**
     * ´´½¨À¶É«Ñùʽ°´Å¥µÄͨÓ÷½·¨
     * @param text °´Å¥Îı¾
     * @return ÅäÖúÃÑùʽµÄJButton
     */
    public static JButton createBlueButton(String text) {
        JButton button = new JButton(text);
        button.setBackground(new Color(0, 120, 215)); // À¶É«±³¾°
        button.setForeground(Color.WHITE); // °×É«ÎÄ×Ö
        button.setFocusPainted(false);
        button.setOpaque(true);
        button.setBorderPainted(false);
        button.setFont(button.getFont().deriveFont(Font.BOLD)); // ¼Ó´Ö×ÖÌå
        
        // Ìí¼ÓÊó±êÐüͣЧ¹û
        button.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                button.setBackground(Color.GRAY); // Êó±êÐüͣʱ±äΪ»ÒÉ«
                button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // Êó±ê±äΪÊÖÐÍ
            }
            
            @Override
            public void mouseExited(MouseEvent e) {
                button.setBackground(new Color(0, 120, 215)); // Êó±êÀ뿪ʱ»Ö¸´À¶É«
                button.setCursor(Cursor.getDefaultCursor()); // Êó±ê»Ö¸´Ä¬ÈÏÐÎ×´
            }
        });
        
        return button;
    }
}