小程序启动屏幕、JWIndow?
这是我的第三个问题。请再次帮助...我想在我的小程序上放置一个启动屏幕。为此,我使用了 JWindow 组件。我已经使用它为我的独立 java 应用程序创建启动屏幕,所以我认为它也适用于小程序。问题是,它不起作用。 Jwindow可以和applet一起使用吗?有更好的方法来实现这一点吗? tnx很多!
我在小程序的启动方法中实例化 LoadingScreen 对象? 这是代码:
public class LoadingScreen extends JWindow{
private static final long serialVersionUID = 1L;
private Image image1;
private ImageIcon icon1;
public LoadingScreen(){
//image = Toolkit.getDefaultToolkit().getImage("WebContent/images/loadbar.gif");
image1 = getImage(getCodeBase(), "images/loadbar.gif");
icon1= new ImageIcon(image1);
setSize(icon1.getIconWidth(), icon1.getIconHeight());
setLocationRelativeTo(null);
setVisible(true);
try{
//Make JWindow appear for 5 seconds before disappear
Thread.sleep(5000);
dispose();
System.exit(0);
}catch(Exception exception){
exception.printStackTrace();
}
}
public void paint(Graphics g){
super.paint(g);
g.drawImage(image1,0,0,null);
}
}
更新! 问题解决了。对小程序启动方法内的静态 Thread.sleep 方法的调用有点阻止资源(图像)加载。这就是它不显示的原因。它是通过创建一个单独的计时器线程来进行实际计数来修复的...只是为了让每个人都知道...:)
This is my 3rd SO question. Please help again... I want to put up a splashscreen on my applet. In doing so, I used the JWindow component. I already used it in creating splashscreens for my stand-alone java application so I thought it will also work on applet. The problem is, it does not work. Is Jwindow usable with applet? is there a better way to accomplish this? tnx a lot!
I instantiate LoadingScreen object in the applet's start method?
Here is the code:
public class LoadingScreen extends JWindow{
private static final long serialVersionUID = 1L;
private Image image1;
private ImageIcon icon1;
public LoadingScreen(){
//image = Toolkit.getDefaultToolkit().getImage("WebContent/images/loadbar.gif");
image1 = getImage(getCodeBase(), "images/loadbar.gif");
icon1= new ImageIcon(image1);
setSize(icon1.getIconWidth(), icon1.getIconHeight());
setLocationRelativeTo(null);
setVisible(true);
try{
//Make JWindow appear for 5 seconds before disappear
Thread.sleep(5000);
dispose();
System.exit(0);
}catch(Exception exception){
exception.printStackTrace();
}
}
public void paint(Graphics g){
super.paint(g);
g.drawImage(image1,0,0,null);
}
}
Update!
Problem solved. The call to the static Thread.sleep method inside the applet start method sort of stop the resources (image) from loading.. that's why it's not showing. It was fixed by creating a separate timer Thread to do the actual counting... Just so everyone knows...:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么要重写 Paint(...) 方法来显示图像?将 ImageIcon 添加到 JLabel 并将标签添加到窗口。然后您只需使用 pack() 方法来调整窗口大小。
我不知道 JWindow 是否有效。也许大小为零,因为设置大小时图像尚未加载。
或者,您可以尝试使用未修饰的 JFrame。
Why did you override the paint(...) method to display an image? Add the ImageIcon to a JLabel and add the label to the window. Then you just use the pack() method to size the window.
I don't know if a JWindow works or not. Maybe the size is zero because the image hasn't been loaded when you set the size.
Or, you could try using an undecorated JFrame.
问题解决了。对小程序启动方法内的静态 Thread.sleep 方法的调用有点阻止资源(图像)加载。这就是它不显示的原因。它是通过创建一个单独的计时器线程来进行实际计数来修复的...只是为了让每个人都知道...:)
Problem solved. The call to the static Thread.sleep method inside the applet start method sort of stop the resources (image) from loading.. that's why it's not showing. It was fixed by creating a separate timer Thread to do the actual counting... Just so everyone knows...:)