In this example we show how the Set operations going to make a Subtraction of 2 circles . Subtraction examples how the code as follows:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
import java.awt.geom.*;
import java.awt.image.*;
public class DrawsubtractExample extends Applet {
public static void main(String[] args) {
Frame Drawsubtract = new Frame("Draw subtract Example");
Drawsubtract.setSize(350, 250);
Applet DrawsubtractExample = new DrawsubtractExample();
Drawsubtract.add(DrawsubtractExample);
Drawsubtract.setVisible(true);
Drawsubtract.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void paint(Graphics g) {
g.setColor(Color.blue);
g.setFont(new Font("Arial",Font.BOLD,14));
g.drawString("Draw subtract Example", 50, 40);
g.setFont(new Font("Arial",Font.BOLD,10));
g.drawString("http://ecomputernotes.com", 200, 205);
Graphics2D G2D = (Graphics2D)g;
GradientPaint GPaint = new GradientPaint(50.0f, 50.0f, Color.red,200.0f, 50.0f, Color.green);
G2D.setPaint(GPaint);
Ellipse2D E2D = new Ellipse2D.Double(50.0, 50.0, 80.0, 80.0);
Ellipse2D E2D2 = new Ellipse2D.Double(100.0, 50.0, 80.0, 80.0);
Area area1 = new Area(E2D);
Area area2 = new Area(E2D2);
area1.subtract(area2);
G2D.fill(area1);
}
}