HILFE JPanel - Graphics

mcm19

Mitglied
Hallo zusammen,
ich schreibe morgen eine Prüfung und irgendwie habe ich ein Fehler:( Kann mir jemand vielleicht helfen?
Die Aufgabe:
1644334809383.png>>>>>1644334778256.png
Java:
import java.awt.*;
import javax.swing.*;
import java.awt.Graphics.*;
import java.awt.Color;
   

public class MusterPanel extends JFrame {
   
    public MusterPanel()
      {
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        init(); }
   
    private void init()
      {this.setTitle("Muster Fenster");
        this.setSize(350, 350);

        JPanel frame = new JPanel();
        frame.validate();
        frame.setVisible(true);
        this.setContentPane(frame);
      }
    private int buh;
    public MusterPanel(int value) {
        this.setSize(value, value);
        buh = value;
    }
    public void paint(Graphics g) {
        g.setColor(Color.BLACK);
        for (int y = 0; y < buh; y += 20)
            for (int x = 0; x < buh; x += 20) {
                g.fillRect(x, y, 10, 10);
       
            }
    }
        public static void main(String[]args) {
            MusterPanel test = new MusterPanel();
            test.setSize(350, 350);
            test.validate();
            test.setVisible(true);
           
                     }  
        }
 

Neue Themen


Oben