【发布时间】:2013-12-28 15:11:25
【问题描述】:
问题是:当我关闭主程序时,我有一个带有一些图像的小窗口(退出屏幕),这个图像不可见,只有框架。当我启动程序时,我还有另一个图像,这个图像在屏幕上可见,但第二个(关闭时)不可见。当我在 Eclipse 中编译这个类时,一切正常,但是当我运行 MAIN 程序时它没有。两者都是从同一个类生成的,但区别在于构造函数的参数。这两个 PNG 文件都在此项目的 JAR 文件和 WorkSpace 所在的文件夹中。请帮忙。
闪屏代码:
package Models;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;
import MainProject.ExpertSystem;
public class SplashScreen extends JWindow {
private static final long serialVersionUID = 1L;
private int duration;
private ExpertSystem context;
private String graphicPath;
private boolean exit = false;
int width,height;
private boolean showContext;
public SplashScreen(int d, ExpertSystem context,String graphicPath,boolean exit,int width, int height,boolean showContext) {
duration = d;
this.graphicPath = graphicPath;
this.context = context;
this.exit = exit;
this.width = width;
this.height = height;
this.showContext = showContext;
showSplashAndExit();
}
public SplashScreen(int d)
{
duration = d;
}
// A simple little method to show a title screen in the center
// of the screen for the amount of time given in the constructor
public void showSplash() {
JPanel content = (JPanel)getContentPane();
content.setBackground(Color.white);
// Set the window's bounds, centering the window
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width-width)/2;
int y = (screen.height-height)/2;
setBounds(x,y,width,height);
// Build the splash screen
JLabel label = new JLabel(new ImageIcon(graphicPath));
JLabel copyrt = new JLabel("Copyright 2013, Dariusz Kruk", JLabel.CENTER);
copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 12));
content.add(label, BorderLayout.CENTER);
content.add(copyrt, BorderLayout.SOUTH);
//Color oraRed = new Color(156, 20, 20, 255);
// content.setBorder(BorderFactory.createLineBorder(oraRed, 0));
// Display it
setVisible(true);
// Wait a little while, maybe while loading resources
try
{
Thread.sleep(duration);
} catch (Exception e) {}
setVisible(false);
}
public void showSplashAndExit() {
showSplash();
if(showContext == true)
{
context.setVisible(true);
}
dispose();
//System.exit(0);
if(exit == true)
{
System.exit(0);
}
}
public static void main(String[] args) {
// Throw a nice little title page up on the screen first
SplashScreen splash = new SplashScreen(5000);
// Normally, we'd call splash.showSplash() and get on with the program.
// But, since this is only a test...
splash.showSplashAndExit();
}
}
启动欢迎屏幕:
public ExpertSystem()
{
introduction = new SplashScreen(5000,this,"Multimedia/AIWelcome.png",false,478,150,true);
..........
..........
}
启动退出屏幕:
else if(input == mWyjscie)
{
int odpo=JOptionPane.showConfirmDialog(this, "Czy na pewno wyjsc?","Pytanie",JOptionPane.YES_NO_OPTION);
if(odpo==JOptionPane.YES_OPTION)
{
this.setVisible(false);
exit = new SplashScreen(5000,this,"Multimedia/e.jpg",true,613,173,false);
}
else if(odpo==JOptionPane.NO_OPTION)
{
}
}
【问题讨论】:
-
等一下,您在第一次加载时正在看到图像吗?另外,是斜线屏幕,用于打开关闭,相同的对象
-
是的。我看到第一个 SplashScreen 和第二个框架。 SplashScreen 类有两个对象
-
所以中间没有程序?你只是想测试你的启动画面?
-
这是我粘贴在这里的一部分代码,因为它真的很长。
标签: java eclipse user-interface