Warum funktioniert die Malmethode nicht so, funktioniert aber auf die zweite Art?Warum Farbe nicht funktioniert?
Erster Weg:
public class Ex extends JFrame{
public static void main(String args[]){
JFrame frame=new JFrame("Title");
frame.setVisible(true);
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g){
super.paint(g);
g.drawString("HEllo", 500, 500);
}
}
Zweiter Weg: arbeitet Warum?
public class Ex extends JFrame{
{
this.setTitle("Title");
this.setSize(800, 600);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
new Ex();
}
public void paint(Graphics g){
super.paint(g);
g.drawString("HEllo", 500, 500);
}
}
Siehe auch [Erkennung/Fix für die hängende schließen Klammer eines Codeblocks] (http://meta.stackexchange.com/q/251795/155831) für ein Problem, das ich in dieser Frage beheben musste. Bitte verwenden Sie Code-Formatierung für Code und Code-Snippets, strukturierte Dokumente wie HTML/XML oder Eingabe/Ausgabe. Um dies zu tun, ** wähle den Text aus und klicke auf den '{}' Button oben im Nachrichten-Posting/Editier-Formular. ** –
'JFrame' ist keine Instanz von' Ex' – MadProgrammer