//这是闪烁窗口类/*
* Created on 2004-8-10
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package frameApp;/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import java.awt.*;
import javax.swing.*;public class splash extends JWindow
{
splash()
{
JPanel panel = new JPanel()
{
//for painting the component
public void paintComponent(Graphics g)
{
//for getting the image
ImageIcon img = new ImageIcon(ClassLoader.getSystemResource ("frameApp/images/Logo.JPG"));
//for drawing the image
g.drawImage(img.getImage(), 0, 0, null);
super.paintComponent(g);
}
};
//for setting the border
panel.setOpaque(false);
//for setting the panel in the contentPane
panel.setBorder(BorderFactory.createEtchedBorder());
//for setting the ContentPane to true
setContentPane(panel);
//for setting the background
panel.setBackground(Color.black);
setSize(350, 250);
Dimension frameSize = getSize();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
setVisible(true);
}
}
* Created on 2004-8-10
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package frameApp;/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import java.awt.*;
import javax.swing.*;public class splash extends JWindow
{
splash()
{
JPanel panel = new JPanel()
{
//for painting the component
public void paintComponent(Graphics g)
{
//for getting the image
ImageIcon img = new ImageIcon(ClassLoader.getSystemResource ("frameApp/images/Logo.JPG"));
//for drawing the image
g.drawImage(img.getImage(), 0, 0, null);
super.paintComponent(g);
}
};
//for setting the border
panel.setOpaque(false);
//for setting the panel in the contentPane
panel.setBorder(BorderFactory.createEtchedBorder());
//for setting the ContentPane to true
setContentPane(panel);
//for setting the background
panel.setBackground(Color.black);
setSize(350, 250);
Dimension frameSize = getSize();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
setVisible(true);
}
}
public static void main (String args [])
{
/*有两种启动方法;
* 1. 用线程启动
* 2. 普通方法, 直接在本类中启动
*/
//方法1
//new thread().start();
//方法2
try
{
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
JFrame.setDefaultLookAndFeelDecorated (true);
JDialog.setDefaultLookAndFeelDecorated (true);
splash myLogo = new splash ();//for creting an object
myLogo.show(); //show the logo
new frameApp();//for running the progam
myLogo.hide(); //hide the logo
myLogo = null; // no longer use it
}
catch (Exception e)
{
System.out.println(e.toString());
}
finally
{
System.out.println ("系统启动完毕!");
}
}
import java.lang.Runnable;
import java.awt.*;
public class Logo extends JWindow implements Runnable {
String filename; //Logo图像文件的文件名
public Logo(String name) {
filename = name;
}
public void run()
{
ImageIcon ig = new ImageIcon(filename);
JButton btn = new JButton(ig); //将图片给JButton显示
getContentPane().add(btn); //将显示图片的btn加到JPanel里
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize(); //获得屏幕的大小
setLocation(screenSize.width/2-150, screenSize.height/2-100);//将Logo窗口显示在屏幕宽的1/4,高的1/4处
setSize(ig.getIconWidth(), ig.getIconHeight()); //将Logo窗口大小设成图像的大小
toFront(); //将Logo窗口显示为最前面的窗口
setVisible(true);
}
public void setNotVisible()
{
setVisible(false);
}
}主程序
Logo lg =new Logo("splash.gif");
lg.run();
lg.setNotVisible();
logoImg=getToolkit().getImage( ClassLoader.getSystemResource("splesh.jpg"));
请问上边两句有问题吗?
我用icon也可以实现,就是用image不行,
还有,提示的错误的原因是什么运行时提示信息如下:
Uncaught error fetching image:java.lang.NullPointerException at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:99) at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:108) at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:248) at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172) at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
casinosun(姑苏慕容) (
这老兄的应该不会闪烁。 cuizm(射天狼) (
这老兄的可能是因为这句://for setting the background
panel.setBackground(Color.black);
所以闪烁。要不就是super.paint..调用顺序问题。
谁来说说为什么会闪烁啊?我也听听。呵呵。
还有啊 ,看起来像现有的应用程序这样好的启动界面还是挺难做的。
大家有什么好办法嘛?