我想知道如何显示应用程序的加载。通常(假设 Netbeans IDE)
该应用程序将显示其已加载的程度以及要加载的程度。此外,还可以在欢迎页面中看到加载类。这是如何完成的以及我们如何在应用程序中显示类加载和加载状态(在进度栏中)?另外,假设我们已经使用了 Hibernate,并且首页上有一个登录,启动需要时间,但只是启动(我认为这是因为 Hibernate 工厂正在启动并加载其类)。答案寄希望于Java。
I want to know how to show the loading of an application. Normally (let's say Netbeans IDE,)
the application will show how far it has loaded and how far to load. Also, loading classes as well can be seen in welcome page. How is this is done and how we can show our classes loading and loaded status (in a progress bar) in our applications? Also let's say that we have used Hibernate, and there is a login on first page, it takes time to start but only for the starting (I think it is because that the Hibernate factory is getting started and load its classes). The answer is hoped in Java.
发布评论
评论(4)
请参阅 java.awt.SplashScreen 类。但是..
..带有定制图像。调用 SplashScreen.createGraphics() 获取可以在其上绘制的
Graphics
对象(来自清单中定义为启动画面的图像)。在 Graphics 对象上的适当位置绘制进度条。对于进度条,可以使用前面提到的 JProgressBar,或者为了保持简洁(使用纯 AWT),绘制一个大的矩形
来表示进度条,并填充较小的矩形
来表示进度。另请参阅 Java 教程中的如何创建启动屏幕 。 (您可以在上面看到该图片。)
See the java.awt.SplashScreen class. But..
..with a customized image. Call SplashScreen.createGraphics() to get a
Graphics
object (from the image defined as a splash in the manifest) which can be drawn on. Draw the progress bar at an appropriate location on theGraphics
object. For the progress bar, either use aJProgressBar
as already mentioned, or to keep it lean (using pure AWT), draw one bigRectangle
to represent the bar, and fill a smallerRectangle
to represent the progress.See also How to Create a Splash Screen in the Java Tutorial. (Where you can see that image above.)
这听起来适合使用 JProgressBar ,结合 启动屏幕 或 JDialog。
确保必须在 事件上更新
JProgressBar
调度线程,更多关于并发性Swing,那么您有两种选择如何正确更新
JProgressBar
- 将代码包装到:可运行
/线程
That sounds for using JProgressBar, combined with Splash Screen or JDialog.
Be sure that
JProgressBar
must be updated on the Event Dispatch Thread, more about that in Concurrency in Swing,Then you have two choices as to how to update a
JProgressBar
correctly - by wrapping code into:Runnable
/Thread
swing 中为此内置了一些支持。请参阅有关如何使用进度条的教程来开始使用。
There is some support built into swing for this. See the tutorial on How to Use Progress Bars to get started.
这是一个非常基本的代码:
Here is a very basic code: