仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1971|回复: 20
打印 上一主题 下一主题

[学习教程] JAVA网站制作之swt tray demo:右键菜单,单击埋没,一切...

[复制链接]
若相依 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:48:19 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
java也能做一些底层语言开发做的事情(难度很高,不是java顶尖高手是做不来的),菜单
swt的systemtray,只能处置三种事务:左键单击,左键双击和右键双击,右键单击这是我看swt3.0.1win32的源码所知此demo有以下功效:1.左键单击时,埋没,显现主窗口2.右键单击,弹出菜单注重:1.左键双击和右键双击是一种事务,没法辨别2.左键双击将发生以下事务:左键单击,左键双击,左键单击3.关于弹出菜单,menu必需有一个parent,假如程序里没有任何shell,能够建一个不成见的shell专门作为menu的parent.

importorg.eclipse.swt.*;importorg.eclipse.swt.widgets.*;importorg.eclipse.swt.events.*;importorg.eclipse.swt.layout.FillLayout;importorg.eclipse.swt.graphics.Image;classHelloTrayimplementsSelectionListener{Displaydisplay;Shellshell;Buttonhello;Traytray;TrayItemti;Menumenu;MenuItemmi1;MenuItemmi2;MenuItemquit;publicHelloTray(){display=Display.getDefault();shell=newShell();FillLayoutfillLayout=newFillLayout();fillLayout.type=SWT.VERTICAL;shell.setLayout(fillLayout);hello=newButton(shell,SWT.NONE);hello.setText("HelloWorld!");hello.addSelectionListener(newSelectionAdapter(){publicvoidwidgetSelected(SelectionEvente){if(hello.getText().equals("HelloWorld!"))hello.setText("Clicked");elsehello.setText("HelloWorld!");}});menu=newMenu(shell);mi1=newMenuItem(menu,SWT.PUSH);mi1.setText("MenuItem1");mi1.addSelectionListener(this);mi2=newMenuItem(menu,SWT.PUSH);mi2.setText("MenuItem2");mi2.addSelectionListener(this);quit=newMenuItem(menu,SWT.PUSH);quit.setText("Quit");quit.addSelectionListener(this);//天生swt的traytray=display.getSystemTray();ti=newTrayItem(tray,0);ti.setToolTipText("ThisisaswtTray!");ti.setImage(newImage(display,"E:MyDocumentsMyPicturesalm.gif"));//swt,tray的一切事务:ti.addSelectionListener(newSelectionListener(){//左键单击publicvoidwidgetSelected(SelectionEvente){System.out.println("TraySelcted");//左键单击时,埋没,显现主窗口if(shell.isVisible()){shell.setVisible(false);}else{shell.setVisible(true);shell.forceActive();}}//左键双击,右键双击,都是它publicvoidwidgetDefaultSelected(SelectionEvente){System.out.println("TraywidgetDefaultSelected");}});//右键单击,弹出菜单ti.addListener(SWT.MenuDetect,newListener(){publicvoidhandleEvent(Eventevent){System.out.println("SWT.MenuDetect");menu.setLocation(display.getCursorLocation());menu.setVisible(true);}});}publicvoidstart(){shell.open();while(!shell.isDisposed()){if(!display.readAndDispatch())display.sleep();}display.dispose();}publicstaticvoidmain(String[]args){HelloTrayapp=newHelloTray();app.start();}publicvoidwidgetSelected(SelectionEvente){System.out.println(e.getSource()+"selected.");if(e.getSource()==quit){System.out.println("Quit");display.dispose();System.exit(0);}}publicvoidwidgetDefaultSelected(SelectionEvente){}}

java也能做一些底层语言开发做的事情(难度很高,不是java顶尖高手是做不来的),
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-12 00:14

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表