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();
}
}发布于 2020-08-02 02:55:25
既然类JWindow已经扩展了JWindow,那么为什么要创建内部JWindow呢?没有必要这样做。你在搞乱你的程序。
如何?,您实际上是在通过jw.setVisible(true);查看内部JWindow,但是您正在CreateSplashScreen的“`JWindow”中绘制图像。
试试下面的代码:
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();
}
}注意:我不知道您从源文件夹中获取图像资源的方法。
编辑:假设包含类CreateSplashScreen的包的名称是createsplashscreen,请确保图像testImage.png存在于项目的createsplashscreen包中。
发布于 2020-08-04 14:49:09

@Peter作为错误代码,我删除了在mamifest.mf文件中添加的一行代码,并构建了一个程序.这一次,没有给我一个错误,奇怪.当我得到错误代码时,我正在跟踪它,它引导我找到应用程序生成代码的"CLASSPATH“部分.对不起,我记不起来了,真的很感谢彼得的帮助。祝你好运..。
https://stackoverflow.com/questions/63211712
复制相似问题