Created
November 19, 2015 19:47
-
-
Save AnnaBoro/54f11a5af0ca796f5634 to your computer and use it in GitHub Desktop.
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
package lesson6.shapes; | |
import java.awt.*; | |
public class Circle extends Shape { | |
public Circle() { | |
} | |
@Override | |
public void draw(Graphics g) { | |
System.out.println("Draw circle"); | |
g.setColor(new Color(0, 240, 40)); | |
g.drawOval(50, 50, 100, 100); | |
} | |
} |
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
package lesson6.shapes; | |
import java.awt.*; | |
/** | |
* Created by anna on 19.11.15. | |
*/ | |
public class Launcher2 { | |
public static void main(String[] args) { | |
Shape shape = new Shape(); | |
new ShapesTemplate(shape.fillShapeArr()); | |
} | |
} |
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
package lesson6.shapes; | |
import java.awt.*; | |
public class Rectangle extends Shape { | |
public Rectangle() { | |
} | |
@Override | |
public void draw(Graphics g) { | |
System.out.println("Draw rectangle"); | |
g.setColor(new Color(255, 90, 90)); | |
g.fillRect(150, 150, 100, 200); | |
} | |
} |
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
package lesson6.shapes; | |
import java.awt.*; | |
public class Shape{ | |
public Shape() { | |
} | |
public void draw(Graphics g) { | |
} | |
public Shape[] fillShapeArr() { | |
Shape[] shape = new Shape[3]; | |
shape[0] = new Triangle(); | |
shape[1] = new Circle(); | |
shape[2] = new Rectangle(); | |
return shape; | |
} | |
} |
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
package lesson6.shapes; | |
import java.awt.Dimension; | |
import java.awt.Graphics; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
import javax.swing.WindowConstants; | |
public class ShapesTemplate extends JPanel { | |
private Shape[] shapes; | |
public ShapesTemplate(Shape[] shapes) { | |
this.shapes = shapes; | |
if (shapes == null || shapes.length < 1) { | |
this.shapes = new Shape[0]; | |
} | |
JFrame frame = new JFrame("DAY 6, 2D Graphics"); | |
frame.setLocation(750, 150); | |
frame.setMinimumSize(new Dimension(600, 400)); | |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | |
frame.getContentPane().add(this); | |
frame.pack(); | |
frame.setVisible(true); | |
repaint(); | |
} | |
@Override | |
protected void paintComponent(Graphics g) { | |
for (Shape s : shapes) { | |
s.draw(g); | |
} | |
} | |
} |
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
package lesson6.shapes; | |
import java.awt.*; | |
public class Triangle extends Shape { | |
public Triangle() { | |
} | |
@Override | |
public void draw(Graphics g) { | |
System.out.println("Draw triangle"); | |
g.setColor(new Color(0, 0, 255)); | |
int[] arrayX = {300, 600, 450}; | |
int[] arrayY = {100, 100, 300}; | |
Graphics2D g2d = (Graphics2D) g; | |
g2d.setStroke(new BasicStroke(3)); | |
g.drawPolygon(arrayX, arrayY, 3); | |
g2d.setStroke(new BasicStroke()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment