import javax.swing.*;
import java.awt.*;

public class DrawRectangle extends JPanel {

    public void paintComponent(Graphics g) {
	super.paintComponent(g);         // always include this
        g.drawLine(100, 100, 100, 200);
        g.drawLine(100, 200, 300, 200);
        g.drawLine(300, 200, 300, 100);
        g.drawLine(300, 100, 100, 100);
    }
    
    public static void main(String[] args) {
        DrawRectangle drawRectangle = new DrawRectangle();
        JFrame frame = new JFrame("Draw Rectangle");
	frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.getContentPane().add(drawRectangle);
        frame.setSize(400, 300);
        frame.setVisible(true);
    }
}
