CopyPastor

Detecting plagiarism made easy.

Score: 0.8009853959083557; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2018-03-05
by henry.dv

Original Post

Original - Posted on 2008-11-18
by Brendan Cashman



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Images can be incorporated fairly easily into a JFrame/JPanel using this `ImageComponent`-class (you can handle it just like any other component) :
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.*;
class ImageComponent extends Component {
BufferedImage img;
public void paint(Graphics g) { g.drawImage(img, 0, 0, null); }
public ImageComponent(String path) { try { img = ImageIO.read(new File(path)); } catch (IOException e) { e.printStackTrace(); } }
public Dimension getPreferredSize() { if (img == null) { return new Dimension(100,100); } else { return new Dimension(img.getWidth(), img.getHeight()); } } }
Here's how I do it (with a little more info on how to load an image):
import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.swing.JPanel; public class ImagePanel extends JPanel{ private BufferedImage image;
public ImagePanel() { try { image = ImageIO.read(new File("image name and path")); } catch (IOException ex) { // handle exception... } } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(image, 0, 0, this); // see javadoc for more info on the parameters } }

        
Present in both answers; Present only in the new answer; Present only in the old answer;