T
There are two types of components involved, the components heavyweight and lightweight. The components heavyweight rely heavily on details implemented in native code to work (i.e. C and C++) and because of this, their performance tends to be (but not necessarily is) a little better, but leaving them much harder to use, in addition to sometimes relying on specific details of the operating system sacrificing compatibility. The components lightweight are made 100% in Java, without requiring native code.The components heavyweight are AWT (for example, java.awt.Button), while the lightweight are the Swing (for example, javax.swing.JButton). Direct use of components heavyweight is discouraged a long time ago.All AWT components are subclasses of java.awt.Component. One of these subclasses, java.awt.Container is special because it corresponds to a component that may contain subcomponents. A special subclass Container is the class javax.swing.JComponent which is the superclass of all Swing components. This hierarchy also means that any Swing components may contain subcomponents.The drawing of all of them is based on the method https://docs.oracle.com/javase/8/docs/api/java/awt/Component.html#paint-java.awt.Graphics- . However, it is not recommended to overwrite or invoke this method directly.A redesign of a component can be forced with the use of the method https://docs.oracle.com/javase/8/docs/api/java/awt/Component.html#repaint- .A component heavyweight that has its dirty screen drawing, can be redesigned by the AWT through the method https://docs.oracle.com/javase/8/docs/api/java/awt/Component.html#update- . The standard implementation, only cleans the drawing area of the whole component and calls the paint() to redesign it, but more specialized implementations can make incremental updates or determine which areas are dirty and redesign only those. Again, the method update() should not be called directly.However, the concept of incremental drawing and the use of update() has been confused and almost always unnecessary, so this is not used for components lightweight. In the components lightweight, a call to update() is in practice the same as a call to paint(). In the components lightweight, the method paint() implemented in the class JComponent only calls the methods paintComponent(Graphics), paintBorder(Graphics) and paintChildren(Graphics) in this order ( https://docs.oracle.com/javase/8/docs/api/javax/swing/JComponent.html#paint-java.awt.Graphics- ). As the names suggest, they respectively draw the component, draw the edge of the component and draw the subcomponents. Although you can overwrite any of these methods, you will normally want to overwrite only the paintComponent(Graphics).In the end, in both cases, who realizes the drawing is https://docs.oracle.com/javase/8/docs/api/java/awt/Graphics.html . However, AWT will always use an instance of https://docs.oracle.com/javase/8/docs/api/java/awt/Graphics2D.html , then you can do the cast safely if you need to have access to a larger and better set of available methods.And remembering that at the end of the day, who controls everything is the AWT. Swing is just a layer over the AWT, not a complete replacement. Swing is only an AWT replacement with respect to replacing components heavyweight by components lightweight.There is another important detail to be noted: https://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html , https://docs.oracle.com/javase/8/docs/api/javax/swing/JDialog.html and https://docs.oracle.com/javase/8/docs/api/javax/swing/JWindow.html are not subclasses of JComponent, so they do not have the method paintComponent(Graphics)but have the method paint(Graphics). In this case, you may then prefer to overwrite paint(Graphics) invoking a super.paint(g) inside him. However, in the case of JFrames JDialogs, perhaps it is better to add a JPanel inside and then overwrite the paintComponent(Graphics) the JPanel.TL;DR: That is, in the end, what matters is that to implement the design of your subclass JComponent, you should overwrite the method paintComponent(Graphics). For subclasses JFrame, JDialog and JWindow, you overwrite the paint(Graphics) Yeah.More details in http://www.oracle.com/technetwork/java/painting-140037.html