import java.awt.FlowLayout;
import java.awt.SystemColor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JWindow;
public class ToolTipp extends JWindow implements MouseListener{
public ToolTipp(String message,JFrame frame){
super(frame);
setLayout(new FlowLayout(FlowLayout.CENTER));
getContentPane().add(new JLabel(message));
getContentPane().setBackground(SystemColor.info);
getContentPane().setForeground(SystemColor.infoText);
addMouseListener(this);
pack();
}
public void mouseClicked(MouseEvent e) {
setVisible(false);
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
}
import java.awt.Point;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
public class ToolTippFrame extends JFrame implements MouseListener, ComponentListener{
private ToolTipp tipp;
public ToolTippFrame(){
init();
}
private void init() {
addMouseListener(this);
addComponentListener(this);
tipp = new ToolTipp("Mein guter Tipp!!!",this);
}
public void mouseClicked(MouseEvent e) {
if(!tipp.isVisible()){
Point l = new Point(e.getX()+getLocation().x,e.getY()+getLocation().y);
tipp.setLocation(l);
}
tipp.setVisible(!tipp.isVisible());
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public static void main(String[] args) {
ToolTippFrame toolTipp = new ToolTippFrame();
toolTipp.setSize(800,600);
toolTipp.setVisible(true);
}
public void componentResized(ComponentEvent e) {
tipp.setVisible(false);
}
public void componentMoved(ComponentEvent e) {
tipp.setVisible(false);
}
public void componentShown(ComponentEvent e) {
tipp.setVisible(false);
}
public void componentHidden(ComponentEvent e) {
}
}