import java.awt.* ; import java.awt.event.* ; import javax.swing.* ; class TerminationListener implements WindowListener { public void windowActivated(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowClosing(WindowEvent e) { System.exit(0) ; } public void windowDeactivated(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowOpened(WindowEvent e) {} } class ToolTipPanel extends JPanel { public ToolTipPanel() { redButton = new JButton("Red") ; blueButton = new JButton("Blue") ; greenButton = new JButton("Green") ; add(redButton) ; add(blueButton) ; add(greenButton) ; redButton.setToolTipText("Set red background") ; blueButton.setToolTipText("Set blue background") ; greenButton.setToolTipText("Set green background") ; } private JButton redButton ; private JButton blueButton ; private JButton greenButton ; } public class ToolTipTest { public static void main(String [] args) { JFrame frame = new JFrame() ; frame.setTitle("ToolTipTest") ; frame.setSize(450, 300) ; frame.addWindowListener(new TerminationListener()) ; frame.getContentPane().add(new ToolTipPanel()) ; frame.setVisible(true) ; } }