Created
August 9, 2012 20:15
-
-
Save sumtyme/3307711 to your computer and use it in GitHub Desktop.
Path2d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.awt.Dimension; | |
import java.awt.Graphics; | |
import java.awt.Graphics2D; | |
import java.awt.Rectangle; | |
import java.awt.geom.Ellipse2D; | |
import java.awt.geom.Path2D; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
@SuppressWarnings("serial") | |
public class GraphicTest extends JPanel{ | |
@Override | |
protected void paintComponent(Graphics g) { | |
super.paintComponent(g); | |
Graphics2D g2 = (Graphics2D) g; | |
g2.setColor(Color.RED); | |
g2.fillRect(0, 0, getWidth(), getHeight()); | |
g2.setColor(Color.BLUE); | |
Path2D path = new Path2D.Double(new Rectangle(getWidth() / 2 - 100, getHeight() / 2 - 100, 200, 200)); | |
path.setWindingRule(Path2D.WIND_EVEN_ODD); | |
path.append(new Ellipse2D.Double(getWidth() / 2 - 50, getHeight() / 2 - 50, 100, 100), false); | |
g2.fill(path); | |
} | |
@Override | |
public Dimension getPreferredSize() { | |
return new Dimension(500, 500); | |
} | |
public static void main(String[] args){ | |
JFrame frame = new JFrame(); | |
frame.setContentPane(new GraphicTest()); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.pack(); | |
frame.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment