当前位置: 技术问答>java相关
我想做个启动画面的窗口
来源: 互联网 发布时间:2015-01-16
本文导语: 1 窗口的那个标题栏怎么去掉? 2 怎么读个图片到窗口上? | import java.awt.*; import java.awt.event.*; import javax.swing.*; public class splash extends JFrame { Toolkit kit = Toolkit.getDefaultToolkit(); JWindow jw = ...
1 窗口的那个标题栏怎么去掉?
2 怎么读个图片到窗口上?
2 怎么读个图片到窗口上?
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class splash extends JFrame
{
Toolkit kit = Toolkit.getDefaultToolkit();
JWindow jw = new JWindow();
JLabel la = new JLabel(new ImageIcon("a.jpg"));
public splash()
{
la.setBorder(BorderFactory.createRaisedBevelBorder());
jw.getContentPane().add(la,BorderLayout.CENTER);
centerWindow();
jw.show();
jw.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
jw.dispose();
System.exit(0);
}
});
}
private void centerWindow()
{
Dimension sc = kit.getScreenSize();
Dimension ls = la.getPreferredSize();
int law = ls.width;
int lah = ls.height;
jw.setLocation(sc.width/2 - (law/2),sc.height/2 - (lah/2));
jw.pack();
}
public static void main(String args[])
{
JFrame fr = new splash();
}
}
import java.awt.event.*;
import javax.swing.*;
public class splash extends JFrame
{
Toolkit kit = Toolkit.getDefaultToolkit();
JWindow jw = new JWindow();
JLabel la = new JLabel(new ImageIcon("a.jpg"));
public splash()
{
la.setBorder(BorderFactory.createRaisedBevelBorder());
jw.getContentPane().add(la,BorderLayout.CENTER);
centerWindow();
jw.show();
jw.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
jw.dispose();
System.exit(0);
}
});
}
private void centerWindow()
{
Dimension sc = kit.getScreenSize();
Dimension ls = la.getPreferredSize();
int law = ls.width;
int lah = ls.height;
jw.setLocation(sc.width/2 - (law/2),sc.height/2 - (lah/2));
jw.pack();
}
public static void main(String args[])
{
JFrame fr = new splash();
}
}
|
希望这个对你有帮助
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.awt.image.*;
public class Test extends Panel
{
Image img = null;
BufferedImage bimg = null;
public Test() {
Toolkit t = getToolkit();
img = t.getImage("Create.gif");
bimg = new BufferedImage(360,200,BufferedImage.TYPE_INT_RGB);
Frame f = new Frame();
Window win = new Window(f);
win.setBackground(Color.lightGray);
win.add(this);
f.pack();
f.setVisible(false);
win.setSize(360,200);
setLoca(win);
win.show();
}
public void paint(Graphics g)
{
Graphics g1 = bimg.getGraphics();
g1.drawImage(img,0,0,this);
g.drawImage(bimg,0,0,this);
}
public void setLoca(Window win)
{
Toolkit tk = win.getToolkit();
Dimension d = tk.getScreenSize();
int x = 0;
int y = 0;
x = d.width/2 - 180;
y = d.height/2 - 100;
win.setLocation(x,y);
}
public static void main(String args[])
{
new Test();
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.awt.image.*;
public class Test extends Panel
{
Image img = null;
BufferedImage bimg = null;
public Test() {
Toolkit t = getToolkit();
img = t.getImage("Create.gif");
bimg = new BufferedImage(360,200,BufferedImage.TYPE_INT_RGB);
Frame f = new Frame();
Window win = new Window(f);
win.setBackground(Color.lightGray);
win.add(this);
f.pack();
f.setVisible(false);
win.setSize(360,200);
setLoca(win);
win.show();
}
public void paint(Graphics g)
{
Graphics g1 = bimg.getGraphics();
g1.drawImage(img,0,0,this);
g.drawImage(bimg,0,0,this);
}
public void setLoca(Window win)
{
Toolkit tk = win.getToolkit();
Dimension d = tk.getScreenSize();
int x = 0;
int y = 0;
x = d.width/2 - 180;
y = d.height/2 - 100;
win.setLocation(x,y);
}
public static void main(String args[])
{
new Test();
}
}
|
frameImage = new ImageIcon(package.Frame.class.getResource("main.gif"));
setIconImage(frameIamge);
启动窗口不要是frame,用个labe比较好上面弄副图.
setIconImage(frameIamge);
启动窗口不要是frame,用个labe比较好上面弄副图.