Advertisement
xlrnxnlx

MBtn

Jul 4th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package view.external;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.event.MouseEvent;
  6. import java.awt.event.MouseListener;
  7. import javax.swing.JButton;
  8. import javax.swing.border.LineBorder;
  9.  
  10. public class MButton extends JButton implements MouseListener {
  11.    
  12.     private Color init;
  13.     private Color hover;
  14.    
  15.     public MButton(String title, Color hover){
  16.         super(title);
  17.         this.hover = hover;
  18.         this.init = Color.WHITE;
  19.         setBackground(init);
  20.         setForeground(hover);
  21.         setBorder(new LineBorder(hover, 1, false));
  22.         addMouseListener(this);
  23.     }
  24.  
  25.     @Override
  26.     protected void paintComponent(Graphics g) {
  27.         super.paintComponent(g);
  28.         g.setColor(init);
  29.     }
  30.    
  31.     @Override
  32.     public void mouseEntered(MouseEvent e) {
  33.         if(e.getSource() == this && isEnabled()){
  34.             this.setBackground(hover);
  35.             this.setForeground(init);
  36.         }
  37.     }
  38.  
  39.     @Override
  40.     public void mouseExited(MouseEvent e) {
  41.         if(e.getSource() == this){
  42.             this.setBackground(init);
  43.             this.setForeground(hover);
  44.             this.setBorder(new LineBorder(hover, 1, false));
  45.         }
  46.     }
  47.  
  48.     @Override public void mouseClicked(MouseEvent e) {}
  49.     @Override public void mousePressed(MouseEvent e) {}
  50.     @Override public void mouseReleased(MouseEvent e) {}
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement