Estoy realizando un ejercicio en java, donde me muestra nombres en diferentes colores en un cuadro texto. Sin embargo, en Netbeans no me lo ejecuta dándome el siguiente mensaje, en la sentencia setTitle("Dos Elipses");
:
Calling methods that can be overridden can be dangerous in the constructor because in the moment when the overridden method is called the object is not fully initialized.
Código:
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package j009;
/**
*
* @author
*/
import java.awt.*;
import java.awt.event.*;
class j009 extends Frame{
public j009(){
setTitle("Dos Elipses"); // <------------ aquí está el error
}
}
public class J009 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Frame f = new j009();
f.addWindowListener(new WindowAdapter(){
public void windowCLosing(WindowEvent e){
System.exit(0);
}
});
f.setSize(400,300);
f.setVisible(true);
}
public void paint(Graphics g){
g.setColor(Color.red);
g.drawString("Hola",50,50);
g.setColor(Color.blue);
g.drawString("Hola", 100, 100);
g.setColor(Color.green);
g.drawString("Hola", 200, 150);
g.setColor(Color.yellow);
g.drawString("Hola", 300, 200);
}
}