怎么实现flashget那样的悬浮窗功能啊?

cnheying 2006-07-10 09:38:35
怎么实现flashget那样的悬浮窗功能啊?
指点个开源软件参考一下也也行???
...全文
313 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
balckeagle 2006-07-11
  • 打赏
  • 举报
回复
楼上的不错啊

ldg_2 2006-07-11
  • 打赏
  • 举报
回复
代码正常运行,但是很丑,正好我得flashget悬浮窗在,所以有比较。
另外,怎么关闭?
kingdoom 2006-07-11
  • 打赏
  • 举报
回复
学习
congliu 2006-07-10
  • 打赏
  • 举报
回复
import java.awt.*;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.event.MouseInputAdapter;

public class UndecoratedFrame extends JFrame
{
private static final int TITLE_HEIGHT = 20;

public UndecoratedFrame() throws HeadlessException
{
super();
setUndecorated(true);

MouseHandler ml = new MouseHandler();
addMouseListener(ml);
addMouseMotionListener(ml);
}

public UndecoratedFrame(String title) throws HeadlessException
{
super(title);
setUndecorated(true);

MouseHandler ml = new MouseHandler();
addMouseListener(ml);
addMouseMotionListener(ml);
}

public Insets getInsets()
{
return new Insets(TITLE_HEIGHT, 1, 1, 1);
}

public void paint(Graphics g)
{
super.paint(g);
g.setColor(new Color(0, 0, 128));
g.drawRect(0, 0, getWidth()-1, getHeight()-1);
g.fillRect(0, 0, getWidth(), TITLE_HEIGHT);

FontMetrics fm = g.getFontMetrics();
g.setColor(Color.white);
g.drawString(getTitle(), 2, (TITLE_HEIGHT - fm.getHeight()) / 2 + fm.getAscent());
}

private class MouseHandler extends MouseInputAdapter
{
private Point point;

public void mousePressed(MouseEvent e)
{
if (e.getY() <= TITLE_HEIGHT) {
this.point = e.getPoint();
}
}

public void mouseDragged(MouseEvent e)
{
if (point != null) {
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));

Point p = e.getPoint();
int dx = p.x - point.x;
int dy = p.y - point.y;

int x = getX();
int y = getY();
setLocation(x + dx, y + dy);
}
}

public void mouseReleased(MouseEvent e)
{
point = null;
setCursor(Cursor.getDefaultCursor());
}
}

public static void main(String[] args)
{
JFrame f = new UndecoratedFrame("Undecorated Frame");
f.getContentPane().add(new JLabel("Hello World!", JLabel.CENTER), BorderLayout.CENTER);
f.setSize(400, 400);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}

}


xuyang821225 2006-07-10
  • 打赏
  • 举报
回复
什么悬浮窗口?
ms_ms 2006-07-10
  • 打赏
  • 举报
回复
桌面应用不是java的强项
yczz 2006-07-10
  • 打赏
  • 举报
回复
纯JAVA不能实现,只有用C++写好然后用JNI调用
infowain 2006-07-10
  • 打赏
  • 举报
回复
用C或者C++的例子很多,其实就是半透明窗口,
用java实现的还没看到过
wts173 2006-07-10
  • 打赏
  • 举报
回复
up

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧