@@ -0,0 +1,53 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?><!-- You may freely edit this file. See commented blocks below for --><!-- some examples of how to customize the build. --><!-- (If you delete it and reopen the project it will be recreated.) --><!-- By default, only the Clean and Build commands use this build script. --><project name="MontecarloPi" default="default" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant"> | |||||
<description>Builds, tests, and runs the project MontecarloPi.</description> | |||||
<import file="nbproject/build-impl.xml"/> | |||||
<!-- | |||||
There exist several targets which are by default empty and which can be | |||||
used for execution of your tasks. These targets are usually executed | |||||
before and after some main targets. Those of them relevant for JavaFX project are: | |||||
-pre-init: called before initialization of project properties | |||||
-post-init: called after initialization of project properties | |||||
-pre-compile: called before javac compilation | |||||
-post-compile: called after javac compilation | |||||
-pre-compile-test: called before javac compilation of JUnit tests | |||||
-post-compile-test: called after javac compilation of JUnit tests | |||||
-pre-jfx-jar: called before FX SDK specific <fx:jar> task | |||||
-post-jfx-jar: called after FX SDK specific <fx:jar> task | |||||
-pre-jfx-deploy: called before FX SDK specific <fx:deploy> task | |||||
-post-jfx-deploy: called after FX SDK specific <fx:deploy> task | |||||
-pre-jfx-native: called just after -pre-jfx-deploy if <fx:deploy> runs in native packaging mode | |||||
-post-jfx-native: called just after -post-jfx-deploy if <fx:deploy> runs in native packaging mode | |||||
-post-clean: called after cleaning build products | |||||
(Targets beginning with '-' are not intended to be called on their own.) | |||||
Example of inserting a HTML postprocessor after javaFX SDK deployment: | |||||
<target name="-post-jfx-deploy"> | |||||
<basename property="jfx.deployment.base" file="${jfx.deployment.jar}" suffix=".jar"/> | |||||
<property name="jfx.deployment.html" location="${jfx.deployment.dir}${file.separator}${jfx.deployment.base}.html"/> | |||||
<custompostprocess> | |||||
<fileset dir="${jfx.deployment.html}"/> | |||||
</custompostprocess> | |||||
</target> | |||||
Example of calling an Ant task from JavaFX SDK. Note that access to JavaFX SDK Ant tasks must be | |||||
initialized; to ensure this is done add the dependence on -check-jfx-sdk-version target: | |||||
<target name="-post-jfx-jar" depends="-check-jfx-sdk-version"> | |||||
<echo message="Calling jar task from JavaFX SDK"/> | |||||
<fx:jar ...> | |||||
... | |||||
</fx:jar> | |||||
</target> | |||||
For more details about JavaFX SDK Ant tasks go to | |||||
http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm | |||||
For list of available properties check the files | |||||
nbproject/build-impl.xml and nbproject/jfx-impl.xml. | |||||
--> | |||||
</project> |
@@ -0,0 +1,4 @@ | |||||
#Tue, 28 May 2019 17:51:44 +0200 | |||||
D\:\\Tobias\\NetBeans\ Projects\\MonteCarloMethode= |
@@ -0,0 +1,45 @@ | |||||
<html><head> | |||||
<SCRIPT src="./web-files/dtjava.js"></SCRIPT> | |||||
<script> | |||||
function launchApplication(jnlpfile) { | |||||
dtjava.launch( { | |||||
url : 'MontecarloPi.jnlp', | |||||
jnlp_content : 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxqbmxwIHNwZWM9IjEuMCIgeG1sbnM6amZ4PSJodHRwOi8vamF2YWZ4LmNvbSIgaHJlZj0iTW9udGVjYXJsb1BpLmpubHAiPg0KICA8aW5mb3JtYXRpb24+DQogICAgPHRpdGxlPk1vbnRlY2FybG9QaTwvdGl0bGU+DQogICAgPHZlbmRvcj5FZHVhcmQ8L3ZlbmRvcj4NCiAgICA8ZGVzY3JpcHRpb24+bnVsbDwvZGVzY3JpcHRpb24+DQogICAgPG9mZmxpbmUtYWxsb3dlZC8+DQogIDwvaW5mb3JtYXRpb24+DQogIDxyZXNvdXJjZXM+DQogICAgPGoyc2UgdmVyc2lvbj0iMS42KyIgaHJlZj0iaHR0cDovL2phdmEuc3VuLmNvbS9wcm9kdWN0cy9hdXRvZGwvajJzZSIvPg0KICAgIDxqYXIgaHJlZj0iTW9udGVjYXJsb1BpLmphciIgc2l6ZT0iMTA0NDEiIGRvd25sb2FkPSJlYWdlciIgLz4NCiAgPC9yZXNvdXJjZXM+DQogIDxhcHBsZXQtZGVzYyAgd2lkdGg9IjgwMCIgaGVpZ2h0PSI2MDAiIG1haW4tY2xhc3M9ImNvbS5qYXZhZngubWFpbi5Ob0phdmFGWEZhbGxiYWNrIiAgbmFtZT0iTW9udGVjYXJsb1BpIiA+DQogICAgPHBhcmFtIG5hbWU9InJlcXVpcmVkRlhWZXJzaW9uIiB2YWx1ZT0iOC4wKyIvPg0KICA8L2FwcGxldC1kZXNjPg0KICA8amZ4OmphdmFmeC1kZXNjICB3aWR0aD0iODAwIiBoZWlnaHQ9IjYwMCIgbWFpbi1jbGFzcz0ibW9udGVjYXJsb3BpLk1vbnRlY2FybG9QaSIgIG5hbWU9Ik1vbnRlY2FybG9QaSIgLz4NCiAgPHVwZGF0ZSBjaGVjaz0iYWx3YXlzIi8+DQo8L2pubHA+DQo=' | |||||
}, | |||||
{ | |||||
javafx : '8.0+' | |||||
}, | |||||
{} | |||||
); | |||||
return false; | |||||
} | |||||
</script> | |||||
<script> | |||||
function javafxEmbedmontecarlopi() { | |||||
dtjava.embed( | |||||
{ | |||||
id : 'montecarlopi', | |||||
url : 'MontecarloPi.jnlp', | |||||
placeholder : 'javafx-app-placeholder', | |||||
width : '800', | |||||
height : '600', | |||||
jnlp_content : 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxqbmxwIHNwZWM9IjEuMCIgeG1sbnM6amZ4PSJodHRwOi8vamF2YWZ4LmNvbSIgaHJlZj0iTW9udGVjYXJsb1BpLmpubHAiPg0KICA8aW5mb3JtYXRpb24+DQogICAgPHRpdGxlPk1vbnRlY2FybG9QaTwvdGl0bGU+DQogICAgPHZlbmRvcj5FZHVhcmQ8L3ZlbmRvcj4NCiAgICA8ZGVzY3JpcHRpb24+bnVsbDwvZGVzY3JpcHRpb24+DQogICAgPG9mZmxpbmUtYWxsb3dlZC8+DQogIDwvaW5mb3JtYXRpb24+DQogIDxyZXNvdXJjZXM+DQogICAgPGoyc2UgdmVyc2lvbj0iMS42KyIgaHJlZj0iaHR0cDovL2phdmEuc3VuLmNvbS9wcm9kdWN0cy9hdXRvZGwvajJzZSIvPg0KICAgIDxqYXIgaHJlZj0iTW9udGVjYXJsb1BpLmphciIgc2l6ZT0iMTA0NDEiIGRvd25sb2FkPSJlYWdlciIgLz4NCiAgPC9yZXNvdXJjZXM+DQogIDxhcHBsZXQtZGVzYyAgd2lkdGg9IjgwMCIgaGVpZ2h0PSI2MDAiIG1haW4tY2xhc3M9ImNvbS5qYXZhZngubWFpbi5Ob0phdmFGWEZhbGxiYWNrIiAgbmFtZT0iTW9udGVjYXJsb1BpIiA+DQogICAgPHBhcmFtIG5hbWU9InJlcXVpcmVkRlhWZXJzaW9uIiB2YWx1ZT0iOC4wKyIvPg0KICA8L2FwcGxldC1kZXNjPg0KICA8amZ4OmphdmFmeC1kZXNjICB3aWR0aD0iODAwIiBoZWlnaHQ9IjYwMCIgbWFpbi1jbGFzcz0ibW9udGVjYXJsb3BpLk1vbnRlY2FybG9QaSIgIG5hbWU9Ik1vbnRlY2FybG9QaSIgLz4NCiAgPHVwZGF0ZSBjaGVjaz0iYWx3YXlzIi8+DQo8L2pubHA+DQo=' | |||||
}, | |||||
{ | |||||
javafx : '8.0+' | |||||
}, | |||||
{} | |||||
); | |||||
} | |||||
<!-- Embed FX application into web page once page is loaded --> | |||||
dtjava.addOnloadCallback(javafxEmbedmontecarlopi); | |||||
</script> | |||||
</head><body> | |||||
<h2>Test page for <b>MontecarloPi</b></h2> | |||||
<b>Webstart:</b> <a href='MontecarloPi.jnlp' onclick="return launchApplication('MontecarloPi.jnlp');">click to launch this app as webstart</a><br><hr><br> | |||||
<!-- Applet will be inserted here --> | |||||
<div id='javafx-app-placeholder'></div> | |||||
</body></html> |
@@ -0,0 +1,18 @@ | |||||
<?xml version="1.0" encoding="utf-8"?> | |||||
<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="MontecarloPi.jnlp"> | |||||
<information> | |||||
<title>MontecarloPi</title> | |||||
<vendor>Eduard</vendor> | |||||
<description>null</description> | |||||
<offline-allowed/> | |||||
</information> | |||||
<resources> | |||||
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/> | |||||
<jar href="MontecarloPi.jar" size="10441" download="eager" /> | |||||
</resources> | |||||
<applet-desc width="800" height="600" main-class="com.javafx.main.NoJavaFXFallback" name="MontecarloPi" > | |||||
<param name="requiredFXVersion" value="8.0+"/> | |||||
</applet-desc> | |||||
<jfx:javafx-desc width="800" height="600" main-class="montecarlopi.MontecarloPi" name="MontecarloPi" /> | |||||
<update check="always"/> | |||||
</jnlp> |
@@ -0,0 +1,3 @@ | |||||
Manifest-Version: 1.0 | |||||
X-COMMENT: Main-Class will be added automatically by build | |||||
@@ -0,0 +1,23 @@ | |||||
========================================= | |||||
Project MontecarloPi build script updated | |||||
========================================= | |||||
Project build script file jfx-impl.xml in nbproject sub-directory has not been recognized | |||||
as compliant with this version of NetBeans JavaFX support module. To ensure correct | |||||
and complete functionality within this NetBeans installation the script file has been | |||||
backed up to jfx-impl_backup_1.xml and then updated to the currently supported state. | |||||
FX Project build script auto-update may be triggered on project open either after | |||||
NetBeans installation update or by manual changes in jfx-impl.xml. Please note that | |||||
changing jfx-impl.xml manually is not recommended. Any build customization code should | |||||
be placed only in build.xml in project root directory. | |||||
Remark: The auto-update mechanism can be disabled by setting property | |||||
javafx.disable.autoupdate=true | |||||
Automatic opening of this notification when project files are updated can be disabled by setting property | |||||
javafx.disable.autoupdate.notification=true | |||||
(in build.properties, private.properties or project.properties). | |||||
Remark: Files nbproject/jfx-impl_backup*.xml and this file nbproject/UPDATED.TXT | |||||
are not used when building the project and can be freely deleted. | |||||
@@ -0,0 +1,2 @@ | |||||
# Do not modify this property in this configuration. It can be re-generated. | |||||
$label=Run as WebStart |
@@ -0,0 +1,2 @@ | |||||
# Do not modify this property in this configuration. It can be re-generated. | |||||
$label=Run in Browser |
@@ -0,0 +1,8 @@ | |||||
build.xml.data.CRC32=75203b77 | |||||
build.xml.script.CRC32=083846b2 | |||||
build.xml.stylesheet.CRC32=8064a381@1.80.1.48 | |||||
# 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. | |||||
nbproject/build-impl.xml.data.CRC32=75203b77 | |||||
nbproject/build-impl.xml.script.CRC32=cd4ebf93 | |||||
nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.90.1.48 |
@@ -0,0 +1,2 @@ | |||||
# Do not modify this property in this configuration. It can be re-generated. | |||||
javafx.run.as=webstart |
@@ -0,0 +1,2 @@ | |||||
# Do not modify this property in this configuration. It can be re-generated. | |||||
javafx.run.as=embedded |
@@ -0,0 +1,6 @@ | |||||
auxiliary.org-netbeans-modules-projectapi.issue214819_5f_fx_5f_enabled=true | |||||
# No need to modify this property unless customizing JavaFX Ant task infrastructure | |||||
endorsed.javafx.ant.classpath=. | |||||
javafx.run.inbrowser=<Default System Browser> | |||||
javafx.run.inbrowser.path=C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE | |||||
user.properties.file=C:\\Users\\Gamer\\AppData\\Roaming\\NetBeans\\8.2\\build.properties |
@@ -0,0 +1,13 @@ | |||||
<?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:/D:/Tobias/NetBeans%20Projects/MonteCarloMethode/src/montecarlopi/MontecarloPi.java</file> | |||||
<file>file:/D:/Tobias/NetBeans%20Projects/MonteCarloMethode/src/montecarlopi/Model.java</file> | |||||
<file>file:/D:/Tobias/NetBeans%20Projects/MonteCarloMethode/src/montecarlopi/View.java</file> | |||||
<file>file:/D:/Tobias/NetBeans%20Projects/MonteCarloMethode/src/montecarlopi/UpdateThread.java</file> | |||||
<file>file:/D:/Tobias/NetBeans%20Projects/MonteCarloMethode/src/montecarlopi/Controller.java</file> | |||||
</group> | |||||
</open-files> | |||||
</project-private> |
@@ -0,0 +1,6 @@ | |||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> | |||||
<properties> | |||||
<comment/> | |||||
<entry key="ACTIVATED_FEATURES">#org.netbeans.modules.profiler.v2.features.ThreadsFeature@</entry> | |||||
</properties> |
@@ -0,0 +1,125 @@ | |||||
annotation.processing.enabled=true | |||||
annotation.processing.enabled.in.editor=false | |||||
annotation.processing.processor.options= | |||||
annotation.processing.processors.list= | |||||
annotation.processing.run.all.processors=true | |||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output | |||||
application.title=MontecarloPi | |||||
application.vendor=Eduard | |||||
build.classes.dir=${build.dir}/classes | |||||
build.classes.excludes=**/*.java,**/*.form | |||||
# This directory is removed when the project is cleaned: | |||||
build.dir=build | |||||
build.generated.dir=${build.dir}/generated | |||||
build.generated.sources.dir=${build.dir}/generated-sources | |||||
# Only compile against the classpath explicitly listed here: | |||||
build.sysclasspath=ignore | |||||
build.test.classes.dir=${build.dir}/test/classes | |||||
build.test.results.dir=${build.dir}/test/results | |||||
compile.on.save=true | |||||
compile.on.save.unsupported.javafx=true | |||||
# Uncomment to specify the preferred debugger connection transport: | |||||
#debug.transport=dt_socket | |||||
debug.classpath=\ | |||||
${run.classpath} | |||||
debug.modulepath=\ | |||||
${run.modulepath} | |||||
debug.test.classpath=\ | |||||
${run.test.classpath} | |||||
debug.test.modulepath=\ | |||||
${run.test.modulepath} | |||||
# This directory is removed when the project is cleaned: | |||||
dist.dir=dist | |||||
dist.jar=${dist.dir}/MontecarloPi.jar | |||||
dist.javadoc.dir=${dist.dir}/javadoc | |||||
endorsed.classpath= | |||||
excludes= | |||||
includes=** | |||||
# Non-JavaFX jar file creation is deactivated in JavaFX 2.0+ projects | |||||
jar.archive.disabled=true | |||||
jar.compress=false | |||||
javac.classpath=\ | |||||
${javafx.classpath.extension} | |||||
# Space-separated list of extra javac options | |||||
javac.compilerargs= | |||||
javac.deprecation=false | |||||
javac.modulepath= | |||||
javac.processormodulepath= | |||||
javac.processorpath=\ | |||||
${javac.classpath} | |||||
javac.source=1.8 | |||||
javac.target=1.8 | |||||
javac.test.classpath=\ | |||||
${javac.classpath}:\ | |||||
${build.classes.dir} | |||||
javac.test.modulepath=\ | |||||
${javac.modulepath} | |||||
javac.test.processorpath=\ | |||||
${javac.test.classpath} | |||||
javadoc.additionalparam= | |||||
javadoc.author=false | |||||
javadoc.encoding=${source.encoding} | |||||
javadoc.noindex=false | |||||
javadoc.nonavbar=false | |||||
javadoc.notree=false | |||||
javadoc.private=false | |||||
javadoc.splitindex=true | |||||
javadoc.use=true | |||||
javadoc.version=false | |||||
javadoc.windowtitle= | |||||
javafx.application.implementation.version=1.0 | |||||
javafx.binarycss=false | |||||
javafx.classpath.extension=\ | |||||
${java.home}/lib/javaws.jar:\ | |||||
${java.home}/lib/deploy.jar:\ | |||||
${java.home}/lib/plugin.jar | |||||
javafx.deploy.allowoffline=true | |||||
# If true, application update mode is set to 'background', if false, update mode is set to 'eager' | |||||
javafx.deploy.backgroundupdate=false | |||||
javafx.deploy.embedJNLP=true | |||||
javafx.deploy.includeDT=true | |||||
# Set true to prevent creation of temporary copy of deployment artifacts before each run (disables concurrent runs) | |||||
javafx.disable.concurrent.runs=false | |||||
# Set true to enable multiple concurrent runs of the same WebStart or Run-in-Browser project | |||||
javafx.enable.concurrent.external.runs=false | |||||
# This is a JavaFX project | |||||
javafx.enabled=true | |||||
javafx.fallback.class=com.javafx.main.NoJavaFXFallback | |||||
# Main class for JavaFX | |||||
javafx.main.class=montecarlopi.MontecarloPi | |||||
javafx.preloader.class= | |||||
# This project does not use Preloader | |||||
javafx.preloader.enabled=false | |||||
javafx.preloader.jar.filename= | |||||
javafx.preloader.jar.path= | |||||
javafx.preloader.project.path= | |||||
javafx.preloader.type=none | |||||
# Set true for GlassFish only. Rebases manifest classpaths of JARs in lib dir. Not usable with signed JARs. | |||||
javafx.rebase.libs=false | |||||
javafx.run.height=600 | |||||
javafx.run.width=800 | |||||
# Pre-JavaFX 2.0 WebStart is deactivated in JavaFX 2.0+ projects | |||||
jnlp.enabled=false | |||||
# Main class for Java launcher | |||||
main.class=com.javafx.main.Main | |||||
# For improved security specify narrower Codebase manifest attribute to prevent RIAs from being repurposed | |||||
manifest.custom.codebase=* | |||||
# Specify Permissions manifest attribute to override default (choices: sandbox, all-permissions) | |||||
manifest.custom.permissions= | |||||
manifest.file=manifest.mf | |||||
meta.inf.dir=${src.dir}/META-INF | |||||
platform.active=default_platform | |||||
run.classpath=\ | |||||
${dist.jar}:\ | |||||
${javac.classpath}:\ | |||||
${build.classes.dir} | |||||
run.modulepath=\ | |||||
${javac.modulepath} | |||||
run.test.classpath=\ | |||||
${javac.test.classpath}:\ | |||||
${build.test.classes.dir} | |||||
run.test.modulepath=\ | |||||
${javac.test.modulepath} | |||||
source.encoding=UTF-8 | |||||
src.dir=src | |||||
test.src.dir=test |
@@ -0,0 +1,25 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<project xmlns="http://www.netbeans.org/ns/project/1"> | |||||
<type>org.netbeans.modules.java.j2seproject</type> | |||||
<configuration> | |||||
<buildExtensions xmlns="http://www.netbeans.org/ns/ant-build-extender/1"> | |||||
<extension file="jfx-impl.xml" id="jfx3"> | |||||
<dependency dependsOn="-jfx-copylibs" target="-post-jar"/> | |||||
<dependency dependsOn="-rebase-libs" target="-post-jar"/> | |||||
<dependency dependsOn="jfx-deployment" target="-post-jar"/> | |||||
<dependency dependsOn="jar" target="debug"/> | |||||
<dependency dependsOn="jar" target="profile"/> | |||||
<dependency dependsOn="jar" target="run"/> | |||||
</extension> | |||||
</buildExtensions> | |||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3"> | |||||
<name>MontecarloPi</name> | |||||
<source-roots> | |||||
<root id="src.dir"/> | |||||
</source-roots> | |||||
<test-roots> | |||||
<root id="test.src.dir"/> | |||||
</test-roots> | |||||
</data> | |||||
</configuration> | |||||
</project> |
@@ -0,0 +1,37 @@ | |||||
package montecarlopi; | |||||
public class Circle { | |||||
private double diameter; | |||||
public Circle(double diameter) { | |||||
this.diameter = diameter; | |||||
} | |||||
public double getRadius() { | |||||
return diameter/2; | |||||
} | |||||
public double getDurchmesser() { | |||||
return diameter; | |||||
} | |||||
public boolean isInside(Point p) { | |||||
double x = p.getX(); | |||||
double y = p.getY(); | |||||
double a = ((float)diameter/2f)-(float)x; | |||||
double b = ((float)diameter/2f)-(float)y; | |||||
double c = (Math.sqrt(Math.pow(a, 2f) + (Math.pow(b, 2f)))); | |||||
if(((double)diameter/2f) >= c) { | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
} |
@@ -0,0 +1,35 @@ | |||||
package montecarlopi; | |||||
public class Controller { | |||||
private Model m = null; | |||||
private View v = null; | |||||
public Controller() { | |||||
m = new Model(); | |||||
v = new View(this); | |||||
m.addObserver(v); | |||||
} | |||||
public Model getModel() { | |||||
return m; | |||||
} | |||||
public View getView() { | |||||
return v; | |||||
} | |||||
public void addOne() { | |||||
m.setExit(false); | |||||
m.generatePoint(); | |||||
} | |||||
public void addThousand() { | |||||
m.setExit(false); | |||||
for(int i = 0; i < 1000; i++) { | |||||
m.generatePoint(); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,165 @@ | |||||
package montecarlopi; | |||||
import java.util.LinkedList; | |||||
import java.util.Observable; | |||||
import javafx.scene.canvas.Canvas; | |||||
import javafx.scene.canvas.GraphicsContext; | |||||
import javafx.scene.control.ListView; | |||||
import javafx.scene.layout.Pane; | |||||
import javafx.scene.paint.Color; | |||||
public class Model extends Observable{ | |||||
private Circle c; | |||||
private LinkedList<Point> list; | |||||
private Pane pane; | |||||
private Canvas can; | |||||
private int in, out, tries; | |||||
private UpdateThread uT; | |||||
private int count = 0; | |||||
private boolean exit; | |||||
public boolean isExit(){ | |||||
return exit; | |||||
} | |||||
public Model() { | |||||
int size = 400; | |||||
c = new Circle(size); | |||||
list = new LinkedList<>(); | |||||
pane = new Pane(); | |||||
pane.setPrefSize(size, size); | |||||
initPane(); | |||||
in = 0; | |||||
out = 0; | |||||
tries = 0; | |||||
} | |||||
public Pane getPane() { | |||||
return pane; | |||||
} | |||||
public int getIn() { | |||||
return in; | |||||
} | |||||
public int getOut() { | |||||
return out; | |||||
} | |||||
public int getTries() { | |||||
return tries; | |||||
} | |||||
private void initPane() { | |||||
initCanvas(); | |||||
pane.getChildren().add(can); | |||||
} | |||||
private void initCanvas() { | |||||
can = new Canvas(pane.getPrefHeight(),pane.getPrefWidth()); | |||||
GraphicsContext gc = can.getGraphicsContext2D(); | |||||
gc.clearRect(0, 0, can.getWidth(), can.getHeight()); | |||||
gc.fill(); | |||||
gc.setStroke(Color.BLACK); | |||||
gc.setLineWidth(1); | |||||
gc.strokeOval(0, 0, this.c.getDurchmesser() ,this.c.getDurchmesser()); | |||||
gc.strokeRect(0, 0, this.c.getDurchmesser() ,this.c.getDurchmesser()); | |||||
} | |||||
public Point generatePoint() { | |||||
if(exit)return null; | |||||
double x = (Math.random() * c.getDurchmesser()); | |||||
double y = (Math.random() * c.getDurchmesser()); | |||||
Point p = new Point(x,y); | |||||
addPoint(p); | |||||
return p; | |||||
} | |||||
public void reset(ListView<String> list1) { | |||||
list = new LinkedList<>(); | |||||
tries = 0; | |||||
in = 0; | |||||
out = 0; | |||||
GraphicsContext gc = can.getGraphicsContext2D(); | |||||
gc.clearRect(0, 0, can.getWidth(), can.getHeight()); | |||||
gc.setStroke(Color.BLACK); | |||||
gc.setLineWidth(1); | |||||
gc.strokeOval(0, 0, c.getDurchmesser(), c.getDurchmesser()); | |||||
gc.strokeRect(0, 0, c.getDurchmesser(), c.getDurchmesser()); | |||||
setExit(true); | |||||
list1.getItems().clear(); | |||||
setChanged(); | |||||
notifyObservers(); | |||||
} | |||||
public void addPoint(Point p) { | |||||
list.add(p); | |||||
boolean in = inOrout(p); | |||||
tries++; | |||||
GraphicsContext gc = can.getGraphicsContext2D(); | |||||
if(in){ | |||||
gc.setStroke(Color.VIOLET); //inside | |||||
}else{ | |||||
gc.setStroke(Color.BLUE); //outside | |||||
} | |||||
gc.setLineWidth(1); | |||||
gc.strokeRect((double)p.getX(),(double)p.getY(), 1, 1); | |||||
setChanged(); | |||||
notifyObservers(); | |||||
} | |||||
public void generateAuto (ListView<String> list,int count){ | |||||
setExit(false); | |||||
UpdateThread ut = new UpdateThread(this, list, count); | |||||
count++; | |||||
ut.start(); | |||||
} | |||||
private boolean inOrout(Point p) { | |||||
if(c.isInside(p)) { | |||||
in++; | |||||
return true; | |||||
}else{ | |||||
out++; | |||||
} | |||||
return false; | |||||
} | |||||
public double getPi() { | |||||
if(out != 0) { | |||||
return ((double)in / ((double)out+(double)in)) * 4; | |||||
} | |||||
return 0; | |||||
} | |||||
void stop(ListView<String> list) { | |||||
list.getItems().clear(); | |||||
exit=true; | |||||
} | |||||
public void setExit(boolean exit) { | |||||
this.exit=exit; | |||||
} | |||||
} |
@@ -0,0 +1,25 @@ | |||||
package montecarlopi; | |||||
import javafx.application.Application; | |||||
import javafx.scene.Scene; | |||||
import javafx.scene.layout.Pane; | |||||
import javafx.stage.Stage; | |||||
public class MontecarloPi extends Application { | |||||
@Override | |||||
public void start(Stage primaryStage) { | |||||
Controller c = new Controller(); | |||||
Pane p = c.getView().getPane(); | |||||
Scene scene = new Scene(p, 680, 400); | |||||
primaryStage.setTitle("Calculation of Pi"); | |||||
primaryStage.setScene(scene); | |||||
primaryStage.setResizable(false); | |||||
primaryStage.show(); | |||||
} | |||||
public static void main(String[] args) { | |||||
launch(args); | |||||
} | |||||
} |
@@ -0,0 +1,24 @@ | |||||
package montecarlopi; | |||||
public class Point { | |||||
private double x,y; | |||||
public Point(double x, double y) { | |||||
this.x = x; | |||||
this.y = y; | |||||
} | |||||
public double getX() { | |||||
return x; | |||||
} | |||||
public double getY() { | |||||
return y; | |||||
} | |||||
@Override | |||||
public String toString() { | |||||
return "("+x+"\\"+y+")"; | |||||
} | |||||
} |
@@ -0,0 +1,52 @@ | |||||
package montecarlopi; | |||||
import java.util.concurrent.TimeUnit; | |||||
import java.util.logging.Level; | |||||
import java.util.logging.Logger; | |||||
import javafx.application.Platform; | |||||
import javafx.scene.control.ListView; | |||||
/** | |||||
* | |||||
* @author tobia | |||||
*/ | |||||
public class UpdateThread extends Thread { | |||||
private int i = 0; | |||||
private Model test; | |||||
public UpdateThread(Model test, ListView<String> list, int count) { | |||||
setDaemon(true); | |||||
setName("Thread " + count); | |||||
this.test = test; | |||||
list.getItems().add(getName()); | |||||
} | |||||
@Override | |||||
public void run() { | |||||
while (!this.isInterrupted()) { | |||||
if (test.isExit()) { | |||||
return; | |||||
} | |||||
Platform.runLater(new Runnable() { | |||||
@Override | |||||
public void run() { | |||||
test.generatePoint(); | |||||
} | |||||
}); | |||||
try { | |||||
sleep(TimeUnit.MILLISECONDS.toMillis(5)); | |||||
} catch (InterruptedException ex) { | |||||
Logger.getLogger(UpdateThread.class.getName()).log(Level.SEVERE, null, ex); | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,125 @@ | |||||
package montecarlopi; | |||||
import java.util.Observable; | |||||
import java.util.Observer; | |||||
import javafx.scene.control.Button; | |||||
import javafx.scene.control.Label; | |||||
import javafx.scene.control.ListView; | |||||
import javafx.scene.layout.BorderPane; | |||||
import javafx.scene.layout.*; | |||||
import javafx.scene.text.Text; | |||||
public class View implements Observer { | |||||
private Controller c; | |||||
private BorderPane masterPane; | |||||
private Label currPi, in, out, tries, exactPi = null; | |||||
private int count = 0; | |||||
private ListView<String> list; | |||||
public View(Controller c) { | |||||
this.c = c; | |||||
initPane(); | |||||
} | |||||
public Controller getController() { | |||||
return c; | |||||
} | |||||
public BorderPane getPane() { | |||||
return masterPane; | |||||
} | |||||
private void initPane() { | |||||
masterPane = new BorderPane(); | |||||
currPi = new Label(); | |||||
in = new Label(); | |||||
out = new Label(); | |||||
tries = new Label(); | |||||
exactPi = new Label(); | |||||
currPi.setText("Approximation for Pi: 0"); | |||||
in.setText("Inside: 0"); | |||||
out.setText("Outside: 0"); | |||||
tries.setText("Attempt: 0"); | |||||
exactPi.setText("Exact value: 3.1415926"); | |||||
GridPane rightSide = new GridPane(); | |||||
rightSide.add(tries, 0, 0); | |||||
rightSide.add(in, 0, 1); | |||||
rightSide.add(out, 0, 2); | |||||
rightSide.add(exactPi, 0, 3); | |||||
rightSide.add(currPi, 0, 4); | |||||
GridPane buttons = new GridPane(); | |||||
Button add1000, reset, auto, stop; | |||||
GridPane ThreadList = new GridPane(); | |||||
Text text = new Text("running Threads"); | |||||
list = new ListView<>(); | |||||
list.setPrefSize(100, 100); | |||||
VBox box = new VBox(); | |||||
box.getChildren().add(list); | |||||
ThreadList.add(box, 0, 1); | |||||
ThreadList.add(text, 0, 0); | |||||
add1000 = new Button(); | |||||
reset = new Button(); | |||||
auto = new Button(); | |||||
stop = new Button(); | |||||
add1000.setText("+ 1000"); | |||||
stop.setText("stop Threads"); | |||||
reset.setText("Reset"); | |||||
auto.setText("generate Auto (Thread)"); | |||||
buttons.add(add1000, 1, 0); | |||||
buttons.add(reset, 3, 0); | |||||
buttons.add(auto, 4, 0); | |||||
buttons.add(stop, 1, 1); | |||||
rightSide.setVgap(5); | |||||
rightSide.setHgap(5); | |||||
rightSide.add(buttons, 0, 5); | |||||
rightSide.add(ThreadList, 0, 6); | |||||
masterPane.setRight(rightSide); | |||||
masterPane.setCenter(c.getModel().getPane()); | |||||
add1000.setOnAction(listener -> { | |||||
c.addThousand(); | |||||
}); | |||||
reset.setOnAction(listener -> { | |||||
c.getModel().reset(list); | |||||
}); | |||||
auto.setOnAction(listener -> { | |||||
c.getModel().generateAuto(list, count); | |||||
count++; | |||||
}); | |||||
stop.setOnAction(listener -> { | |||||
c.getModel().stop(list); | |||||
count=0; | |||||
}); | |||||
} | |||||
; | |||||
@Override | |||||
public void update(Observable o, Object arg) { | |||||
currPi.setText("Approximation for Pi: " + c.getModel().getPi()); | |||||
in.setText("Inside: " + c.getModel().getIn()); | |||||
out.setText("Outside: " + c.getModel().getOut()); | |||||
tries.setText("Attempt: " + c.getModel().getTries()); | |||||
} | |||||
} |