Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package view.external;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import javax.swing.JButton;
- import javax.swing.border.LineBorder;
- public class MButton extends JButton implements MouseListener {
- private Color init;
- private Color hover;
- public MButton(String title, Color hover){
- super(title);
- this.hover = hover;
- this.init = Color.WHITE;
- setBackground(init);
- setForeground(hover);
- setBorder(new LineBorder(hover, 1, false));
- addMouseListener(this);
- }
- @Override
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.setColor(init);
- }
- @Override
- public void mouseEntered(MouseEvent e) {
- if(e.getSource() == this && isEnabled()){
- this.setBackground(hover);
- this.setForeground(init);
- }
- }
- @Override
- public void mouseExited(MouseEvent e) {
- if(e.getSource() == this){
- this.setBackground(init);
- this.setForeground(hover);
- this.setBorder(new LineBorder(hover, 1, false));
- }
- }
- @Override public void mouseClicked(MouseEvent e) {}
- @Override public void mousePressed(MouseEvent e) {}
- @Override public void mouseReleased(MouseEvent e) {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement