eption;
Layout;
;
;
em;
nfo;
;
enu;
gle;
Tray;
t;
on;
Event;
Listener;
Adapter;
Event;
n;
;
;
;
Constants;
publicclassSysTrayFrameextendsJFrameimplementsActionListener
{
privateRectanglerect;
privateintframeLeft;//窗体离屏幕左边的距离
privateintframeRight;//窗体离屏幕右边的距离;
privateintframeTop;//窗体离屏幕顶部的距离
privateintframeWidth;//窗体的宽
p股票英文 rivateintframeHeight;//窗体的高
privateintscreenXX;//屏幕的宽度;
staticpublicPointpoint=newPoint();//鼠标在窗体的位置
privateTrayIcontrayIcon;
BorderLayoutborderLayout1=newBorderLayout();
privateTimertimer=newTimer(10,this);
JPanelroot=newJPanel();
intx,y;
JButtonexit=newJButton();
publicSysTrayFrame()
{
try
{
();
tLocation(400,300);
tSize(400,300);
jbInit();
ayIcon();
}catch(Exceptionexception)
{
tackTrace();
}
}
privatevoidjbInit()throwsException
{
aultCloO周树人是谁 peration(_ON_CLOSE);
dowListener(ne鼓励人的句子 wWindowAdapter()
{
//捕获窗口关闭事件
publicvoidwindowClosing(WindowEvente)
{
if(orted())
{
tVisible(fal);
minimizeToTray();
}
el
{
(0);
}
}
//捕获窗口最小化事件
publicvoidwindowIconified(WindowEvente)
{
if(orted())
{
tVisible(fal);
minimizeToTray();
}
el
{
(0);
}
}
});
getContentPane().tLayout(borderLayout1);
t("exit");
ionListener(newSysTrayFrame_exit_actionAdapter(this));
tentPane().add(root,);
(exit);
}
privatevoidinitTrayIcon()
{
Imageimage=aultToolkit().getImage(
ss().getResource适合女生手机壁纸 (""));
PopupMenupopup=newPopupMenu();
MenuItemexitItem=newMenuItem("Show");
ActionListenerlistener=newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
tVisible(true);
tExtendedState();
temTray().remove(trayIcon);
}
};
ionListener(listener);
(exitItem);
//根据image、提示、菜单创建TrayIcon
on=newTrayIcon(image,"MyTray",popup);
//给TrayIcon添加事件监听器
ionListener(listener);
}
publicvoidminimizeToTray()
{
if(temTray().getTrayIcons().length==1)
{
return;
}
SystemTraytray=temTray();
try
{
(on);
}catch(AWTExceptionex)
{
tackTrace();
}
}
publicstaticvoidmain(String[]args)
{
SysTrayFramesystrayframe=newSysTrayFrame();
le("MyTray");
ible(true);
Threadt=newThread(newMyThread());
();
}
publicvoidexit_actionPerformed(ActionEvente)
{
(0);
}
publicvoidactionPerformed(ActionEventarg0)
{
if(temTray().getTrayIcons().length==1)
{
frameTop=0;
}el
{
frameTop=ation().y;
}
frameWidth=400;
frameHeight=300;
if((frameTop==0)&&isPtInRect(point))
{
tVisible(true);
tExtendedState();
temTray().remove(trayIcon);
tLocation(ation().x,0);//窗口隐藏了,鼠标指到他,就显
示出来;
}elif(frameTop>-5&&frameTop<5&&!(isPtInRect(point)))
{
x=ation().x;
y=-1;
tVisible(fal);
minimizeToTray();
}
}
publicbooleanisPtInRect(Pointpoint)
{
if(temTray().getTrayIcons().length==1)
{
rect=newRectangle(x,y,frameWidth,6);
}el
{
rect=newRectangle(ation().x,ation().y,
frameWidth,frameHeight);
}
if(rect!=null&&point!=null)
{
intx0=rect.x;
inty0=rect.y;
i很简单英文 ntx1=;
inty1=;
intx=point.x;
inty=point.y;
returnx>=x0&&x<(x1+x0)&&y>=y0&&y<(y1+y0);
}
returnfal;
}
}
classSysTrayFrame_exit_actionAdapterimplementsActionListener
{
privateSysTrayFrameadaptee;
SysTrayFrame_exit_actionAdapter(SysTrayFrameadaptee)
{
e=adaptee;
}
publicvoidactionPerformed(ActionEvente)
{
_actionPerformed(e);
}
}
classMyThreadimplementsRunnable
{
@Over喷漆枪 ride
publicvoidrun()
{
//TODOAuto-generatedmethodstub
while(true)
{
=nterInfo().getLocation();
try
{
(10);
}catch(InterruptedExceptione)
{
//TODOAuto-generatedcatchblock
tackTrace();
}
}
}
}
本文发布于:2023-03-26 09:20:45,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/1679793647392907.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:系统托盘.doc
本文 PDF 下载地址:系统托盘.pdf
留言与评论(共有 0 条评论) |