diff --git a/7.x/P7.17 Purse/Cloud.java b/7.x/P7.17 Purse/Cloud.java new file mode 100644 index 0000000..850285e --- /dev/null +++ b/7.x/P7.17 Purse/Cloud.java @@ -0,0 +1,34 @@ +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.Ellipse2D; +import java.awt.geom.Point2D; + +/** + Classe che rappresenta lo stato di una lampadina + @author radaelli11353 +*/ +public class Cloud { + public static final int DIAMETRO = 5; + private Point2D.Double[] punti; + private int nPunti; + + public Cloud() { + punti = new Point2D.Double[100]; + nPunti = 0; + } + + public void add(Point2D.Double aPoint) { + if(nPunti >= punti.length) throw new IllegalArgumentException(); + punti[nPunti] = aPoint; + nPunti++; + } + + public void draw(Graphics2D g2) { + for(int i = 0; i < nPunti; i++) { + Ellipse2D.Double punto = new Ellipse2D.Double(punti[i].getX(), punti[i].getY(), DIAMETRO, DIAMETRO); + g2.setColor(Color.RED); + g2.draw(punto); + g2.fill(punto); + } + } +} \ No newline at end of file diff --git a/7.x/P7.17 Purse/CloudComponent.java b/7.x/P7.17 Purse/CloudComponent.java new file mode 100644 index 0000000..e85b5e3 --- /dev/null +++ b/7.x/P7.17 Purse/CloudComponent.java @@ -0,0 +1,28 @@ +import java.awt.Graphics; +import java.awt.Graphics2D; +import javax.swing.JComponent; +import java.awt.geom.Point2D; +import java.util.Random; + +/** + Classe che estende JComponent per creare un componente Lampadina + @author radaelli11353 +*/ +public class CloudComponent extends JComponent { + /** + Metodo paintComponent che si occupa di disegnare una lampadina + @param g Contesto grafico di Graphics + */ + public void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + Random generator = new Random(); + + Cloud nuvola = new Cloud(); + + for(int i = 0; i < 100; i++) { + nuvola.add(new Point2D.Double(generator.nextDouble()*400, generator.nextDouble()*400)); + } + + nuvola.draw(g2); + } +} \ No newline at end of file diff --git a/7.x/P7.17 Purse/CloudViewer.java b/7.x/P7.17 Purse/CloudViewer.java new file mode 100644 index 0000000..1a03051 --- /dev/null +++ b/7.x/P7.17 Purse/CloudViewer.java @@ -0,0 +1,24 @@ +import javax.swing.JFrame; + +/** + Classe che visualizza una lampadina tramite un JFrame e LampadinaComponent + @author radaelli11353 +*/ +public class CloudViewer { + /** + Metodo main di LampadinaViewer + @param args Argomenti passati all'esecuzione del programma + */ + public static void main(String[] args) { + JFrame frame = new JFrame(); + + frame.setSize(500, 500); + frame.setTitle("Visualizzatore nuvola"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + CloudComponent component = new CloudComponent(); + frame.add(component); + + frame.setVisible(true); + } +} \ No newline at end of file diff --git a/7.x/P7.18 Polygon/Polygon.java b/7.x/P7.18 Polygon/Polygon.java new file mode 100644 index 0000000..2b866e9 --- /dev/null +++ b/7.x/P7.18 Polygon/Polygon.java @@ -0,0 +1,32 @@ +import java.awt.Graphics2D; +import java.awt.geom.Point2D; +import java.awt.geom.Line2D; + +/** + Classe che rappresenta lo stato di una lampadina + @author radaelli11353 +*/ +public class Polygon { + public static final int DIAMETRO = 5; + private Point2D.Double[] punti; + private int nPunti; + + public Polygon() { + punti = new Point2D.Double[100]; + nPunti = 0; + } + + public void add(Point2D.Double aPoint) { + if(nPunti >= punti.length) throw new IllegalArgumentException(); + punti[nPunti] = aPoint; + nPunti++; + } + + public void draw(Graphics2D g2) { + for(int i = 0; i < nPunti - 1; i++) { + Line2D.Double linea = new Line2D.Double(punti[i].getX(), punti[i].getY(), punti[i+1].getX(), punti[i+1].getY()); + g2.draw(linea); + } + g2.draw(new Line2D.Double(punti[nPunti - 1].getX(), punti[nPunti - 1].getY(), punti[0].getX(), punti[0].getY())); + } +} \ No newline at end of file diff --git a/7.x/P7.18 Polygon/PolygonComponent.java b/7.x/P7.18 Polygon/PolygonComponent.java new file mode 100644 index 0000000..0ad79c1 --- /dev/null +++ b/7.x/P7.18 Polygon/PolygonComponent.java @@ -0,0 +1,36 @@ +import java.awt.Graphics; +import java.awt.Graphics2D; +import javax.swing.JComponent; +import java.awt.geom.Point2D; +import java.util.Random; + +/** + Classe che estende JComponent per creare un componente Lampadina + @author radaelli11353 +*/ +public class PolygonComponent extends JComponent { + /** + Metodo paintComponent che si occupa di disegnare una lampadina + @param g Contesto grafico di Graphics + */ + public void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + + Polygon quadrato = new Polygon(); + Polygon pentagono = new Polygon(); + + quadrato.add(new Point2D.Double(0, 0)); + quadrato.add(new Point2D.Double(50, 0)); + quadrato.add(new Point2D.Double(50, 50)); + quadrato.add(new Point2D.Double(0, 50)); + + pentagono.add(new Point2D.Double(100, 100)); + pentagono.add(new Point2D.Double(70, 80)); + pentagono.add(new Point2D.Double(50, 50)); + pentagono.add(new Point2D.Double(150, 70)); + pentagono.add(new Point2D.Double(120, 100)); + + quadrato.draw(g2); + pentagono.draw(g2); + } +} \ No newline at end of file diff --git a/7.x/P7.18 Polygon/PolygonViewer.java b/7.x/P7.18 Polygon/PolygonViewer.java new file mode 100644 index 0000000..bb45650 --- /dev/null +++ b/7.x/P7.18 Polygon/PolygonViewer.java @@ -0,0 +1,24 @@ +import javax.swing.JFrame; + +/** + Classe che visualizza una lampadina tramite un JFrame e LampadinaComponent + @author radaelli11353 +*/ +public class PolygonViewer { + /** + Metodo main di LampadinaViewer + @param args Argomenti passati all'esecuzione del programma + */ + public static void main(String[] args) { + JFrame frame = new JFrame(); + + frame.setSize(500, 500); + frame.setTitle("Visualizzatore poligono"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + PolygonComponent component = new PolygonComponent(); + frame.add(component); + + frame.setVisible(true); + } +} \ No newline at end of file