Thema: KButton

  1. #1
    Permanent gesperrt

    Registriert seit
    19.12.2011
    Beiträge
    356
    Thanked 164 Times in 101 Posts

    Standard KButton

    PHP-Code:
    package KCClient.UI.Components;

    import java.awt.*;
    import java.awt.event.MouseAdapter;
    import javax.swing.JButton;


    /**
     *
     * @author DeKaDeNz
     */



    public class KButton extends JButton {
        
        
        public class 
    KButton_MouseEvents extends MouseAdapter
        
    {
            @
    Override
            
    public void mouseEntered(java.awt.event.MouseEvent evt) {
                
    KButton button = (KButton)evt.getComponent();
                
    button.hover true;
            }
            
            @
    Override
            
    public void mouseExited(java.awt.event.MouseEvent evt) {
                
    KButton button = (KButton)evt.getComponent();
                
    button.hover false;

            }
            
            @
    Override
            
    public void mousePressed(java.awt.event.MouseEvent evt)
            {
                
    KButton button = (KButton)evt.getComponent();
                
    button.clicked true;
            }
            
            @
    Override
            
    public void mouseReleased(java.awt.event.MouseEvent evt)
            {
                
    KButton button = (KButton)evt.getComponent();
                
    button.clicked false;
            }
        }
        
        

        private 
    GradientPaint paint2;
        
        
        public 
    KButton()
        {
            
    super();
            
    this.addMouseListener(new KButton_MouseEvents());
        }
        
        
        
        
        
        
        private 
    Color background2 Color.WHITE;
        private 
    Color borderColor Color.BLACK;
        
        public 
    Color getBorderColor()
        {
            return 
    borderColor;
        }
        public 
    void setBorderColor(Color c)
        {
            
    borderColor c;
        }
        
        public 
    Color getBackground2()
        {
            return 
    background2;
        }
        public 
    void setBackground2(Color c)
        {
            
    background2 c;
        }
        
        
        public 
    boolean hover false;
        public 
    boolean clicked false;
        public 
    Paint paintBackground(Graphics g)
        {

           
    //background
           
    Graphics2D g2 = (Graphics2D)g;
           
    Paint old g2.getPaint();
           
          
       
           
           
           
           
    //background
           
    g2.setColor(this.getBackground());
           
    g2.fillRoundRect(0,0,this.getWidth()-1this.getHeight()-1,6,6);
           

           
    //bckground//shine
           
    Color transp1 = new Color(this.getBackground2().getRed(),this.getBackground2().getBlue(), this.getBackground2().getGreen(), 180);
           
    Color transp2 = new Color(this.getBackground2().getRed(),this.getBackground2().getBlue(), this.getBackground2().getGreen(), 50);
           
           
    paint2 = new GradientPaint(0,0,transp10,this.getHeight()/2,transp2,true);
           
    g2.setPaint(paint2);
           if(!
    clicked)
                
    g2.fillRoundRect(0,0,this.getWidth()-1, (this.getHeight())/2,6,6);
           else
                
    g2.fillRoundRect(0,(this.getHeight())/2,this.getWidth()-1,(this.getHeight()-2)/2,6,0);
           
           
           
    //hovereffectz
           
    g2.setPaint(old);
           if(
    hover)
           {
               
    //background
               
    Color transp3 = new Color(this.getBackground2().getRed(),this.getBackground2().getBlue(), this.getBackground2().getGreen(), 30);
               
    g2.setColor(transp3);
               
    g2.fillRoundRect(0,0,this.getWidth()-1this.getHeight()-1,6,6);
           }

           
         
      

           
           return 
    old;
        }
        
        
        
        @
    Override
        
    public void paintBorder(Graphics gtmp)
        {

           
           
    Graphics2D g = (Graphics2D)gtmp;
           
    g.setColor(this.getBorderColor());
           
    g.drawRoundRect(0,0,this.getWidth()-1this.getHeight()-1,6,6);
        }
        
        @
    Override
        
    public void paintComponent(Graphics g)
        {

           
    Graphics2D g2 = (Graphics2D)g;
           
    Paint oldPaint paintBackground(g2);
           
            
           
           
    //schrift
           
    g2.setPaint(oldPaint);
           
    String text this.getText();
           
    g2.setFont(this.getFont());
           
    g2.setColor(this.getForeground());
           
    FontMetrics metrics g2.getFontMetrics();
           
    int w=metrics.stringWidth(text);
           
    int h=metrics.getHeight();
           
    Dimension d=getSize();
           
    int x=(d.width-w)/2;
           
    int y=(d.height-h)/2+metrics.getAscent();
          
           

           
    g2.drawString(textxy);
           
           
           
        }
        

    Geändert von DeKaDeNz (08.02.2012 um 00:35 Uhr)

  2. The Following 3 Users Say Thank You to DeKaDeNz For This Useful Post:

    Gangstersheep (07.02.2012), Mardcore (11.02.2012), Mentos (07.02.2012)

Ähnliche Themen

  1. [JAVA] KButton
    Von Mentos im Forum Sourcecode
    Antworten: 0
    Letzter Beitrag: 04.04.2012, 17:49
  2. [SCR] KButton - Knuddels Button Control
    Von Devon im Forum Sourcecode
    Antworten: 4
    Letzter Beitrag: 02.03.2012, 00:43
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.

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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191