Skip to content
Permalink
50a373dac2
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
53 lines (43 sloc) 1.63 KB
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);
}
}