[英]Using jWindow as splash screen which shows good but image doesn't paint … just blank jWindow opened…any thoughts?
public class CreateSplashScreen extends JWindow {
JWindow jw = new JWindow();
Image scImage = Toolkit.getDefaultToolkit().getImage("testImage.png");
ImageIcon imageIcon = new ImageIcon(scImage);
public CreateSplashScreen() {
try {
jw.setSize(700, 500);
jw.setLocationRelativeTo(null);
jw.setVisible(true);
} catch (Exception e) {
}
}
public void paint(Graphics g) {
super.paint(g);
g.drawImage(scImage, 0, 0, jw);
}
public void CloseSplashScreen() {
jw.setVisible(false);
}
public static void main(String[] args) {
CreateSplashScreen sp = new CreateSplashScreen();
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
Logger.getLogger(CreateSplashScreen.class.getName()).log(Level.SEVERE, null, ex);
}
sp.CloseSplashScreen();
}
}
Why are you creating an internal JWindow
when your class CreateSplashScreen
already extends JWindow
?当您的 class
CreateSplashScreen
已经扩展JWindow
JWindow
There is no need of it.没有必要。 You are messing with your program.
你在弄乱你的程序。
How?如何? You are actually viewing the inner
JWindow
by jw.setVisible(true);
您实际上是通过
jw.setVisible(true);
查看内部JWindow
; but you are painting the image in the CreateSplashScreen
's `JWindow.但是您正在
CreateSplashScreen
的 `JWindow.
Try this code:试试这个代码:
public class CreateSplashScreen extends JWindow
{
ImageIcon i = new ImageIcon(getClass().getResource("/createsplashscreen/testImage.png"));
public CreateSplashScreen() {
setSize(700, 500);
setLocationRelativeTo(null);
setVisible(true);
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(i.getImage(), 0, 0, null);
}
public void CloseSplashScreen() {
setVisible(false);
}
public static void main(String[] args) {
CreateSplashScreen sp = new CreateSplashScreen();
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
}
sp.CloseSplashScreen();
}
}
Note: I do not know about your method to fetch image resource from the source folder.注意:我不知道您从源文件夹中获取图像资源的方法。
Edit: Assuming that the name of the package containing your class CreateSplashScreen
is createsplashscreen
, make sure that the image testImage.png
is present in the createsplashscreen
package of your project.编辑:假设包含您的 class
CreateSplashScreen
的createsplashscreen
的名称是createsplashscreen
,请确保图像testImage.png
存在于您的 project.
@Peter For error code, I deleted one line that I added in mamifest.mf file and build a program... This time, didn't give me an error, weird... I was following error code when I got it and it led me to something like "CLASSPATH" section of application generated code... sorry I can't remember exactly Really appreciate Peter for your help. @Peter对于错误代码,我删除了我在 mamifest.mf 文件中添加的一行并构建了一个程序...这一次,没有给我错误,很奇怪...当我得到它时我正在遵循错误代码并且它使我进入了应用程序生成代码的“CLASSPATH”部分......对不起,我不记得完全感谢彼得的帮助。 Wish you luck...
祝您好运...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.