I have been given an assignment to create a GUI that allows a user to change parts of an image by selecting checkboxes(for different parts of an image) and clicking a button. However, I am having trouble figuring out exactly how I am supposed to get multiple images to lay on top of one another in a JPanel to create a single image. The instructions I have been given regarding this part are as follows:
A picture panel, that is implemented as a separate class that extends JPanel. It draws the picture (in my case the face) with the three features, and each of those features is a separate image.
Your picture can be anything you want as long as it is not a face. However, it needs to include three exchangeable features and those features need to be placed appropriately to fit the context (e.g. the mouth needs to be below the eyes and it needs to fit inside the face).
FYI: One way to create a picture based on multiple images is by overriding the method paintComponent and by calling paintIcon (a method from the interface Icon) on the ImageIcon object. There is no need to pass a Component object. You can pass null instead.
I have tried to do some research regarding paintComponent and paintIcon, but I still can't seem to figure it out. This is nothing we have ever covered and class, and now with the Coronavirus(campus being closed) it is super difficult to get any actual help from professors. Anyways, here is the code I have so far. If you can help point me in the right direction it would be greatly appreciated!
public class PicturePanel extends JPanel {
private Image TShirt;
public void paintComponent(Graphics g) {
super.paintComponent(g);
ImageIcon tShirt = new ImageIcon("TShirt.png");
TShirt = tShirt.getImage();
tShirt.paintIcon(this, g, 0, 0);
}
/**
* Create the panel.
*/
public PicturePanel() {
JPanel panel = new JPanel();
panel.setVisible(true);
}
All in all I have a person I drew where I can change their top, bottom, and shoes, but I have no idea how to implement this.