Phenomenon:
An extension of the JButton class button that has a different look when the mouse is moved, moved, or clicked
Solution:
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.awt.*;
/** * Title: * Description: * Copyright: * Company: * @author * @version 1.0/
An extension of the
/** * JButton button that has a different appearance when the mouse is moved, removed, or clicked
public class Zbutton extends JButton
{
private Border borderout;
private Border Borderin;
private Border borderpressed;
public Zbutton () {init ();}/** initialization/
private void init ()
{
borderout = Borderfactory.createemptyborder ();//(2,2,2,2);
Borderin = Borderfactory.createbevelborder (Bevelborder.raised,color.white,color.white, New Color (148, 145, 140), New Color (103, 101, 98));
borderpressed = Borderfactory.createbevelborder (Bevelborder.lowered,color.white,color.white, New Color (148, 145, 140 ), New Color (103, 101, 98));
This.setborder (borderout);
This.addmouselistener (New Java.awt.event.MouseAdapter ()
{
public void mouseentered (MouseEvent e)
{
thisbutton_mouseentered (e);
}
public void mouseexited (MouseEvent e)
{
thisbutton_mouseexited (e);
}
public void mousepressed (MouseEvent e)
{
thisbutton_mousepressed (e);
}
public void mousereleased (MouseEvent e)
{
thisbutton_mousereleased (e);
}
});
}
/** the appearance of mouse move/
void thisbutton_mouseentered (MouseEvent e)
{
if (this.isenabled ()) This.setborder (Borderin); }
/** The appearance of the mouse when it is removed * *
void thisbutton_mouseexited (MouseEvent e)
{
This.setborder (borderout);
}
/** the appearance of mouse when clicked * *
void thisbutton_mousepressed (MouseEvent e)
{
if (this.isenabled ()) This.setborder (borderpressed);
}
/** Mouse is released when the appearance * * *
void thisbutton_mousereleased (MouseEvent e)
{
if (This.getbounds (). Contains (E.getx (), E.gety ())) && this.isenabled ())
This.setborder (Borderin); else This.setborder (borderout); }
}