Merge branch 'master' of gitea.it:gicorada/java-scuola
This commit is contained in:
commit
6ad6edfb8d
1
.gitignore
vendored
1
.gitignore
vendored
@ -35,3 +35,4 @@ hs_err_pid*
|
|||||||
/NetBeans Projects/BankAccount/build/
|
/NetBeans Projects/BankAccount/build/
|
||||||
/NetBeans Projects/BankAccount/dist/
|
/NetBeans Projects/BankAccount/dist/
|
||||||
/NetBeans Projects/Inventory/build/
|
/NetBeans Projects/Inventory/build/
|
||||||
|
/NetBeans Projects/Grafica/nbproject/private/
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
<!-- the Compile on Save feature is turned off for the project. -->
|
<!-- the Compile on Save feature is turned off for the project. -->
|
||||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||||
<!-- in the project's Project Properties dialog box.-->
|
<!-- in the project's Project Properties dialog box.-->
|
||||||
<project name="shape" default="default" basedir=".">
|
<project name="Grafica" default="default" basedir=".">
|
||||||
<description>Builds, tests, and runs the project shape.</description>
|
<description>Builds, tests, and runs the project Grafica.</description>
|
||||||
<import file="nbproject/build-impl.xml"/>
|
<import file="nbproject/build-impl.xml"/>
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
@ -58,7 +58,7 @@
|
|||||||
|
|
||||||
An example of overriding the target for project execution could look like this:
|
An example of overriding the target for project execution could look like this:
|
||||||
|
|
||||||
<target name="run" depends="shape-impl.jar">
|
<target name="run" depends="Grafica-impl.jar">
|
||||||
<exec dir="bin" executable="launcher.exe">
|
<exec dir="bin" executable="launcher.exe">
|
||||||
<arg file="${dist.jar}"/>
|
<arg file="${dist.jar}"/>
|
||||||
</exec>
|
</exec>
|
3
NetBeans Projects/Grafica/manifest.mf
Normal file
3
NetBeans Projects/Grafica/manifest.mf
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
X-COMMENT: Main-Class will be added automatically by build
|
||||||
|
|
@ -19,7 +19,7 @@ is divided into following sections:
|
|||||||
- cleanup
|
- cleanup
|
||||||
|
|
||||||
-->
|
-->
|
||||||
<project xmlns:if="ant:if" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" xmlns:unless="ant:unless" basedir=".." default="default" name="shape-impl">
|
<project xmlns:if="ant:if" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" xmlns:unless="ant:unless" basedir=".." default="default" name="Grafica-impl">
|
||||||
<fail message="Please build using Ant 1.8.0 or higher.">
|
<fail message="Please build using Ant 1.8.0 or higher.">
|
||||||
<condition>
|
<condition>
|
||||||
<not>
|
<not>
|
||||||
@ -641,7 +641,7 @@ is divided into following sections:
|
|||||||
</fileset>
|
</fileset>
|
||||||
</union>
|
</union>
|
||||||
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
|
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
|
||||||
<testng classfilesetref="test.set" failureProperty="tests.failed" jvm="${platform.java}" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="shape" testname="TestNG tests" workingDir="${work.dir}">
|
<testng classfilesetref="test.set" failureProperty="tests.failed" jvm="${platform.java}" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="Grafica" testname="TestNG tests" workingDir="${work.dir}">
|
||||||
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
|
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
|
||||||
<propertyset>
|
<propertyset>
|
||||||
<propertyref prefix="test-sys-prop."/>
|
<propertyref prefix="test-sys-prop."/>
|
||||||
@ -738,7 +738,7 @@ is divided into following sections:
|
|||||||
<condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
|
<condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
|
||||||
<isset property="test.method"/>
|
<isset property="test.method"/>
|
||||||
</condition>
|
</condition>
|
||||||
<condition else="-suitename shape -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
|
<condition else="-suitename Grafica -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
|
||||||
<matches pattern=".*\.xml" string="@{testClass}"/>
|
<matches pattern=".*\.xml" string="@{testClass}"/>
|
||||||
</condition>
|
</condition>
|
||||||
<delete dir="${build.test.results.dir}" quiet="true"/>
|
<delete dir="${build.test.results.dir}" quiet="true"/>
|
||||||
@ -1082,7 +1082,7 @@ is divided into following sections:
|
|||||||
<delete file="${built-jar.properties}" quiet="true"/>
|
<delete file="${built-jar.properties}" quiet="true"/>
|
||||||
</target>
|
</target>
|
||||||
<target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
|
<target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
|
||||||
<echo level="warn" message="Cycle detected: shape was already built"/>
|
<echo level="warn" message="Cycle detected: Grafica was already built"/>
|
||||||
</target>
|
</target>
|
||||||
<target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
|
<target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
|
||||||
<mkdir dir="${build.dir}"/>
|
<mkdir dir="${build.dir}"/>
|
||||||
@ -1756,7 +1756,7 @@ is divided into following sections:
|
|||||||
<delete file="${built-clean.properties}" quiet="true"/>
|
<delete file="${built-clean.properties}" quiet="true"/>
|
||||||
</target>
|
</target>
|
||||||
<target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
|
<target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
|
||||||
<echo level="warn" message="Cycle detected: shape was already built"/>
|
<echo level="warn" message="Cycle detected: Grafica was already built"/>
|
||||||
</target>
|
</target>
|
||||||
<target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
|
<target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
|
||||||
<mkdir dir="${build.dir}"/>
|
<mkdir dir="${build.dir}"/>
|
@ -1,8 +1,8 @@
|
|||||||
build.xml.data.CRC32=184eed3a
|
build.xml.data.CRC32=acf20e45
|
||||||
build.xml.script.CRC32=04b06f70
|
build.xml.script.CRC32=761ebeaf
|
||||||
build.xml.stylesheet.CRC32=f85dc8f2@1.106.0.48
|
build.xml.stylesheet.CRC32=f85dc8f2@1.106.0.48
|
||||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||||
nbproject/build-impl.xml.data.CRC32=184eed3a
|
nbproject/build-impl.xml.data.CRC32=acf20e45
|
||||||
nbproject/build-impl.xml.script.CRC32=677ad60c
|
nbproject/build-impl.xml.script.CRC32=a1851d6a
|
||||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48
|
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48
|
@ -1,10 +1,9 @@
|
|||||||
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:
|
||||||
@ -29,11 +28,10 @@ debug.test.modulepath=\
|
|||||||
dist.archive.excludes=
|
dist.archive.excludes=
|
||||||
# This directory is removed when the project is cleaned:
|
# This directory is removed when the project is cleaned:
|
||||||
dist.dir=dist
|
dist.dir=dist
|
||||||
dist.jar=${dist.dir}/shape.jar
|
dist.jar=${dist.dir}/Grafica.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}/Grafica
|
||||||
endorsed.classpath=
|
|
||||||
excludes=
|
excludes=
|
||||||
includes=**
|
includes=**
|
||||||
jar.compress=false
|
jar.compress=false
|
||||||
@ -72,7 +70,7 @@ jlink.additionalmodules=
|
|||||||
# The jlink additional command line parameters
|
# The jlink additional command line parameters
|
||||||
jlink.additionalparam=
|
jlink.additionalparam=
|
||||||
jlink.launcher=true
|
jlink.launcher=true
|
||||||
jlink.launcher.name=shape
|
jlink.launcher.name=Grafica
|
||||||
main.class=shape.ShapesViewer
|
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
|
@ -3,7 +3,7 @@
|
|||||||
<type>org.netbeans.modules.java.j2seproject</type>
|
<type>org.netbeans.modules.java.j2seproject</type>
|
||||||
<configuration>
|
<configuration>
|
||||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||||
<name>shape</name>
|
<name>Grafica</name>
|
||||||
<explicit-platform explicit-source-supported="true"/>
|
<explicit-platform explicit-source-supported="true"/>
|
||||||
<source-roots>
|
<source-roots>
|
||||||
<root id="src.dir"/>
|
<root id="src.dir"/>
|
28
NetBeans Projects/Grafica/src/investment/BankAccount.java
Normal file
28
NetBeans Projects/Grafica/src/investment/BankAccount.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package investment;
|
||||||
|
|
||||||
|
public class BankAccount {
|
||||||
|
private double balance;
|
||||||
|
|
||||||
|
public BankAccount() {
|
||||||
|
balance = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BankAccount(double initialBalance) {
|
||||||
|
balance = initialBalance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deposit(double amount) {
|
||||||
|
double newBalance = balance + amount;
|
||||||
|
balance = newBalance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void withdraw(double amount) {
|
||||||
|
double newBalance = balance - amount;
|
||||||
|
balance = newBalance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBalance() {
|
||||||
|
return balance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
|||||||
|
package investment;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
public class InvestmentViewer1 {
|
||||||
|
private static final int FRAME_WIDTH = 120;
|
||||||
|
private static final int FRAME_HEIGHT = 60;
|
||||||
|
|
||||||
|
private static final double INTEREST_RATE = 10;
|
||||||
|
private static final double INITIAL_BALANCE = 1000;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
BankAccount account = new BankAccount(INITIAL_BALANCE);
|
||||||
|
|
||||||
|
JButton button = new JButton("Aggiungi interessi");
|
||||||
|
frame.add(button);
|
||||||
|
|
||||||
|
class InterestListener implements ActionListener {
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
double interest = account.getBalance() * INTEREST_RATE / 100;
|
||||||
|
account.deposit(interest);
|
||||||
|
System.out.println("saldo: " + account.getBalance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionListener listener = new InterestListener();
|
||||||
|
button.addActionListener(listener);
|
||||||
|
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
|||||||
|
package investment;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
public class InvestmentViewer2 {
|
||||||
|
private static final int FRAME_WIDTH = 400;
|
||||||
|
private static final int FRAME_HEIGHT = 100;
|
||||||
|
|
||||||
|
private static final double INTEREST_RATE = 10;
|
||||||
|
private static final double INITIAL_BALANCE = 1000;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
BankAccount account = new BankAccount(INITIAL_BALANCE);
|
||||||
|
|
||||||
|
JButton button = new JButton("Aggiungi interessi");
|
||||||
|
JLabel label = new JLabel("Saldo: " + account.getBalance());
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
|
||||||
|
panel.add(button);
|
||||||
|
panel.add(label);
|
||||||
|
frame.add(panel);
|
||||||
|
|
||||||
|
class InterestListener implements ActionListener {
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
double interest = account.getBalance() * INTEREST_RATE / 100;
|
||||||
|
account.deposit(interest);
|
||||||
|
label.setText("Saldo: " + account.getBalance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionListener listener = new InterestListener();
|
||||||
|
button.addActionListener(listener);
|
||||||
|
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -32,8 +32,6 @@ public class Circle extends Shape {
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = 5;
|
int hash = 5;
|
||||||
hash = 83 * hash + (int) (Double.doubleToLongBits(this.xc) ^ (Double.doubleToLongBits(this.xc) >>> 32));
|
|
||||||
hash = 83 * hash + (int) (Double.doubleToLongBits(this.yc) ^ (Double.doubleToLongBits(this.yc) >>> 32));
|
|
||||||
hash = 83 * hash + (int) (Double.doubleToLongBits(this.r) ^ (Double.doubleToLongBits(this.r) >>> 32));
|
hash = 83 * hash + (int) (Double.doubleToLongBits(this.r) ^ (Double.doubleToLongBits(this.r) >>> 32));
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
@ -43,7 +41,7 @@ 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) == 0 && Double.compare(yc, c.yc) == 0 && Double.compare(r, c.r) == 0;
|
return r == c.r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
47
NetBeans Projects/Grafica/src/shape/Geometria.java
Normal file
47
NetBeans Projects/Grafica/src/shape/Geometria.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package shape;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
|
||||||
|
public class Geometria {
|
||||||
|
private ArrayList<Shape> elementi;
|
||||||
|
|
||||||
|
public Geometria() {
|
||||||
|
elementi = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void riempiACaso(int size) {
|
||||||
|
Random r = new Random();
|
||||||
|
|
||||||
|
for(int i = 0; i < size; i++) {
|
||||||
|
int s = r.nextInt(3);
|
||||||
|
|
||||||
|
double x = r.nextDouble()*300;
|
||||||
|
double y = r.nextDouble()*300;
|
||||||
|
|
||||||
|
switch(s) {
|
||||||
|
case 0:
|
||||||
|
//circle
|
||||||
|
double raggio = r.nextDouble()*30;
|
||||||
|
elementi.add(new Circle(x, y, raggio));
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
//square
|
||||||
|
double lato = r.nextDouble()*40;
|
||||||
|
elementi.add(new Square(x, y, lato));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
//triangolo
|
||||||
|
double base = r.nextDouble()*30;
|
||||||
|
double altezza = r.nextDouble()*30;
|
||||||
|
elementi.add(new TriangoloRettangolo(x, y, base, altezza));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(Graphics2D g2) {
|
||||||
|
for(Shape s : elementi) s.draw(g2);
|
||||||
|
}
|
||||||
|
}
|
@ -8,13 +8,10 @@ import java.awt.Rectangle;
|
|||||||
* @author radaelli11353
|
* @author radaelli11353
|
||||||
*/
|
*/
|
||||||
public class Square extends Shape {
|
public class Square extends Shape {
|
||||||
private double x;
|
|
||||||
private double y;
|
|
||||||
private double l;
|
private double l;
|
||||||
|
|
||||||
public Square(double x, double y, double l) {
|
public Square(double x, double y, double l) {
|
||||||
this.x = x;
|
super(x, y);
|
||||||
this.y = y;
|
|
||||||
this.l = l;
|
this.l = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,22 +25,11 @@ public class Square extends Shape {
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double posX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double posY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = 7;
|
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));
|
hash = 97 * hash + (int) (Double.doubleToLongBits(this.l) ^ (Double.doubleToLongBits(this.l) >>> 32));
|
||||||
|
hash = 97 * hash + super.hashCode();
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +38,7 @@ public class Square extends Shape {
|
|||||||
if (o == null) return false;
|
if (o == null) return false;
|
||||||
if (getClass() != o.getClass()) return false;
|
if (getClass() != o.getClass()) return false;
|
||||||
Square s = (Square) o;
|
Square s = (Square) o;
|
||||||
return Double.compare(l, s.l) == 0 && Double.compare(x, s.x) == 0 && Double.compare(y, s.y) == 0;
|
return l == s.l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
21
NetBeans Projects/Grafica/src/shape/Tester.java
Normal file
21
NetBeans Projects/Grafica/src/shape/Tester.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package shape;
|
||||||
|
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author radaelli11353
|
||||||
|
*/
|
||||||
|
public class Tester extends JComponent{
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
|
||||||
|
Geometria geom = new Geometria();
|
||||||
|
|
||||||
|
geom.riempiACaso(10);
|
||||||
|
|
||||||
|
geom.draw(g2);
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ public class TriangoloRettangolo extends Shape {
|
|||||||
private double b;
|
private double b;
|
||||||
private double h;
|
private double h;
|
||||||
|
|
||||||
public TriangoloRettangolo(double b, double h, double x, double y) {
|
public TriangoloRettangolo(double x, double y, double b, double h) {
|
||||||
super(x, y);
|
super(x, y);
|
||||||
this.b = b;
|
this.b = b;
|
||||||
this.h = h;
|
this.h = h;
|
||||||
@ -32,33 +32,20 @@ public class TriangoloRettangolo extends Shape {
|
|||||||
int hash = 3;
|
int hash = 3;
|
||||||
hash = 53 * hash + (int) (Double.doubleToLongBits(this.b) ^ (Double.doubleToLongBits(this.b) >>> 32));
|
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.h) ^ (Double.doubleToLongBits(this.h) >>> 32));
|
||||||
hash = 53 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32));
|
hash = 53 * hash + super.hashCode();
|
||||||
hash = 53 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object o) {
|
||||||
if (this == obj) {
|
if (o == null || getClass() != o.getClass()) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
TriangoloRettangolo t = (TriangoloRettangolo) o;
|
||||||
|
if (Double.doubleToLongBits(b) != Double.doubleToLongBits(t.b)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final TriangoloRettangolo other = (TriangoloRettangolo) obj;
|
return Double.doubleToLongBits(h) != Double.doubleToLongBits(t.h);
|
||||||
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
|
@Override
|
@ -1,8 +0,0 @@
|
|||||||
compile.on.save=true
|
|
||||||
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
|
|
@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
|
||||||
<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">
|
|
||||||
<group>
|
|
||||||
<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>
|
|
||||||
</open-files>
|
|
||||||
</project-private>
|
|
@ -1,47 +0,0 @@
|
|||||||
package shape;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
|
|
||||||
public class Geometria {
|
|
||||||
private ArrayList<Shape> elementi;
|
|
||||||
|
|
||||||
public Geometria() {
|
|
||||||
elementi = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void riempiACaso(int size) {
|
|
||||||
Random r = new Random();
|
|
||||||
|
|
||||||
for(int i = 0; i < size; i++) {
|
|
||||||
int s = r.nextInt(3);
|
|
||||||
|
|
||||||
double x = r.nextDouble()*300;
|
|
||||||
double y = r.nextDouble()*300;
|
|
||||||
|
|
||||||
switch(s) {
|
|
||||||
case 0:
|
|
||||||
//circle
|
|
||||||
double raggio = r.nextDouble()*30;
|
|
||||||
elementi.add(new Circle(x, y, raggio));
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
//square
|
|
||||||
double lato = r.nextDouble()*40;
|
|
||||||
elementi.add(new Square(lato, x, y));
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
//triangolo
|
|
||||||
double base = r.nextDouble()*30;
|
|
||||||
double altezza = r.nextDouble()*30;
|
|
||||||
elementi.add(new TriangoloRettangolo(base, altezza, x, y));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw(Graphics2D g2) {
|
|
||||||
for(Shape s : elementi) s.draw(g2);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package shape;
|
|
||||||
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author radaelli11353
|
|
||||||
*/
|
|
||||||
public class Tester extends JComponent{
|
|
||||||
/*public static void main(String[] args) {
|
|
||||||
Shape c1 = new Circle(2, 3, 1);
|
|
||||||
Shape c2 = new Circle(2, 3, 1);
|
|
||||||
|
|
||||||
System.out.println(c1.posX() + ", " +c1.posY());
|
|
||||||
System.out.println(c1.width() + ", " +c1.height());
|
|
||||||
System.out.println(c1.equals(c2));
|
|
||||||
|
|
||||||
((Circle) c2).setRadius(2);
|
|
||||||
System.out.println(c2.posX() + ", " + c2.posY());
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public void paintComponent(Graphics g) {
|
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
|
||||||
|
|
||||||
Geometria geom = new Geometria();
|
|
||||||
|
|
||||||
geom.riempiACaso(10);
|
|
||||||
|
|
||||||
geom.draw(g2);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user