How to add an image to a JPanel?
I have a JPanel to which I’d like to add JPEG and PNG images that I generate on the fly. All the examples … Read more
I have a JPanel to which I’d like to add JPEG and PNG images that I generate on the fly. All the examples … Read more
How do I draw a triangle?
Usage depends on whether the component’s parent has a layout manager or not. setSize() — use when a parent layout manager does not exist; … Read more
Here’s how I do it (with a little more info on how to load an image): import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import … Read more
How to repaint a JPanel after have drawn on it?
JPanel doesn’t have ActionListener capabilities. Instead, you need to use a MouseListener import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.GridLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import … Read more