A simple applet that shows labels with six different types of border.

/*******************************************************
*     MYCPLUS Sample Code - https://www.mycplus.com     *
*                                                     *
*   This code is made available as a service to our   *
*      visitors and is provided strictly for the      *
*               purpose of illustration.              *
*                                                     *
* Please direct all inquiries to saqib at mycplus.com *
*******************************************************/


// A simple applet that shows labels with six different types of border.

import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;

public class BorderDemo extends JApplet {

   public void init() {
      setBackground(Color.lightGray);
      getContentPane().setBackground( Color.lightGray );
      getContentPane().setLayout( new GridLayout(0,1,7,7) );
      make(BorderFactory.createLineBorder(Color.red,2),
          "BorderFactory.createLineBorder(Color.red,2)");
      make(BorderFactory.createMatteBorder(2,2,5,5,Color.red),
          "BorderFactory.createMatteBorder(2,2,5,5,Color.red)");
      make(BorderFactory.createEtchedBorder(),
          "BorderFactory.createEtchedBorder()");
      make(BorderFactory.createRaisedBevelBorder(),
          "BorderFactory.createRaisedBevelBorder()");
      make(BorderFactory.createLoweredBevelBorder(),
          "BorderFactory.createLoweredBevelBorder()");
      make(BorderFactory.createTitledBorder("Title Goes Here"),
          "BorderFactory.createTitledBorder(\"Title Goes Here\")");
   }

   void make(Border border, String command) {
         // Make a lable showing the string and with the specified border.
         // The label will be opaque and will have a light gray background.
         // The label is added to the applet's content pane.
      JLabel label = new JLabel(command, JLabel.CENTER);
      label.setBackground(Color.lightGray);
      label.setOpaque(true);
      label.setBorder(border);
      getContentPane().add(label);
   }

   public Insets getInsets() {
        // Leave a border around the applet where the background
        // color will show through.
      return new Insets(7,7,7,7);
   }

} // end class JApplet