import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import javax.swing.*;
public class AreaIntersect extends JApplet {
Ellipse2D.Double leaf = new Ellipse2D.Double();
Ellipse2D.Double stem = new Ellipse2D.Double();
Area leaf1 = new Area(leaf);
Area leaf2 = new Area(leaf);
public void init() {
setBackground(Color.white);
}
public void paint (Graphics g) {
Graphics2D g2 = (Graphics2D) g;
double halfWdith = getSize().width/2;
double halfHeight = getSize().height/2;
g2.setColor(Color.green);
leaf.setFrame(halfWdith-16, halfHeight-29, 15.0, 15.0);
leaf1 = new Area(leaf);
leaf.setFrame(halfWdith-14, halfHeight-47, 30.0, 30.0);
leaf2 = new Area(leaf);
leaf1.intersect(leaf2);
g2.fill(leaf1);
}
public static void main(String s[]) {
JFrame f = new JFrame("Pear");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
JApplet applet = new AreaIntersect();
f.getContentPane().add("Center", applet);
applet.init();
f.pack();
f.setSize(new Dimension(150,200));
f.show();
}
}
|