Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;

public class Main {

    public static void main(String[] args) throws Exception {
        URL url = new URL("http://www.java2s.com/style/download.png");
        BufferedImage origImg = ImageIO.read(url);

        JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(origImg)));

        File newFile = new File("new.png");
        ImageIO.write(origImg, "png", newFile);
        BufferedImage newImg = ImageIO.read(newFile);

        JOptionPane.showMessageDialog(null, new JLabel("New", new ImageIcon(newImg), SwingConstants.LEFT));
    }
}