2 x243964552 X243964552 于 2013.09.19 15:29 提问

Java 中如何控制弹出窗口的关闭,类似于QQ的天气的弹窗
本人新手,我想做一个就类似于QQ的天气的弹窗得东西,谁帮我完善一下后面的代码

我的想法是:鼠标移动到label上弹出一个窗口,移出这个label后几秒内判断鼠标移动是否到了这个窗口上,如没有就关闭这个窗口。





  package com.frame;

    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;


    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;


    public class Frame01 extends JFrame implements MouseListener{
        private JLabel loginlabel = null;
        public void init() {
            Container cont = this.getContentPane();
            cont.setLayout(new BorderLayout());
            JPanel panel = new JPanel(new GridBagLayout());
            this.loginlabel = new JLabel("登陆");
            this.loginlabel.addMouseListener(this);
            panel.add(this.loginlabel, local(0, 0));
            cont.add(panel);
        }
        public Frame01() {
            this.init();
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setResizable(false);
            this.setUndecorated(true);
            // 设置窗口大小
            this.setSize(380, 292);
            //窗口初始位置设为中间
            this.setLocationRelativeTo(null);
        }
        private GridBagConstraints local(int x, int y) {
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = x;
            gbc.gridy = y;
            return gbc;
        }
        public static void main(String[] args) {
            Frame01 fm = new Frame01();
            fm.setVisible(true);

        }
        @Override
        public void mouseClicked(MouseEvent e) {}
        @Override
        public void mousePressed(MouseEvent e) {}
        @Override
        public void mouseReleased(MouseEvent e) {}

   //Dialog1 是外面已经做好的弹窗,这里我只做出了 移动到loginlabe上弹出Dialog1,但是后面的我就不会了 
        Dialog1 dia1 = new Dialog1();
        @Override
        public void mouseEntered(MouseEvent e) {        
            Point Location = this.getLocation();
            if(e.getSource() == loginlabel) {
                dia1.setLocation(Location.x + 385,Location.y);
                dia1.setVisible(true);
            }
        }
        @Override
        public void mouseExited(MouseEvent e) {
            // TODO Auto-generated method stub

        }


    }
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!