66import java .awt .*;
77
88/**
9- * Created by IntelliJ IDEA.
10- * User: Ye
11- * Date: 2006-4-11
12- * Time: 16:28:51
13- * To change this template use File | Settings | File Templates.
9+ * BlueishButtonUI.java
10+ * This class extends BasicButtonUI to create a custom button UI with a blueish theme.
11+ * It provides a unique look and feel for buttons in a Swing application.
1412 */
15- public class BlueishButtonUI extends BasicButtonUI
16- {
13+ public class BlueishButtonUI extends BasicButtonUI {
1714
18- private static Color blueishBackgroundOver = new Color (214 , 214 , 214 );
19- private static Color blueishBorderOver = new Color (152 , 180 , 226 );
15+ private static Color blueishBackgroundOver = new Color (214 , 214 , 214 );
16+ private static Color blueishBorderOver = new Color (152 , 180 , 226 );
2017
21- private static Color blueishBackgroundSelected = new Color (192 , 192 , 192 );
22- private static Color blueishBorderSelected = new Color (49 , 106 , 197 );
18+ private static Color blueishBackgroundSelected = new Color (192 , 192 , 192 );
19+ private static Color blueishBorderSelected = new Color (49 , 106 , 197 );
2320
24- public BlueishButtonUI ()
25- {
26- super ();
27- }
21+ /**
22+ * Constructs a BlueishButtonUI.
23+ * Calls the superclass constructor.
24+ */
25+ public BlueishButtonUI () {
26+ super ();
27+ }
2828
29- public void installUI (JComponent c )
30- {
29+ /**
30+ * Installs the UI for a specified component.
31+ * Sets the rollover enabled, makes the button non-opaque, and adjusts text position.
32+ *
33+ * @param c the component where this UI will be installed
34+ */
35+ public void installUI (JComponent c ) {
36+ super .installUI (c );
37+ AbstractButton b = (AbstractButton ) c ;
38+ b .setRolloverEnabled (true );
39+ b .setOpaque (false );
40+ b .setHorizontalTextPosition (JButton .CENTER );
41+ b .setVerticalTextPosition (JButton .BOTTOM );
42+ }
3143
32- super .installUI (c );
33- AbstractButton b = (AbstractButton ) c ;
34- b .setRolloverEnabled (true );
35- b .setOpaque (false );
36- b .setHorizontalTextPosition (JButton .CENTER );
37- b .setVerticalTextPosition (JButton .BOTTOM );
38-
39- }
40-
41- public void paint (Graphics g , JComponent c )
42- {
43- AbstractButton button = (AbstractButton ) c ;
44- if (button .getModel ().isRollover () || button .getModel ().isArmed ()
45- || button .getModel ().isSelected ())
46- {
47-
48- Color oldColor = g .getColor ();
49- if (button .getModel ().isSelected ())
50- {
51- g .setColor (blueishBackgroundSelected );
52- } else
53- {
54- g .setColor (blueishBackgroundOver );
55- }
56- g .fillRect (0 , 0 , c .getWidth () - 1 , c .getHeight () - 1 );
57-
58- if (button .getModel ().isSelected ())
59- {
60- g .setColor (blueishBorderSelected );
61- } else
62- {
63- g .setColor (blueishBorderOver );
64- }
65- g .drawRect (0 , 0 , c .getWidth () - 1 , c .getHeight () - 1 );
44+ /**
45+ * Paints the specified component.
46+ * Changes the background and border colors based on the button's state.
47+ *
48+ * @param g the Graphics context in which to paint
49+ * @param c the component being painted
50+ */
51+ public void paint (Graphics g , JComponent c ) {
52+ AbstractButton button = (AbstractButton ) c ;
53+ if (button .getModel ().isRollover () || button .getModel ().isArmed () || button .getModel ().isSelected ()) {
54+ Color oldColor = g .getColor ();
55+ if (button .getModel ().isSelected ()) {
56+ g .setColor (blueishBackgroundSelected );
57+ } else {
58+ g .setColor (blueishBackgroundOver );
59+ }
60+ g .fillRect (0 , 0 , c .getWidth () - 1 , c .getHeight () - 1 );
6661
67- g .setColor (oldColor );
62+ if (button .getModel ().isSelected ()) {
63+ g .setColor (blueishBorderSelected );
64+ } else {
65+ g .setColor (blueishBorderOver );
6866 }
67+ g .drawRect (0 , 0 , c .getWidth () - 1 , c .getHeight () - 1 );
68+
69+ g .setColor (oldColor );
70+ }
6971
70- super .paint (g , c );
71- }
72+ super .paint (g , c );
73+ }
7274
7375}
0 commit comments