import java.awt.*; import javax.swing.JPanel; import javax.swing.JFrame; public class Draw { public static void main(String args[]) { JFrame frame = new JFrame("Draw"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DrawPanel panel = new DrawPanel(); frame.add(panel); frame.setPreferredSize(new Dimension(1000, 500)); frame.pack(); frame.setVisible(true); } } class DrawPanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); g.drawLine(0, 0, getWidth(), getHeight()); g.drawRect(20, 20, getWidth()-100, getHeight()-100); } }