[Java]在窗口界面上画出硬盘中图片文件

  利用类javax.swing.JPanel来在窗口界面上画图。图片文件通过javax.imageio.ImageIO类来获取。

[Java]在窗口界面上画出硬盘中图片文件
 1 import java.awt.Graphics;
 2 import java.awt.image.BufferedImage;
 3 import java.io.File;
 4 import java.io.IOException;
 5 
 6 import javax.imageio.ImageIO;
 7 import javax.swing.JFrame;
 8 import javax.swing.JPanel;
 9 
10 import com.Sunday.TankWar.configure.TankWarConfigure;
11 
12 public class ImageFrame {
13 
14     private BufferedImage image;
15     private String imageName = "home.jpg";
16 
17     public ImageFrame() throws IOException {
18         image = ImageIO.read(new File(TankWarConfigure.imagePath + imageName));
19     }
20 
21     @SuppressWarnings("serial")
22     class Background extends JPanel {
23         public void paint(Graphics g) {
24             g.drawImage(image, 0, 0, null);
25             g.drawImage(image, 100, 100, null);
26         }
27     }
28 
29     public static void main(String[] args) throws Exception {
30         ImageFrame image = new ImageFrame();
31         JPanel jpanel = image.new Background();
32         JFrame frame = new JFrame("图片测试");
33         frame.add(jpanel);
34         frame.setBounds(0, 0, 200, 220);
35         frame.setVisible(true);
36     }
37 
38 }
[Java]在窗口界面上画出硬盘中图片文件

[Java]在窗口界面上画出硬盘中图片文件,布布扣,bubuko.com

[Java]在窗口界面上画出硬盘中图片文件

上一篇:配置vim,快捷键添加作者信息&C语言语法设置


下一篇:HttpRunner2.X开源接口测试框架学习(七):跳过用例