Overlap.java Source code

Java tutorial

Introduction

Here is the source code for Overlap.java

Source

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Overlap extends JPanel {
    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.getContentPane().add(new Overlap());
        f.setSize(300, 200);
        f.setVisible(true);
    }

    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        double x = 15, y = 50, w = 70, h = 70;
        Ellipse2D e = new Ellipse2D.Double(x, y, w, h);
        g2.setStroke(new BasicStroke(8));

        Color smokeyColor = new Color(128, 128, 128, 128);
        g2.setPaint(smokeyColor);
        g2.fill(e);
        g2.draw(e);

        e.setFrame(x + 100, y, w, h);
        g2.setPaint(Color.black);
        g2.draw(e);
        g2.setPaint(Color.gray);
        g2.fill(e);

        e.setFrame(x + 200, y, w, h);
        g2.setPaint(Color.gray);
        g2.fill(e);
        g2.setPaint(Color.black);
        g2.draw(e);
    }
}