Hallo,
Ich bekomme es nicht hin einem Frame ein Panel hinzuzufügen. Hier mein Code:
Schonmal danke im Vorraus und Schöne Festtage.
Ich bekomme es nicht hin einem Frame ein Panel hinzuzufügen. Hier mein Code:
Code:
import javax.swing.*;
import java.awt.*;
public class GUI extends JFrame {
private JPanel panel;
public GUI() {
setSize(300,300);
setVisible(true);
setTitle("Gui");
setBackground(Color.RED);
getRootPane();setVisible(true);
add(new MyPanel());
}
class MyPanel extends JPanel {
MyPanel(){
JPanel panel = new JPanel();
panel.setBounds(50,50, 100,100);
panel.setBackground(Color.RED);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.fillRect(70,70,100,100);
}
}
public static void main(String[] args) {
new GUI();
}
}