Hello, I'm trying to fill a shape using TexturePaint in java. However when i'm running the codes i'm having the following errors: Exception in thread "main" java.lang.Error: Unresolved compilation problems: ImageIO cannot be resolved IOException cannot be resolved to a type at Textures.
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test1 extends JPanel {
BufferedImage img;
TexturePaint imgTp;
public Test1() {
try {
slate = ImageIO.read(this.getClass().getResource("greycar.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
imgTp = new TexturePaint(slate, new Rectangle(0, 0, 90, 60));
g2d.setPaint(imgTp);
g2d.fillRect(25, 30, 80, 60);
}
public static void main(String[] args) {
Test1 t=new Test1();
JFrame frame = new JFrame("Texture paint");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(t);
frame.setSize(360, 120);
frame.setVisible(true);
}
}