Java - Duda con paintComponent

 
Vista:
sin imagen de perfil
Val: 82
Ha disminuido su posición en 6 puestos en Java (en relación al último mes)
Gráfica de Java

Duda con paintComponent

Publicado por System.out.println("Me llamo Carlos") (43 intervenciones) el 21/05/2020 16:59:17
Estoy comenzando con el tema de swing y awt, y me surge la siguiente duda:

¿En este método que es lo que estoy haciendo?

1
2
3
4
5
6
7
8
9
class Lamina extends JPanel {
 
    public void paintComponent(Graphics g) {
 
        super.paintComponent(g);
 
        g.drawString("Estamos aprendiendo swing", 200, 200);
    }
}
Estoy usando un metodo llamada paintComponent que recibe como parametro un objeto de tipo Graphics, esto si, ¿ Pero que se supone que se esta haciendo con el super.paintComponent? Estoy llamando al mismo método dentro de otro que sobrescribe al mismo ...No entiendo.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Duda con paintComponent

Publicado por Tom (1831 intervenciones) el 21/05/2020 18:03:31
Y ¿ por qué no te lees un tutorial, o algo, antes de empezar ?

https://docs.oracle.com/javase/tutorial/uiswing/painting/index.html

Copio y pego:

The paintComponent method is where all of your custom painting takes place. This method is defined by javax.swing.JComponent and then overridden by your subclasses to provide their custom behavior. Its sole parameter, a java.awt.Graphics object, exposes a number of methods for drawing 2D shapes and obtaining information about the application's graphics environment. In most cases the object that is actually received by this method will be an instance of java.awt.Graphics2D (a Graphics subclass), which provides support for sophisticated 2D graphics rendering.

Most of the standard Swing components have their look and feel implemented by separate "UI Delegate" objects. The invocation of super.paintComponent(g) passes the graphics context off to the component's UI delegate, which paints the panel's background. For a closer look at this process, see the section entitled "Painting and the UI Delegate" in the aforementioned SDN article.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar