I would like to know about the error that I am getting. I am trying to set individual pixels on a jframe with the bufferedimage class, but for some reason when I try to add them to the frame, I get an error saying that no suitable method has been found.
Here is my code and the error can someone please tell me how to add the bufferedimage to the frame please.
import javax.swing.JFrame;
import java.awt.image.BufferedImage;
public class gui {
public static void main(String[] args) {
int width = 40;
int height = 80;
int[] data = new int [width * height];
JFrame frame = new JFrame("gui");
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
image.setRGB(0, 0, width, height, data, 0, width);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(image);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Error:
gui.java:15: error: no suitable method found for add(BufferedImage)
frame.add(image);
^
method Container.add(Component,Object,int) is not applicable
(actual and formal argument lists differ in length)
method Container.add(Component,Object) is not applicable
(actual and formal argument lists differ in length)
method Container.add(Component,int) is not applicable
(actual and formal argument lists differ in length)
method Container.add(String,Component) is not applicable
(actual and formal argument lists differ in length)
method Container.add(Component) is not applicable
(actual argument BufferedImage cannot be converted to Component by method invocation conversion)
method Component.add(PopupMenu) is not applicable
(actual argument BufferedImage cannot be converted to PopupMenu by method invocation conversion)
1 error