import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
public class FloatLabel extends JLabel implements MouseListener {
private String text;
private float fontSize;
public FloatLabel(String text) {
super();
this.text = text;
this.setBounds (30, 30, 100, 20);
this.setBorder(BorderFactory.createLineBorder (Color.black));
this.fontSize = this.getHeight() / 2;
this.addMouseListener(this);
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.setFont(g.getFont().deriveFont(fontSize));
g.setColor(Color.black);
g.drawString(text, 10,(int) (this.getHeight() + fontSize) / 2);
}
public void mouseClicked(MouseEvent arg0) {
}
public void mouseEntered(MouseEvent arg0) {
this.setBounds(this.getX(), this.getY(), this.getWidth() * 2, this.getHeight() * 2);
this.fontSize = this.getHeight() / 2;
this.repaint();
}
public void mouseExited(MouseEvent arg0) {
this.setBounds(this.getX(), this.getY(), this.getWidth() / 2, this.getHeight() / 2);
this.fontSize = this.getHeight() / 2;
this.repaint();
}
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}