java程序中怎么设置背景图片?
http://www.diybl.com/course/3_program/java/javajs/20090303/156858.html如以上链接java程序,如何在...
http://www.diybl.com/course/3_program/java/javajs/20090303/156858.html
如以上链接java程序,如何在猜对后显示一张背景图片?我图片文件已经放到java包里了!请高手帮忙!!1 展开
如以上链接java程序,如何在猜对后显示一张背景图片?我图片文件已经放到java包里了!请高手帮忙!!1 展开
展开全部
这是我在网上找到的,大家看看,我也是个超级菜鸟
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestBackground extends JFrame{
ImageIcon img;
public TestBackground(){
img = new ImageIcon("D:/temp/Winter.jpg");
JPanel panel = new JPanel(){
public void paintComponent(Graphics g){
g.drawImage(img.getImage(), 0, 0, null);
super.paintComponent(g);
}
};
panel.setOpaque(false);
panel.add( new JButton( "Hello" ) );
setContentPane( panel );
}
public static void main(String [] args){
TestBackground frame = new TestBackground();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestBackground extends JFrame{
ImageIcon img;
public TestBackground(){
img = new ImageIcon("D:/temp/Winter.jpg");
JPanel panel = new JPanel(){
public void paintComponent(Graphics g){
g.drawImage(img.getImage(), 0, 0, null);
super.paintComponent(g);
}
};
panel.setOpaque(false);
panel.add( new JButton( "Hello" ) );
setContentPane( panel );
}
public static void main(String [] args){
TestBackground frame = new TestBackground();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询