import java.awt.*; import javax.swing.*; public class BasicDraw { public static void main(String[] args) { new BasicDraw(); } BasicDraw() { // Create a frame JFrame frame = new JFrame(); // Add a component with a custom paint method frame.getContentPane().add(new MyComponent()); // Display the frame int frameWidth = 300; int frameHeight = 300; frame.setSize(frameWidth, frameHeight); frame.setVisible(true); } class MyComponent extends JComponent { // This method is called whenever the contents needs to be painted public void paint(Graphics g) { // Retrieve the graphics context; this object is used to paint shapes Graphics2D g2d = (Graphics2D)g; // Draw an oval that fills the window int x = 0; int y = 0; int width = getSize().width-1; int height = getSize().height-1; g2d.drawOval(x, y, width, height); } } }