netbeans创建桌面应用程序-状态栏的应用(进度条、busyicon和message)
2010-07-19 21:09
302 查看
用netbeans新建桌面应用程序时会自动生成状态栏,包括一个进度条一个busyicon和一个信息提示。最初我看的很纠结,不知道应该如何让这些东西动起来。研究了一下nb生成的代码,总算会用了,分享给大家。
先看看生成的代码:
是不是很纠结呢……如果单独用progressBar的话还是很简单的:
分别用setMinimum setMaxmum 方法来设定进度条的起止量,用setValue更新进度条的显示。 setIndeterminate可以用于不确定的任务长度,你会看到进度条在不断摇摆。
上面的代码如果仔细看看也不难,主要是用两个timer分别实现了busyicon和定时清楚提示信息。用法如下:
不过很明显到目前为止我们还没有用到最初代码中的后半部分:taskMonitor.addPropertyChangeListener。。。
这个涉及到org.jdesktop.application.TaskMonitor类的用法,靠大家去探索了。。。
先看看生成的代码:
// status bar initialization - message timeout, idle icon and busy animation, etc ResourceMap resourceMap = getResourceMap(); int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout"); messageTimer = new Timer(messageTimeout, new ActionListener() { public void actionPerformed(ActionEvent e) { statusMessageLabel.setText(""); } }); messageTimer.setRepeats(false); int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate"); for (int i = 0; i < busyIcons.length; i++) { busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]"); } busyIconTimer = new Timer(busyAnimationRate, new ActionListener() { public void actionPerformed(ActionEvent e) { busyIconIndex = (busyIconIndex + 1) % busyIcons.length; statusAnimationLabel.setIcon(busyIcons[busyIconIndex]); } }); idleIcon = resourceMap.getIcon("StatusBar.idleIcon"); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false); // connecting action tasks to status bar via TaskMonitor TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext()); taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if ("started".equals(propertyName)) { if (!busyIconTimer.isRunning()) { statusAnimationLabel.setIcon(busyIcons[0]); busyIconIndex = 0; busyIconTimer.start(); } progressBar.setVisible(true); progressBar.setIndeterminate(true); } else if ("done".equals(propertyName)) { busyIconTimer.stop(); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false); progressBar.setValue(0); } else if ("message".equals(propertyName)) { String text = (String)(evt.getNewValue()); statusMessageLabel.setText((text == null) ? "" : text); messageTimer.restart(); } else if ("progress".equals(propertyName)) { int value = (Integer)(evt.getNewValue()); progressBar.setVisible(true); progressBar.setIndeterminate(false); progressBar.setValue(value); } } });
是不是很纠结呢……如果单独用progressBar的话还是很简单的:
分别用setMinimum setMaxmum 方法来设定进度条的起止量,用setValue更新进度条的显示。 setIndeterminate可以用于不确定的任务长度,你会看到进度条在不断摇摆。
上面的代码如果仔细看看也不难,主要是用两个timer分别实现了busyicon和定时清楚提示信息。用法如下:
//不确定模式 //这样你就可以看到进度条在摇摆,busyicon在转,信息显示了一会消失 this.progressBar.setVisible(true); this.progressBar.setIndeterminate(true); this.statusMessageLabel.setText("I am busy!"); this.messageTimer.start(); this.busyIconTimer.start(); //确定模式 //进度条每秒走十分之一 this.progressBar.setVisible(true); this.progressBar.setMaximum(10); this.progressBar.setMinimum(0); //this.progressBar.setIndeterminate(true); this.statusMessageLabel.setText("I am busy!"); this.messageTimer.start(); this.busyIconTimer.start(); new Timer(1000,new ActionListener() { public void actionPerformed(ActionEvent e) { progressBar.setValue(i++); } }).start();
不过很明显到目前为止我们还没有用到最初代码中的后半部分:taskMonitor.addPropertyChangeListener。。。
这个涉及到org.jdesktop.application.TaskMonitor类的用法,靠大家去探索了。。。
相关文章推荐
- 使用NetBeans开发Java桌面应用程序时修改应用的UI样式为Windows
- 创建一个 Java 应用数据库的桌面应用程序
- 创建一个 Java 应用数据库的桌面应用程序
- c/s结构windows桌面应用程序wpf教程-创建wpf应用
- nodejs+chromium 创建桌面应用程序
- 利用NetBeans构建一个 Java 桌面数据库应用程序
- Enlightenment 是窗口管理器,Enlightenment 是桌面外壳,Enlightenment是创建漂亮应用程序的材料
- 让iOS的应用程序在点击设备的home键返回桌面后,再次打开应用进入启动画面
- 利用NetBeans构建一个 Java 桌面数据库应用程序
- Android开发:为指定的应用创建桌面快捷方式
- Ubuntu下如何在桌面创建一个应用程序的“快捷方式”?
- Creating Dialogbased Windows Application (2) / 创建基于对话框的Windows应用程序(二)Button的应用、新建子窗体 / VC++, Windows
- 利用NetBeans构建一个 Java 桌面数据库应用程序
- 在 Azure Web 应用中创建 .NET 应用程序
- 解析Android应用启动后自动创建桌面快捷方式的实现方法
- Android应用开发之(如何自动在桌面创建快捷方式)
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Windows桌面应用程序(1-2-3-4th) 在COM中创建一个对象
- html postMessage 创建聊天应用
- python-创建桌面应用--了解