Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
shapes/ShapesPanel.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
53 lines (43 sloc)
1.63 KB
This file contains 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 javax.swing.*; | |
import java.awt.*; | |
public class ShapesPanel extends JPanel{ | |
private SmartEllipse _ellipse; | |
private SmartRectangle _rectangle; | |
private SmartRectangle _diamond; | |
private Polygon _triangle; | |
private SmartRectangle _star1; | |
private SmartRectangle _star2; | |
public ShapesPanel(){ | |
_ellipse = new SmartEllipse(java.awt.Color.BLUE); | |
_ellipse.setLocation(200,200); | |
_ellipse.setSize(50,50); | |
_rectangle = new SmartRectangle(java.awt.Color.RED); | |
_rectangle.setLocation(300,250); | |
_rectangle.setSize(70,100); | |
_diamond = new SmartRectangle(java.awt.Color.GREEN); | |
_diamond.setLocation(86, 75); | |
_diamond.setSize(30,30); | |
_diamond.setRotation(150); | |
_star1 = new SmartRectangle(java.awt.Color.GRAY); | |
_star1.setLocation(500,100); | |
_star1.setSize(60,60); | |
_star1.setRotation(150); | |
_star2 = new SmartRectangle(java.awt.Color.GRAY); | |
_star2.setLocation(500,100); | |
_star2.setSize(60,60); | |
} | |
public void paintComponent(java.awt.Graphics aBrush) { | |
super.paintComponent(aBrush); | |
java.awt.Graphics2D aBetterBrush = (java.awt.Graphics2D) aBrush; | |
_ellipse.fill(aBetterBrush); | |
_rectangle.fill(aBetterBrush); | |
_diamond.fill(aBetterBrush); | |
_star1.fill(aBetterBrush); | |
_star2.fill(aBetterBrush); | |
int[] tr1 = {10, 20, 30}; | |
int[] tr2 = {60, 50, 60}; | |
_triangle = new Polygon(tr1, tr2, 3); | |
aBrush.setColor(Color.yellow); | |
aBrush.fillPolygon(_triangle); | |
} | |
} |