java,php,asp.net,linux,javascript,mysql,mssql,oracle,编程

java的常用函数5

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class ToolTipCtrl
{
   
private static boolean flag = true;
   
public static void main(String[] args)
    {
        JFrame frame
= new JFrame();
       
final JButton btnSH = new JButton("Show or Hide");
       
final JButton btnS = new JButton("Show Only");
        btnSH.setToolTipText(btnSH.getText());
        btnS.setToolTipText(btnS.getText());
        frame.add(btnSH, BorderLayout.WEST);
        frame.add(btnS, BorderLayout.EAST);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(
300, 100);
        frame.setLocationRelativeTo(
null);
        frame.setVisible(
true);
        btnSH.addActionListener(
new ActionListener()
        {
           
public void actionPerformed(ActionEvent e)
            {
               
if(flag)
                {
                    postToolTip(btnSH);
                }
               
else
                {
                    hideToolTip(btnSH);
                }
                flag
= !flag;
            }
        });
        btnS.addActionListener(
new ActionListener()
        {
           
public void actionPerformed(ActionEvent e)
            {
                postToolTip(btnS);
            }
        });
    }
   
public static void postToolTip(JComponent comp)
    {
        Action action
= comp.getActionMap().get("postTip");
       
if(action != null)
        {
            ActionEvent ae
= new ActionEvent(comp, ActionEvent.ACTION_PERFORMED, "postTip", EventQueue.getMostRecentEventTime(), 0);
            action.actionPerformed(ae);
        }
    }
   
public static void hideToolTip(JComponent comp)
    {
        Action action
= comp.getActionMap().get("hideTip");
       
if(action != null)
        {
            ActionEvent ae
= new ActionEvent(comp, ActionEvent.ACTION_PERFORMED, "hideTip", EventQueue.getMostRecentEventTime(), 0);
            action.actionPerformed(ae);
        }
    }
}
                                                                  

posted on 2009-06-10 21:12 rrong_m 阅读(205) 评论(0)  编辑  收藏 所属分类: java

<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

随笔档案

文章分类

文章档案

java编程

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜