Aggiornato Shape
Aggiunti Square e TriangoloRettangolo. Aggiunto Viewer di test
This commit is contained in:
parent
a313c50eae
commit
f7f5965619
|
@ -1,2 +1,8 @@
|
||||||
compile.on.save=true
|
compile.on.save=true
|
||||||
user.properties.file=/home/giacomo/.netbeans/17/build.properties
|
do.depend=false
|
||||||
|
do.jar=true
|
||||||
|
do.jlink=false
|
||||||
|
javac.debug=true
|
||||||
|
javadoc.preview=true
|
||||||
|
jlink.strip=false
|
||||||
|
user.properties.file=/home/gicorada/.netbeans/17/build.properties
|
||||||
|
|
|
@ -3,7 +3,12 @@
|
||||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||||
<group>
|
<group>
|
||||||
<file>file:/home/giacomo/Scrivania/Scuola/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/Shape.java</file>
|
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/Square.java</file>
|
||||||
|
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/Tester.java</file>
|
||||||
|
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/Shape.java</file>
|
||||||
|
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/Circle.java</file>
|
||||||
|
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/TriangoloRettangolo.java</file>
|
||||||
|
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/ShapesViewer.java</file>
|
||||||
</group>
|
</group>
|
||||||
</open-files>
|
</open-files>
|
||||||
</project-private>
|
</project-private>
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processor.options=
|
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
annotation.processing.run.all.processors=true
|
annotation.processing.run.all.processors=true
|
||||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||||
|
application.title=shape
|
||||||
|
application.vendor=gicorada
|
||||||
build.classes.dir=${build.dir}/classes
|
build.classes.dir=${build.dir}/classes
|
||||||
build.classes.excludes=**/*.java,**/*.form
|
build.classes.excludes=**/*.java,**/*.form
|
||||||
# This directory is removed when the project is cleaned:
|
# This directory is removed when the project is cleaned:
|
||||||
|
@ -32,6 +33,7 @@ dist.jar=${dist.dir}/shape.jar
|
||||||
dist.javadoc.dir=${dist.dir}/javadoc
|
dist.javadoc.dir=${dist.dir}/javadoc
|
||||||
dist.jlink.dir=${dist.dir}/jlink
|
dist.jlink.dir=${dist.dir}/jlink
|
||||||
dist.jlink.output=${dist.jlink.dir}/shape
|
dist.jlink.output=${dist.jlink.dir}/shape
|
||||||
|
endorsed.classpath=
|
||||||
excludes=
|
excludes=
|
||||||
includes=**
|
includes=**
|
||||||
jar.compress=false
|
jar.compress=false
|
||||||
|
@ -71,11 +73,11 @@ jlink.additionalmodules=
|
||||||
jlink.additionalparam=
|
jlink.additionalparam=
|
||||||
jlink.launcher=true
|
jlink.launcher=true
|
||||||
jlink.launcher.name=shape
|
jlink.launcher.name=shape
|
||||||
main.class=shape.Tester
|
main.class=shape.ShapesViewer
|
||||||
manifest.file=manifest.mf
|
manifest.file=manifest.mf
|
||||||
meta.inf.dir=${src.dir}/META-INF
|
meta.inf.dir=${src.dir}/META-INF
|
||||||
mkdist.disabled=false
|
mkdist.disabled=false
|
||||||
platform.active=Oracle_OpenJDK_20_36
|
platform.active=Zulu_17.0.6_10
|
||||||
run.classpath=\
|
run.classpath=\
|
||||||
${javac.classpath}:\
|
${javac.classpath}:\
|
||||||
${build.classes.dir}
|
${build.classes.dir}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package shape;
|
package shape;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.Ellipse2D;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author radaelli11353
|
* @author radaelli11353
|
||||||
|
@ -41,10 +44,10 @@ public class Circle extends Shape {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = 3;
|
int hash = 5;
|
||||||
hash = 59 * hash + this.xc;
|
hash = 83 * hash + (int) (Double.doubleToLongBits(this.xc) ^ (Double.doubleToLongBits(this.xc) >>> 32));
|
||||||
hash = 59 * hash + this.yc;
|
hash = 83 * hash + (int) (Double.doubleToLongBits(this.yc) ^ (Double.doubleToLongBits(this.yc) >>> 32));
|
||||||
hash = 59 * hash + this.r;
|
hash = 83 * hash + (int) (Double.doubleToLongBits(this.r) ^ (Double.doubleToLongBits(this.r) >>> 32));
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +56,13 @@ public class Circle extends Shape {
|
||||||
if (o == null) return false;
|
if (o == null) return false;
|
||||||
if (getClass() != o.getClass()) return false;
|
if (getClass() != o.getClass()) return false;
|
||||||
Circle c = (Circle) o;
|
Circle c = (Circle) o;
|
||||||
return Double.compare(xc, c.xc) && Double.compare(yc, c.yc) && Double.compare(r, c.r);
|
return Double.compare(xc, c.xc) == 0 && Double.compare(yc, c.yc) == 0 && Double.compare(r, c.r) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Graphics2D g2) {
|
||||||
|
Ellipse2D.Double e = new Ellipse2D.Double(xc-r, yc-r, r*2, r*2);
|
||||||
|
|
||||||
|
g2.draw(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
package shape;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author radaelli11353
|
|
||||||
*/
|
|
||||||
public class Rectangle extends Shape {
|
|
||||||
private double x;
|
|
||||||
private double y;
|
|
||||||
private double w;
|
|
||||||
private double h;
|
|
||||||
|
|
||||||
public Rectangle(double x, double y, double w, double h) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.w = w;
|
|
||||||
this.h = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double width() {
|
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double height() {
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double posX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double posY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int hash = 5;
|
|
||||||
hash = 37 * hash + this.x;
|
|
||||||
hash = 37 * hash + this.y;
|
|
||||||
hash = 37 * hash + this.w;
|
|
||||||
hash = 37 * hash + this.h;
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (o == null) return false;
|
|
||||||
if (getClass() != o.getClass()) return false;
|
|
||||||
Rectangle r = (Rectangle) o;
|
|
||||||
return Double.compare(r, r.w) && Double.compare(h, r.h) && Double.compare(x, r.x) && Double.compare(y, r.y);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,7 @@
|
||||||
package shape;
|
package shape;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author radaelli11353
|
* @author radaelli11353
|
||||||
|
@ -10,6 +12,8 @@ public abstract class Shape implements Comparable<Shape> {
|
||||||
public abstract double posX();
|
public abstract double posX();
|
||||||
public abstract double posY();
|
public abstract double posY();
|
||||||
|
|
||||||
|
public abstract void draw(Graphics2D g2);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Shape o) {
|
public int compareTo(Shape o) {
|
||||||
return Double.compare(width() * height(), o.width() * o.height());
|
return Double.compare(width() * height(), o.width() * o.height());
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package shape;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author radaelli11353
|
||||||
|
*/
|
||||||
|
public class ShapesViewer {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
|
||||||
|
frame.setSize(600, 600);
|
||||||
|
frame.setTitle("Circles");
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
Tester component = new Tester();
|
||||||
|
frame.add(component);
|
||||||
|
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package shape;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author radaelli11353
|
||||||
|
*/
|
||||||
|
public class Square extends Shape {
|
||||||
|
private double x;
|
||||||
|
private double y;
|
||||||
|
private double l;
|
||||||
|
|
||||||
|
public Square(double x, double y, double l) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.l = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double width() {
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double height() {
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double posX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double posY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 7;
|
||||||
|
hash = 97 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32));
|
||||||
|
hash = 97 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
|
||||||
|
hash = 97 * hash + (int) (Double.doubleToLongBits(this.l) ^ (Double.doubleToLongBits(this.l) >>> 32));
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == null) return false;
|
||||||
|
if (getClass() != o.getClass()) return false;
|
||||||
|
Square s = (Square) o;
|
||||||
|
return Double.compare(l, s.l) == 0 && Double.compare(x, s.x) == 0 && Double.compare(y, s.y) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Graphics2D g2) {
|
||||||
|
Rectangle r = new Rectangle((int)x, (int)y, (int)l, (int)l);
|
||||||
|
|
||||||
|
g2.draw(r);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +1,14 @@
|
||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
||||||
*/
|
|
||||||
package shape;
|
package shape;
|
||||||
|
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author gicorada
|
* @author radaelli11353
|
||||||
*/
|
*/
|
||||||
public class Tester {
|
public class Tester extends JComponent{
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Shape c1 = new Circle(2, 3, 1);
|
Shape c1 = new Circle(2, 3, 1);
|
||||||
Shape c2 = new Circle(2, 3, 1);
|
Shape c2 = new Circle(2, 3, 1);
|
||||||
|
@ -21,5 +21,15 @@ public class Tester {
|
||||||
System.out.println(c2.posX() + ", " + c2.posY());
|
System.out.println(c2.posX() + ", " + c2.posY());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
|
||||||
|
Shape s1 = new Circle(88, 200, 50);
|
||||||
|
Shape s2 = new Square(200, 100, 100);
|
||||||
|
Shape s3 = new TriangoloRettangolo(200, 100, 100, 100);
|
||||||
|
|
||||||
|
s1.draw(g2);
|
||||||
|
s2.draw(g2);
|
||||||
|
s3.draw(g2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
package shape;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author radaelli11353
|
||||||
|
*/
|
||||||
|
public class TriangoloRettangolo extends Shape {
|
||||||
|
private double b;
|
||||||
|
private double h;
|
||||||
|
private double x;
|
||||||
|
private double y;
|
||||||
|
|
||||||
|
public TriangoloRettangolo(double b, double h, double x, double y) {
|
||||||
|
this.b = b;
|
||||||
|
this.h = h;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double width() {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double height() {
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double posX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double posY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 3;
|
||||||
|
hash = 53 * hash + (int) (Double.doubleToLongBits(this.b) ^ (Double.doubleToLongBits(this.b) >>> 32));
|
||||||
|
hash = 53 * hash + (int) (Double.doubleToLongBits(this.h) ^ (Double.doubleToLongBits(this.h) >>> 32));
|
||||||
|
hash = 53 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32));
|
||||||
|
hash = 53 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final TriangoloRettangolo other = (TriangoloRettangolo) obj;
|
||||||
|
if (Double.doubleToLongBits(this.b) != Double.doubleToLongBits(other.b)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Double.doubleToLongBits(this.h) != Double.doubleToLongBits(other.h)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Double.doubleToLongBits(this.y) == Double.doubleToLongBits(other.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Graphics2D g2) {
|
||||||
|
Line2D.Double altezza = new Line2D.Double(x, y, x, y+h);
|
||||||
|
Line2D.Double base = new Line2D.Double(x, y+h, x+b, y+h);
|
||||||
|
Line2D.Double ipotenusa = new Line2D.Double(x, y, x+b, y+h);
|
||||||
|
|
||||||
|
g2.draw(altezza);
|
||||||
|
g2.draw(base);
|
||||||
|
g2.draw(ipotenusa);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue