日期:2014-05-20 浏览次数:20713 次
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
}