java 1 find a set of images at least 3 2 display two displayregions with a line of t 5122139
Java 1. find a set of images (at least 3), (2) display two displayregions (with a line of text under each: “original image” and“clipped image) for the output—one is the original image andanother clipped one, and (3) add two buttons: “>” for viewingforward and “
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;
import java.net.URL;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*; public class Clip extends JApplet {
public static void main(String s[]) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JApplet applet = new Clip();
applet.init();
frame.getContentPane().add(applet);
frame.pack();
frame.setVisible(true);
}
public void init() {
JPanel panel = new ClipPanel();
getContentPane().add(panel);
}
} class ClipPanel extends JPanel{
BufferedImage image;
public ClipPanel() {
setPreferredSize(new Dimension(400, 400));
setBackground(Color.white);
URL url =getClass().getClassLoader().getResource(“Image.jpg”);
try {
image = ImageIO.read(url);
} catch (IOException ex) {
ex.printStackTrace();
}
} public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D)g;
int w = this.getWidth();
int h = this.getHeight();
Shape clip = new Ellipse2D.Double(w/5, h/5, 3*w/5, 3*h/5);
g2.setClip(clip);
g2.drawImage(image, 0, 0, w, h, this);
}
} Asked May. 13, 2018 . . .