Pixel Colorization Start with the pixel-coloring program we wrote in class. Howe
ID: 3680213 • Letter: P
Question
Pixel Colorization Start with the pixel-coloring program we wrote in class. However, instead of extending JFrame, the class should extend JPanel. The class should have the following: • Instance variables: image (store the BufferedImage), drawLayer (boolean indicating if a layer should be drawn), coordinates (ArrayList of coordinates to draw in red) • Constructor: Load the Jurassic image. • findTan method: Find all the pixels that are close to tan (the color of the ground) and save their coordinates in the coordinates ArrayList, then set drawLayer to true and repaint the JPanel • resetTan method: Sets drawLayer to false and repaints the JPanel • paintComponent method: draw the Jurassic image on the panel, then if drawLayer is true, draw Red pixels over all the Tan coordinates. Make a JFrame window with a BorderLayout. Put your class from above (that extends JPanel) in the CENTER of the JFrame. In the SOUTH of the JFrame add a button that invokes findTan() and another that invokes resetTan() using the FlowLayout. Pixel Colorization Start with the pixel-coloring program we wrote in class. However, instead of extending JFrame, the class should extend JPanel. The class should have the following: • Instance variables: image (store the BufferedImage), drawLayer (boolean indicating if a layer should be drawn), coordinates (ArrayList of coordinates to draw in red) • Constructor: Load the Jurassic image. • findTan method: Find all the pixels that are close to tan (the color of the ground) and save their coordinates in the coordinates ArrayList, then set drawLayer to true and repaint the JPanel • resetTan method: Sets drawLayer to false and repaints the JPanel • paintComponent method: draw the Jurassic image on the panel, then if drawLayer is true, draw Red pixels over all the Tan coordinates. Make a JFrame window with a BorderLayout. Put your class from above (that extends JPanel) in the CENTER of the JFrame. In the SOUTH of the JFrame add a button that invokes findTan() and another that invokes resetTan() using the FlowLayout. Pixel Colorization Start with the pixel-coloring program we wrote in class. However, instead of extending JFrame, the class should extend JPanel. The class should have the following: • Instance variables: image (store the BufferedImage), drawLayer (boolean indicating if a layer should be drawn), coordinates (ArrayList of coordinates to draw in red) • Constructor: Load the Jurassic image. • findTan method: Find all the pixels that are close to tan (the color of the ground) and save their coordinates in the coordinates ArrayList, then set drawLayer to true and repaint the JPanel • resetTan method: Sets drawLayer to false and repaints the JPanel • paintComponent method: draw the Jurassic image on the panel, then if drawLayer is true, draw Red pixels over all the Tan coordinates. Make a JFrame window with a BorderLayout. Put your class from above (that extends JPanel) in the CENTER of the JFrame. In the SOUTH of the JFrame add a button that invokes findTan() and another that invokes resetTan() using the FlowLayout.Explanation / Answer
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class BackgroundImageJFrame extends JFrame
{
JButton b1;
JLabel l1;
public BackgroundImageJFrame()
{
setTitle("Background Color for JFrame");
setSize(400,400);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
setLayout(new BorderLayout());
setContentPane(new JLabel(new ImageIcon("C:\Users\Computer\Downloads\colorful design.png")));
setLayout(new FlowLayout());
l1=new JLabel("Here is a button");
b1=new JButton("I am a button");
add(l1);
add(b1);
setSize(399,399);
setSize(400,400);
}
public static void main(String args[])
{
new BackgroundImageJFrame();
}
}