网站建设宽带,seo怎么优化方法,vps云主机可以建立几个网站,广州 网站的设计公司SWT 3.0 开始引入了 Tray#xff0c;可以在系统栏放置你的程序图标了 本程序实现的功能有#xff1a;
点击窗口的最小化或关闭按钮都是隐藏窗口–任务栏里不显示#xff0c;不退出程序窗口隐藏时#xff0c;任务栏无图标#xff0c;系统栏有图标#xff1b;窗口处于显示…SWT 3.0 开始引入了 Tray可以在系统栏放置你的程序图标了 本程序实现的功能有
点击窗口的最小化或关闭按钮都是隐藏窗口–任务栏里不显示不退出程序窗口隐藏时任务栏无图标系统栏有图标窗口处于显示状态时则恰好相反窗口隐藏时可通过单击系统栏图标或点击系统栏的 “显示窗口” 菜单显示窗口程序只能通过点击系统栏的 “退出程序” 菜单项退出窗口的 X 按钮无效
import org.eclipse.swt.SWT
import org.eclipse.swt.events.*
import org.eclipse.swt.widgets.*fun main() {TrayExample.show()
}/*** SWT 3.0 开始引入了 Tray可以在系统栏放置你的程序图标了* 本程序实现的功能有四* 1. 点击窗口的最小化或关闭按钮都是隐藏窗口--任务栏里不显示不退出程序* 2. 窗口隐藏时任务栏无图标系统栏有图标窗口处于显示状态时则恰好相反* 3. 窗口隐藏时可通过单击系统栏图标或点击系统栏的 显示窗口 菜单显示窗口* 4. 程序只能通过点击系统栏的 退出程序 菜单项退出窗口的 X 按钮无效*/
object TrayExample {fun show() {val display Display()//禁用掉了最大化按钮val shell Shell(display, SWT.SHELL_TRIM xor SWT.MAX)shell.text TrayExample//取系统中预置的图标省得测试运行时还得加个图标文件shell.image display.getSystemImage(SWT.ICON_WORKING)//构造系统栏控件val tray display.systemTrayval trayItem TrayItem(tray, SWT.NONE)//程序启动时窗口是显示的所以系统栏图标隐藏trayItem.visible falsetrayItem.toolTipText shell.texttrayItem.addSelectionListener(SelectionListener.widgetSelectedAdapter {toggleDisplay(shell, tray)})val trayMenu: Menu getTrayMenu(shell, tray)//在系统栏图标点击鼠标右键时的事件弹出系统栏菜单trayItem.addMenuDetectListener { trayMenu.isVisible true }trayItem.image shell.image//注册窗口事件监听器shell.addShellListener(object : ShellAdapter() {//点击窗口最小化按钮时窗口隐藏系统栏显示图标override fun shellIconified(e: ShellEvent) {toggleDisplay(shell, tray)}//点击窗口关闭按钮时并不终止程序而时隐藏窗口同时系统栏显示图标override fun shellClosed(e: ShellEvent) {e.doit false //消耗掉原本系统来处理的事件toggleDisplay(shell, tray)}})shell.setSize(320, 240)center(shell)shell.open()while (!shell.isDisposed) {if (!display.readAndDispatch()) {display.sleep()}}display.dispose()}
}private fun getTrayMenu(shell: Shell, tray: Tray): Menu {val trayMenu Menu(shell, SWT.POP_UP)val showMenuItem MenuItem(trayMenu, SWT.PUSH)showMenuItem.text 显示窗口(s)//显示窗口并隐藏系统栏中的图标showMenuItem.addSelectionListener(SelectionListener.widgetSelectedAdapter {toggleDisplay(shell, tray)})trayMenu.defaultItem showMenuItemMenuItem(trayMenu, SWT.SEPARATOR)//系统栏中的退出菜单程序只能通过这个菜单退出val exitMenuItem MenuItem(trayMenu, SWT.PUSH)exitMenuItem.text 退出程序(x)exitMenuItem.addSelectionListener(object : SelectionAdapter() {override fun widgetSelected(event: SelectionEvent) {shell.dispose()}})return trayMenu
}/*** 窗口是可见状态时则隐藏窗口同时把系统栏中图标删除* 窗口是隐藏状态时则显示窗口并且在系统栏中显示图标** param shell 窗口* param tray 系统栏图标控件*/
private fun toggleDisplay(shell: Shell, tray: Tray) {shell.isVisible !shell.isVisibletray.getItem(0).visible !shell.isVisibleif (shell.visible) {shell.minimized falseshell.setActive()}
}/*** 窗口居中显示** param shell 要显示的窗口*/
private fun center(shell: Shell) {val monitor shell.monitorval bounds monitor.boundsval rect shell.boundsval x bounds.x (bounds.width - rect.width) / 2val y bounds.y (bounds.height - rect.height) / 2shell.setLocation(x, y)
}