当前位置: 技术问答>java相关
怎么加入启动封面?
来源: 互联网 发布时间:2015-03-07
本文导语: | import java.awt.*; import java.awt.event.*; public class splashTest extends Frame { Toolkit toolkits=Toolkit.getDefaultToolkit(); Window Windows; Image Images; public static void main(String args[]) { Frame frame=new splashTest(); } public splashTes...
|
import java.awt.*;
import java.awt.event.*;
public class splashTest extends Frame
{
Toolkit toolkits=Toolkit.getDefaultToolkit();
Window Windows;
Image Images;
public static void main(String args[])
{
Frame frame=new splashTest();
}
public splashTest()
{
ImageCanvas Canvas1;
Windows =new Window(this);
Images =toolkits.getImage("saint.jpg");
Canvas1 =new ImageCanvas(Images);
Windows.add(Canvas1,"Center");
Dimension scrnSize =toolkits.getScreenSize();
int imgWidth =Images.getWidth(this),
imgHeight=Images.getHeight(this);
Windows.setLocation(scrnSize.width/2-(imgWidth/2),
scrnSize.height/2-(imgHeight/2));
Windows.setSize(imgWidth,imgHeight);
Windows.show();
Windows.toFront();
try {Thread.currentThread().sleep(20000);}
catch(Exception e) {e.printStackTrace();}
Windows.dispose();
System.exit(0);
}
}
class ImageCanvas extends Canvas
{
private Image Images;
public ImageCanvas(Image Images)
{
MediaTracker mt=new MediaTracker(this);
mt.addImage(Images,0);
try {mt.waitForID(0);}
catch(Exception e) { e.printStackTrace();}
this.Images=Images;
}
public void paint(Graphics g)
{
g.drawImage(Images,0,0,this);
}
public void update(Graphics g)
{
paint(g);
}
public Dimension getPreferredSize()
{
return new Dimension(Images.getWidth(this),Images.getHeight(this));
}
}
你自己找一个图片命名saint.jpg
import java.awt.event.*;
public class splashTest extends Frame
{
Toolkit toolkits=Toolkit.getDefaultToolkit();
Window Windows;
Image Images;
public static void main(String args[])
{
Frame frame=new splashTest();
}
public splashTest()
{
ImageCanvas Canvas1;
Windows =new Window(this);
Images =toolkits.getImage("saint.jpg");
Canvas1 =new ImageCanvas(Images);
Windows.add(Canvas1,"Center");
Dimension scrnSize =toolkits.getScreenSize();
int imgWidth =Images.getWidth(this),
imgHeight=Images.getHeight(this);
Windows.setLocation(scrnSize.width/2-(imgWidth/2),
scrnSize.height/2-(imgHeight/2));
Windows.setSize(imgWidth,imgHeight);
Windows.show();
Windows.toFront();
try {Thread.currentThread().sleep(20000);}
catch(Exception e) {e.printStackTrace();}
Windows.dispose();
System.exit(0);
}
}
class ImageCanvas extends Canvas
{
private Image Images;
public ImageCanvas(Image Images)
{
MediaTracker mt=new MediaTracker(this);
mt.addImage(Images,0);
try {mt.waitForID(0);}
catch(Exception e) { e.printStackTrace();}
this.Images=Images;
}
public void paint(Graphics g)
{
g.drawImage(Images,0,0,this);
}
public void update(Graphics g)
{
paint(g);
}
public Dimension getPreferredSize()
{
return new Dimension(Images.getWidth(this),Images.getHeight(this));
}
}
你自己找一个图片命名saint.jpg