1 /*
2 *
3 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of Oracle nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
124 g2.setColor(BLACK);
125 g2.fill(st1);
126
127 // Creates the pear itself by filling the Area resulting from the
128 // union of two Area objects created by two different ellipses.
129 Ellipse2D circle = new Ellipse2D.Double(x - 25, y, 50.0, 50.0);
130 Ellipse2D oval = new Ellipse2D.Double(x - 19, y - 20, 40.0, 70.0);
131 Area circ = new Area(circle);
132 circ.add(new Area(oval));
133
134 g2.setColor(YELLOW);
135 g2.fill(circ);
136 return;
137 }
138
139 g2.fill(area);
140 g2.setColor(RED);
141 g2.draw(area);
142 }
143
144 public static void main(String argv[]) {
145 createDemoFrame(new Areas());
146 }
147
148
149 static final class DemoControls extends CustomControls implements
150 ActionListener {
151
152 Areas demo;
153 JToolBar toolbar;
154 JComboBox combo;
155
156 public DemoControls(Areas demo) {
157 super(demo.name);
158 this.demo = demo;
159 add(toolbar = new JToolBar());
160 toolbar.setFloatable(false);
161 addTool("nop", "no area operation", true);
162 addTool("add", "add", false);
163 addTool("sub", "subtract", false);
164 addTool("xor", "exclusiveOr", false);
|
1 /*
2 *
3 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of Oracle nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
124 g2.setColor(BLACK);
125 g2.fill(st1);
126
127 // Creates the pear itself by filling the Area resulting from the
128 // union of two Area objects created by two different ellipses.
129 Ellipse2D circle = new Ellipse2D.Double(x - 25, y, 50.0, 50.0);
130 Ellipse2D oval = new Ellipse2D.Double(x - 19, y - 20, 40.0, 70.0);
131 Area circ = new Area(circle);
132 circ.add(new Area(oval));
133
134 g2.setColor(YELLOW);
135 g2.fill(circ);
136 return;
137 }
138
139 g2.fill(area);
140 g2.setColor(RED);
141 g2.draw(area);
142 }
143
144 public static void main(String[] argv) {
145 createDemoFrame(new Areas());
146 }
147
148
149 static final class DemoControls extends CustomControls implements
150 ActionListener {
151
152 Areas demo;
153 JToolBar toolbar;
154 JComboBox combo;
155
156 public DemoControls(Areas demo) {
157 super(demo.name);
158 this.demo = demo;
159 add(toolbar = new JToolBar());
160 toolbar.setFloatable(false);
161 addTool("nop", "no area operation", true);
162 addTool("add", "add", false);
163 addTool("sub", "subtract", false);
164 addTool("xor", "exclusiveOr", false);
|