I'm not sure about "paint", but I can explain the relationship between repaint () and paintComponent ().
In my limited experience with java, the paintComponent () method is a method of the JPanel class and is a member of the "swing".
The paintComponent () method handles the entire painting. Essentially, it draws everything you want in JPanel, which is a Graphic object.
repaint () is the inherited instance method for all JPanel objects. Calling [your_JPanel_object] .repaint () calls the paintComponent () method.
Every time you want to change the look of your JPanel, you must call repaint ().
Some actions automatically call the repaint () method:
- Window resizing
- Window minimization and maximization
to name a few.
In SHORT, paintComponent () is a method defined in JPanel or your own custom class that extends JPanel. repaint () is a method called in another class (like JFrame) that ultimately calls paintComponent ().
here is an example:
public class MyPanel extends JPanel{ public void paintComponent(Graphics g){ super.paintComponent(g); g.draw([whatever you want]); ... ... } } public class MyFrame extends JFrame{ public MyFrame(){ MyPanel myPanel = new MyPanel(); myPanel.repaint(); } }
source share