1 package com.badlogic.gdx.tools.flame; 2 3 import java.awt.Dimension; 4 import java.awt.Graphics; 5 import java.awt.image.BufferedImage; 6 import java.io.File; 7 import java.io.IOException; 8 9 import javax.imageio.ImageIO; 10 import javax.swing.JPanel; 11 12 /** @author Inferno */ 13 public class ImagePanel extends JPanel{ 14 private BufferedImage image; 15 ImagePanel()16 public ImagePanel() {} 17 setImage(BufferedImage image)18 public void setImage(BufferedImage image){ 19 this.image = image; 20 } 21 setImage(String file)22 public void setImage (String file) { 23 try { 24 image = ImageIO.read( new File(file) ); 25 } catch (IOException e) { 26 e.printStackTrace(); 27 } 28 } 29 30 @Override paintComponent(Graphics g)31 protected void paintComponent(Graphics g) { 32 super.paintComponent(g); 33 g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters 34 } 35 36 @Override getPreferredSize()37 public Dimension getPreferredSize () { 38 Dimension dimension = super.getPreferredSize(); 39 if(image != null){ 40 dimension.width = image.getWidth(); 41 dimension.height = image.getHeight(); 42 } 43 return dimension; 44 } 45 }