// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.*;
import javax.swing.*;

public class ShowBoxes extends JFrame {
   public ShowBoxes() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      getContentPane().setLayout(new BorderLayout());
      JPanel p1 = new MyBox(0, 0, 50, 50);
      p1.setForeground(Color.red);
      getContentPane().add(p1, BorderLayout.NORTH);
      JLabel lbl2 = new JLabel("tekst");
      getContentPane().add(lbl2, BorderLayout.CENTER);
      JPanel p3 = new MyBox(0, 0, 50, 50);
      p3.setForeground(Color.blue);
      getContentPane().add(p3, BorderLayout.SOUTH);
      pack();
   }
   public static void main(String[] args) {
      ShowBoxes f = new ShowBoxes();
      f.show();
   }
}

class MyBox extends JPanel {
   private int x, y, w, h;
   public MyBox(int x, int y, int w, int h) {
      this.x = x;
      this.y = y;
      this.w = w;
      this.h = h;
   }
   public void paintComponent(Graphics g) {
      g.fillRect(x, y, w, h);
   }
}
