|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
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顶尖高手是做不来的), |
|