Add screensaver files

This commit is contained in:
Sem van der Hoeven
2025-09-02 20:34:20 +02:00
parent 3dd1b85b54
commit e347ea492f
67 changed files with 4048 additions and 26 deletions

29
.gitignore vendored
View File

@@ -1,26 +1,3 @@
# ---> Java
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
/build
/dist
/nbproject/private

1
.idea/.name generated Normal file
View File

@@ -0,0 +1 @@
E:\Avans\OGP1\TMCProjects\2017_avans_ti_breda-2D_Graphics-2019\week3-005.Screensaver

View File

@@ -0,0 +1,15 @@
<component name="ArtifactManager">
<artifact type="jar" name="week3-005.Screensaver:jar">
<output-path>$PROJECT_DIR$/out/artifacts/week3_005_Screensaver_jar</output-path>
<root id="archive" name="week3-005.Screensaver.jar">
<element id="module-output" name="week3-005.Screensaver" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/testrunner/tmc-junit-runner.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/testfx-junit-4.0.13-alpha.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/edu-test-utils-0.4.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/hamcrest-core-1.3.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/fxgraphics2d-1.9.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/junit-4.11.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/testfx-core-4.0.13-alpha.jar" path-in-jar="/" />
</root>
</artifact>
</component>

4
.idea/encodings.xml generated Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>

14
.idea/libraries/lib.xml generated Normal file
View File

@@ -0,0 +1,14 @@
<component name="libraryTable">
<library name="lib">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/testfx-junit-4.0.13-alpha.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/edu-test-utils-0.4.2.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/fxgraphics2d-1.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/testfx-core-4.0.13-alpha.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

9
.idea/libraries/tmc_junit_runner.xml generated Normal file
View File

@@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="tmc-junit-runner">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/testrunner/tmc-junit-runner.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

6
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/week3-005.Screensaver.iml" filepath="$PROJECT_DIR$/week3-005.Screensaver.iml" />
</modules>
</component>
</project>

View File

@@ -0,0 +1,9 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="week3-005.Screensaver" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="Screensaver" />
<module name="week3-005.Screensaver" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

124
.idea/uiDesigner.xml generated Normal file
View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

143
.idea/workspace.xml generated Normal file
View File

@@ -0,0 +1,143 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ArtifactsWorkspaceSettings">
<artifacts-to-build>
<artifact name="week3-005.Screensaver:jar" />
</artifacts-to-build>
</component>
<component name="ChangeListManager">
<list default="true" id="5980d439-1133-41be-81ba-ae0ee7321501" name="Default Changelist" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-8" />
<option name="y" value="-8" />
<option name="width" value="1936" />
<option name="height" value="1066" />
</component>
<component name="ProjectId" id="1YuM8OCsKEf3pJSUDRHvKRJbGIf" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1582477810978" />
<property name="project.structure.last.edited" value="SDKs" />
<property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.2" />
</component>
<component name="RunManager" selected="Application.AudioCapture02">
<configuration name="AudioCapture02" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="sound.AudioCapture02" />
<module name="week3-005.Screensaver" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="sound.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Capture" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="sound.Capture" />
<module name="week3-005.Screensaver" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="JavaSoundRecorder" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="sound.JavaSoundRecorder" />
<module name="week3-005.Screensaver" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TestSoundRecordingUtil" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="sound.TestSoundRecordingUtil" />
<module name="week3-005.Screensaver" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.AudioCapture02" />
<item itemvalue="Application.TestSoundRecordingUtil" />
<item itemvalue="Application.JavaSoundRecorder" />
<item itemvalue="Application.Capture" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="5980d439-1133-41be-81ba-ae0ee7321501" name="Default Changelist" comment="" />
<created>1582272091452</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1582272091452</updated>
<workItem from="1583787895066" duration="5847000" />
<workItem from="1584719178796" duration="23000" />
<workItem from="1584719243058" duration="389000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state x="698" y="328" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1583795135908">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state x="698" y="328" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1050/1920.-286.768.1336@0.0.1920.1050" timestamp="1583795135908" />
<state x="690" y="308" key="#com.intellij.ide.util.TreeClassChooserDialog" timestamp="1583788239635">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state x="690" y="308" key="#com.intellij.ide.util.TreeClassChooserDialog/0.0.1920.1050/1920.-286.768.1336@0.0.1920.1050" timestamp="1583788239635" />
<state x="740" y="279" key="FileChooserDialogImpl" timestamp="1583791310907">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state x="740" y="279" key="FileChooserDialogImpl/0.0.1920.1050/1920.-286.768.1336@0.0.1920.1050" timestamp="1583791310907" />
<state width="1877" height="279" key="GridCell.Tab.0.bottom" timestamp="1583796314812">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1877" height="279" key="GridCell.Tab.0.bottom/0.0.1920.1050/1920.-286.768.1336@0.0.1920.1050" timestamp="1583796314812" />
<state width="1877" height="279" key="GridCell.Tab.0.center" timestamp="1583796314812">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1877" height="279" key="GridCell.Tab.0.center/0.0.1920.1050/1920.-286.768.1336@0.0.1920.1050" timestamp="1583796314812" />
<state width="1877" height="279" key="GridCell.Tab.0.left" timestamp="1583796314812">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1877" height="279" key="GridCell.Tab.0.left/0.0.1920.1050/1920.-286.768.1336@0.0.1920.1050" timestamp="1583796314812" />
<state width="1877" height="279" key="GridCell.Tab.0.right" timestamp="1583796314812">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1877" height="279" key="GridCell.Tab.0.right/0.0.1920.1050/1920.-286.768.1336@0.0.1920.1050" timestamp="1583796314812" />
<state x="440" y="99" key="SettingsEditor" timestamp="1583791312853">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state x="440" y="99" key="SettingsEditor/0.0.1920.1050/1920.-286.768.1336@0.0.1920.1050" timestamp="1583791312853" />
<state x="342" y="145" key="new project wizard" timestamp="1584719630901">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state x="342" y="145" key="new project wizard/0.0.1920.1050/1920.-286.768.1336@0.0.1920.1050" timestamp="1584719630901" />
</component>
</project>

74
build.xml Normal file
View File

@@ -0,0 +1,74 @@
<?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. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="001.Moon" default="default" basedir=".">
<description>Builds, tests, and runs the project 001.Moon.</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. They 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-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar-with-manifest: JAR building (if you are using a manifest)
-do-jar-without-manifest: JAR building (if you are not using a manifest)
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="001.Moon-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

Binary file not shown.

BIN
lib/fxgraphics2d-1.9.jar Normal file

Binary file not shown.

BIN
lib/hamcrest-core-1.3.jar Normal file

Binary file not shown.

BIN
lib/junit-4.11.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
manifest.mf Normal file
View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

1420
nbproject/build-impl.xml Normal file

File diff suppressed because it is too large Load Diff

1042
nbproject/build-impl.xml~ Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
build.xml.data.CRC32=c2a9ffde
build.xml.script.CRC32=8bda9acc
build.xml.stylesheet.CRC32=28e38971@1.44.1.45
# 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=aa12f475
nbproject/build-impl.xml.script.CRC32=0e6a05f2
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

View File

@@ -0,0 +1,98 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=005.Screensaver
application.vendor=
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
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
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/005.Screensaver.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.fxgraphics2d-1.9.jar-1=lib/fxgraphics2d-1.9.jar
file.reference.testfx-core-4.0.13-alpha.jar=lib/testfx-core-4.0.13-alpha.jar
file.reference.testfx-junit-4.0.13-alpha.jar=lib/testfx-junit-4.0.13-alpha.jar
file.reference.fxgraphics2d-1.9.jar=lib/fxgraphics2d-1.5.jar
file.reference.edu-test-utils-0.4.2.jar=lib/edu-test-utils-0.4.2.jar
file.reference.junit-4.11.jar=lib/junit-4.11.jar
file.reference.hamcrest-core-1.3.jar=lib/hamcrest-core-1.3.jar
includes=**
jar.archive.disabled=${jnlp.enabled}
jar.compress=false
jar.index=${jnlp.enabled}
javac.classpath=\
${file.reference.fxgraphics2d-1.9.jar-1}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=false
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${file.reference.hamcrest-core-1.3.jar}:\
${file.reference.junit-4.11.jar}:\
${file.reference.edu-test-utils-0.4.2.jar}:\
${file.reference.fxgraphics2d-1.9.jar-1}
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=
jnlp.codebase.type=no.codebase
jnlp.descriptor=application
jnlp.enabled=false
jnlp.mixed.code=default
jnlp.offline-allowed=false
jnlp.signed=false
jnlp.signing=
jnlp.signing.alias=
jnlp.signing.keystore=
main.class=Screensaver
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

15
nbproject/project.xml Normal file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>005.Screensaver</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>gui</headerType>
<jar>F:\User Files\Sem\Documents\Projects\Java\java2d-screensaver\out\artifacts\week3_005_Screensaver_jar\week3-005.Screensaver.jar</jar>
<outfile>F:\User Files\Sem\Documents\Projects\Java\java2d-screensaver\out\artifacts\week3_005_Screensaver_jar\screensaver.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>true</stayAlive>
<restartOnCrash>false</restartOnCrash>
<manifest></manifest>
<icon>F:\User Files\Sem\Documents\Projects\Java\java2d-screensaver\out\artifacts\week3_005_Screensaver_jar\icon.ico</icon>
<jre>
<path></path>
<bundledJre64Bit>false</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.8.0</minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
<versionInfo>
<fileVersion>1.0.2.0</fileVersion>
<txtFileVersion>1.0.2.0</txtFileVersion>
<fileDescription>A screensaver in java2d</fileDescription>
<copyright>2020 Sem van der Hoeven</copyright>
<productVersion>1.0.2.0</productVersion>
<txtProductVersion>1.0.2.0</txtProductVersion>
<productName>Screensaver</productName>
<companyName></companyName>
<internalName>screensaver</internalName>
<originalFilename>screensaver.exe</originalFilename>
<trademarks></trademarks>
<language>DUTCH</language>
</versionInfo>
</launch4jConfig>

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Screensaver

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

Binary file not shown.

0
src/.gitkeep Normal file
View File

3
src/META-INF/MANIFEST.MF Normal file
View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Screensaver

61
src/MovingLine.java Normal file
View File

@@ -0,0 +1,61 @@
import org.jfree.fx.FXGraphics2D;
import java.awt.*;
import java.awt.geom.Line2D;
public class MovingLine {
private MovingPoint beginPoint;
private MovingPoint endPoint;
private Color color;
private int counter = 0;
private int MAX_LINES = 30;
private Line2D.Double[] trailingLines;
public MovingLine(MovingPoint beginPoint, MovingPoint endPoint, Color color) {
this.beginPoint = beginPoint;
this.endPoint = endPoint;
this.color = color;
trailingLines = new Line2D.Double[MAX_LINES];
}
public void draw(FXGraphics2D graphics) {
graphics.setColor(color);
graphics.draw(getAsLine());
for (int i = trailingLines.length-1; i >= 0; i--) {
if (trailingLines[i] != null)
graphics.draw(trailingLines[i]);
}
}
public void update() {
this.beginPoint.update();
this.endPoint.update();
counter++;
if (counter == MAX_LINES) {
counter = 0;
}
for (int i = trailingLines.length-1; i > 0; i--) {
trailingLines[i] = trailingLines[i-1];
}
trailingLines[0] = getAsLine();
}
public void setMovingBounds(double canvasWidth, double canvasHeight) {
this.beginPoint.setMovingBounds(canvasWidth, canvasHeight);
this.endPoint.setMovingBounds(canvasWidth, canvasHeight);
}
public Line2D.Double getAsLine() {
return new Line2D.Double(beginPoint.getxPos(), beginPoint.getyPos(), endPoint.getxPos(), endPoint.getyPos());
}
}

45
src/MovingPoint.java Normal file
View File

@@ -0,0 +1,45 @@
import org.jfree.fx.FXGraphics2D;
import java.awt.geom.Point2D;
public class MovingPoint {
private double xPos;
private double yPos;
private double xSpeed;
private double ySpeed;
private double canvasWidth;
private double canvasHeight;
public MovingPoint(double startX, double startY, double xStartSpeed, double yStartSpeed) {
this.xPos = startX;
this.yPos = startY;
this.xSpeed = xStartSpeed * 0.8;
this.ySpeed = yStartSpeed * 0.8;
}
public void update() {
if (this.xPos > canvasWidth || this.xPos < 0) xSpeed = -xSpeed;
if (this.yPos > canvasHeight || this.yPos < 0) ySpeed = -ySpeed;
this.xPos += xSpeed;
this.yPos += ySpeed;
}
public void setMovingBounds(double canvasWidth, double canvasHeight) {
this.canvasHeight = canvasHeight;
this.canvasWidth = canvasWidth;
}
public double getxPos() {
return xPos;
}
public double getyPos() {
return yPos;
}
public Point2D.Double getAsPoint() {
return new Point2D.Double(xPos, yPos);
}
}

119
src/Screensaver.java Normal file
View File

@@ -0,0 +1,119 @@
import java.awt.*;
import java.awt.geom.*;
import java.util.ArrayList;
import java.util.Random;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import org.jfree.fx.FXGraphics2D;
import org.jfree.fx.ResizableCanvas;
public class Screensaver extends Application {
private ResizableCanvas canvas;
private double frameTime = 0;
private ArrayList<MovingLine> lines;
private Random r;
@Override
public void start(Stage stage) throws Exception {
r = new Random();
BorderPane mainPane = new BorderPane();
canvas = new ResizableCanvas(this::draw, mainPane);
mainPane.setCenter(canvas);
FXGraphics2D g2d = new FXGraphics2D(canvas.getGraphicsContext2D());
this.lines = new ArrayList<>();
makeLines();
new AnimationTimer() {
long last = -1;
@Override
public void handle(long now) {
if (last == -1)
last = now;
update((now - last) / 1000000000.0);
last = now;
draw(g2d);
}
}.start();
stage.setScene(new Scene(mainPane));
stage.setTitle("Screensaver");
stage.show();
draw(g2d);
}
public void makeLines() {
//min + (max - min) * r.nextDouble();
MovingPoint point1 = new MovingPoint(generateRandomInt(), generateRandomInt(), generateRandomDouble(), generateRandomDouble());
MovingPoint point2 = new MovingPoint(generateRandomInt(), generateRandomInt(), generateRandomDouble(), generateRandomDouble());
MovingPoint point3 = new MovingPoint(generateRandomInt(), generateRandomInt(), generateRandomDouble(), generateRandomDouble());
MovingPoint point4 = new MovingPoint(generateRandomInt(), generateRandomInt(), generateRandomDouble(), generateRandomDouble());
MovingPoint point5 = new MovingPoint(generateRandomInt(), generateRandomInt(), generateRandomDouble(), generateRandomDouble());
MovingPoint point6 = new MovingPoint(generateRandomInt(), generateRandomInt(), generateRandomDouble(), generateRandomDouble());
lines.add(new MovingLine(point1, point2, Color.magenta));
lines.add(new MovingLine(point3, point2, Color.green));
lines.add(new MovingLine(point1, point3, Color.cyan));
lines.add(new MovingLine(point4, point5, Color.RED));
lines.add(new MovingLine(point4, point6, Color.yellow));
lines.add(new MovingLine(point5, point6, Color.LIGHT_GRAY));
// lines.add(new MovingLine(point4,point1,Color.magenta));
// lines.add(new MovingLine(point3, point2, Color.red));
}
public void draw(FXGraphics2D graphics) {
graphics.setTransform(new AffineTransform());
graphics.setBackground(Color.black);
graphics.clearRect(0, 0, (int) canvas.getWidth(), (int) canvas.getHeight());
for (MovingLine line : this.lines) {
line.draw(graphics);
}
}
public void update(double deltaTime) {
frameTime += deltaTime;
if (frameTime > 1d / 60d) {
updateFrame();
frameTime = 0.0;
}
}
private void updateFrame() {
for (MovingLine line : this.lines) {
line.setMovingBounds(canvas.getWidth(), canvas.getHeight());
line.update();
}
}
private double generateRandomDouble() {
double rand = -2d + (2d - -2d) * r.nextDouble();
System.out.println(rand);
return rand;
}
private double generateRandomInt() {
return r.nextInt((500 - 10) + 1) - 10;
}
public static void main(String[] args) {
launch(Screensaver.class);
}
}

View File

@@ -0,0 +1,321 @@
package sound;
/*File AudioCapture02.java
This program demonstrates the capture and
subsequent playback of audio data.
A GUI appears on the screen containing the
following buttons:
Capture
Stop
Playback
Input data from a microphone is captured and
saved in a ByteArrayOutputStream object when the
user clicks the Capture button.
Data capture stops when the user clicks the Stop
button.
Playback begins when the user clicks the Playback
button.
This version of the program gets and displays a
list of available mixers, producing the following
output:
Available mixers:
Java Sound Audio Engine
Microsoft Sound Mapper
Modem #0 Line Record
ESS Maestro
Thus, this machine had the four mixers listed
above available at the time the program was run.
Then the program gets and uses one of the
available mixers instead of simply asking for a
compatible mixer as was the case in a previous
version of the program.
Either of the following two mixers can be used in
this program:
Microsoft Sound Mapper
ESS Maestro
Neither of the following two mixers will work in
this program. The mixers fail at runtime for
different reasons:
Java Sound Audio Engine
Modem #0 Line Record
The Java Sound Audio Engine mixer fails due to a
data format compatibility problem.
The Modem #0 Line Record mixer fails due to an
"Unexpected Error"
Tested using SDK 1.4.0 under Win2000
************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.sound.sampled.*;
public class AudioCapture02 extends JFrame{
boolean stopCapture = false;
ByteArrayOutputStream byteArrayOutputStream;
AudioFormat audioFormat;
TargetDataLine targetDataLine;
AudioInputStream audioInputStream;
SourceDataLine sourceDataLine;
public static void main(String args[]){
new AudioCapture02();
}//end main
public AudioCapture02(){//constructor
final JButton captureBtn =
new JButton("Capture");
final JButton stopBtn = new JButton("Stop");
final JButton playBtn =
new JButton("Playback");
captureBtn.setEnabled(true);
stopBtn.setEnabled(false);
playBtn.setEnabled(false);
//Register anonymous listeners
captureBtn.addActionListener(
new ActionListener(){
public void actionPerformed(
ActionEvent e){
captureBtn.setEnabled(false);
stopBtn.setEnabled(true);
playBtn.setEnabled(false);
//Capture input data from the
// microphone until the Stop button is
// clicked.
captureAudio();
}//end actionPerformed
}//end ActionListener
);//end addActionListener()
getContentPane().add(captureBtn);
stopBtn.addActionListener(
new ActionListener(){
public void actionPerformed(
ActionEvent e){
captureBtn.setEnabled(true);
stopBtn.setEnabled(false);
playBtn.setEnabled(true);
//Terminate the capturing of input data
// from the microphone.
stopCapture = true;
}//end actionPerformed
}//end ActionListener
);//end addActionListener()
getContentPane().add(stopBtn);
playBtn.addActionListener(
new ActionListener(){
public void actionPerformed(
ActionEvent e){
//Play back all of the data that was
// saved during capture.
playAudio();
}//end actionPerformed
}//end ActionListener
);//end addActionListener()
getContentPane().add(playBtn);
getContentPane().setLayout(new FlowLayout());
setTitle("Capture/Playback Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(250,70);
setVisible(true);
}//end constructor
//This method captures audio input from a
// microphone and saves it in a
// ByteArrayOutputStream object.
private void captureAudio(){
try{
//Get and display a list of
// available mixers.
Mixer.Info[] mixerInfo =
AudioSystem.getMixerInfo();
System.out.println("Available mixers:");
for(int cnt = 0; cnt < mixerInfo.length;
cnt++){
System.out.println(mixerInfo[cnt].
getName());
}//end for loop
//Get everything set up for capture
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo =
new DataLine.Info(
TargetDataLine.class,
audioFormat);
//Select one of the available
// mixers.
Mixer mixer = AudioSystem.
getMixer(mixerInfo[3]);
//Get a TargetDataLine on the selected
// mixer.
targetDataLine = (TargetDataLine)
mixer.getLine(dataLineInfo);
//Prepare the line for use.
targetDataLine.open(audioFormat);
targetDataLine.start();
//Create a thread to capture the microphone
// data and start it running. It will run
// until the Stop button is clicked.
Thread captureThread = new CaptureThread();
captureThread.start();
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}//end catch
}//end captureAudio method
//This method plays back the audio data that
// has been saved in the ByteArrayOutputStream
private void playAudio() {
try{
//Get everything set up for playback.
//Get the previously-saved data into a byte
// array object.
byte audioData[] = byteArrayOutputStream.
toByteArray();
//Get an input stream on the byte array
// containing the data
InputStream byteArrayInputStream =
new ByteArrayInputStream(audioData);
AudioFormat audioFormat = getAudioFormat();
audioInputStream = new AudioInputStream(
byteArrayInputStream,
audioFormat,
audioData.length/audioFormat.
getFrameSize());
DataLine.Info dataLineInfo =
new DataLine.Info(
SourceDataLine.class,
audioFormat);
sourceDataLine = (SourceDataLine)
AudioSystem.getLine(dataLineInfo);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
//Create a thread to play back the data and
// start it running. It will run until
// all the data has been played back.
Thread playThread = new PlayThread();
playThread.start();
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}//end catch
}//end playAudio
//This method creates and returns an
// AudioFormat object for a given set of format
// parameters. If these parameters don't work
// well for you, try some of the other
// allowable parameter values, which are shown
// in comments following the declartions.
private AudioFormat getAudioFormat(){
float sampleRate = 8000;
//8000,11025,16000,22050,44100
int sampleSizeInBits = 16;
//8,16
int channels = 2;
//1,2
boolean signed = true;
//true,false
boolean bigEndian = true;
//true,false
return new AudioFormat(
sampleRate,
sampleSizeInBits,
channels,
signed,
bigEndian);
}//end getAudioFormat
//=============================================//
//Inner class to capture data from microphone
class CaptureThread extends Thread{
//An arbitrary-size temporary holding buffer
byte tempBuffer[] = new byte[10000];
public void run(){
byteArrayOutputStream =
new ByteArrayOutputStream();
stopCapture = false;
try{//Loop until stopCapture is set by
// another thread that services the Stop
// button.
while(!stopCapture){
//Read data from the internal buffer of
// the data line.
int cnt = targetDataLine.read(tempBuffer,
0,
tempBuffer.length);
if(cnt > 0){
//Save data in output stream object.
byteArrayOutputStream.write(tempBuffer,
0,
cnt);
}//end if
}//end while
byteArrayOutputStream.close();
}catch (Exception e) {
System.out.println(e);
System.exit(0);
}//end catch
}//end run
}//end inner class CaptureThread
//===================================//
//Inner class to play back the data
// that was saved.
class PlayThread extends Thread{
byte tempBuffer[] = new byte[10000];
public void run(){
try{
int cnt;
//Keep looping until the input read method
// returns -1 for empty stream.
while((cnt = audioInputStream.read(
tempBuffer, 0,
tempBuffer.length)) != -1){
if(cnt > 0){
//Write data to the internal buffer of
// the data line where it will be
// delivered to the speaker.
sourceDataLine.write(tempBuffer,0,cnt);
}//end if
}//end while
//Block and wait for internal buffer of the
// data line to empty.
sourceDataLine.drain();
sourceDataLine.close();
}catch (Exception e) {
System.out.println(e);
System.exit(0);
}//end catch
}//end run
}//end inner class PlayThread
//=============================================//
}//end outer class AudioCapture02.java

162
src/sound/Capture.java Normal file
View File

@@ -0,0 +1,162 @@
package sound;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.sound.sampled.*;
public class Capture extends JFrame {
protected boolean running;
ByteArrayOutputStream out;
public Capture() {
super("sound.Capture Sound Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container content = getContentPane();
final JButton capture = new JButton("sound.Capture");
final JButton stop = new JButton("Stop");
final JButton play = new JButton("Play");
capture.setEnabled(true);
stop.setEnabled(false);
play.setEnabled(false);
ActionListener captureListener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
capture.setEnabled(false);
stop.setEnabled(true);
play.setEnabled(false);
captureAudio();
}
};
capture.addActionListener(captureListener);
content.add(capture, BorderLayout.NORTH);
ActionListener stopListener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
capture.setEnabled(true);
stop.setEnabled(false);
play.setEnabled(true);
running = false;
}
};
stop.addActionListener(stopListener);
content.add(stop, BorderLayout.CENTER);
ActionListener playListener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
playAudio();
}
};
play.addActionListener(playListener);
content.add(play, BorderLayout.SOUTH);
}
private void captureAudio() {
try {
final AudioFormat format = getFormat();
DataLine.Info info = new DataLine.Info(
TargetDataLine.class, format);
final TargetDataLine line = (TargetDataLine)
AudioSystem.getLine(info);
line.open(format);
line.start();
Runnable runner = new Runnable() {
int bufferSize = (int)format.getSampleRate()
* format.getFrameSize();
byte buffer[] = new byte[bufferSize];
public void run() {
out = new ByteArrayOutputStream();
running = true;
try {
while (running) {
int count =
line.read(buffer, 0, buffer.length);
if (count > 0) {
out.write(buffer, 0, count);
}
}
out.close();
} catch (IOException e) {
System.err.println("I/O problems: " + e);
System.exit(-1);
}
}
};
Thread captureThread = new Thread(runner);
captureThread.start();
} catch (LineUnavailableException e) {
System.err.println("Line unavailable: " + e);
System.exit(-2);
}
}
private void playAudio() {
try {
byte audio[] = out.toByteArray();
InputStream input =
new ByteArrayInputStream(audio);
final AudioFormat format = getFormat();
final AudioInputStream ais =
new AudioInputStream(input, format,
audio.length / format.getFrameSize());
DataLine.Info info = new DataLine.Info(
SourceDataLine.class, format);
final SourceDataLine line = (SourceDataLine)
AudioSystem.getLine(info);
line.open(format);
line.start();
Runnable runner = new Runnable() {
int bufferSize = (int) format.getSampleRate()
* format.getFrameSize();
byte buffer[] = new byte[bufferSize];
public void run() {
try {
int count;
while ((count = ais.read(
buffer, 0, buffer.length)) != -1) {
if (count > 0) {
line.write(buffer, 0, count);
}
}
line.drain();
line.close();
} catch (IOException e) {
System.err.println("I/O problems: " + e);
System.exit(-3);
}
}
};
Thread playThread = new Thread(runner);
playThread.start();
} catch (LineUnavailableException e) {
System.err.println("Line unavailable: " + e);
System.exit(-4);
}
}
private AudioFormat getFormat() {
float sampleRate = 16000;
int sampleSizeInBits = 8;
int channels = 2;
boolean signed = false;
boolean bigEndian = true;
return new AudioFormat(sampleRate,
sampleSizeInBits, channels, signed, bigEndian);
}
public static void main(String args[]) {
JFrame frame = new Capture();
frame.pack();
frame.show();
}
}

View File

@@ -0,0 +1,108 @@
package sound;
import javax.sound.sampled.*;
import java.io.*;
/**
* A sample program is to demonstrate how to record sound in Java
* author: www.codejava.net
*/
public class JavaSoundRecorder {
// record duration, in milliseconds
static final long RECORD_TIME = 10000; // 1 minute
// path of the wav file
File wavFile = new File("RecordAudio.wav");
// format of audio file
AudioFileFormat.Type fileType = AudioFileFormat.Type.WAVE;
// the line from which audio data is captured
TargetDataLine line;
SourceDataLine sourceDataLine;
/**
* Defines an audio format
*/
AudioFormat getAudioFormat() {
float sampleRate = 16000;
int sampleSizeInBits = 8;
int channels = 2;
boolean signed = true;
boolean bigEndian = true;
AudioFormat format = new AudioFormat(sampleRate, sampleSizeInBits,
channels, signed, bigEndian);
return format;
}
/**
* Captures the sound and record into a WAV file
*/
void start() {
try {
AudioFormat format = getAudioFormat();
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
// checks if system supports the data line
if (!AudioSystem.isLineSupported(info)) {
System.out.println("Line not supported");
System.exit(0);
}
sourceDataLine = AudioSystem.getSourceDataLine(format);
sourceDataLine.open(format);
sourceDataLine.start();
line = (TargetDataLine) AudioSystem.getLine(info);
line.open(format);
line.start(); // start capturing
System.out.println("Start capturing...");
AudioInputStream ais = new AudioInputStream(line);
System.out.println("Start recording...");
// start recording
AudioSystem.write(ais, fileType, wavFile);
} catch (LineUnavailableException ex) {
ex.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
/**
* Closes the target data line to finish capturing and recording
*/
void finish() {
line.stop();
line.close();
System.out.println("Finished");
}
/**
* Entry to run the program
*/
public static void main(String[] args) {
final JavaSoundRecorder recorder = new JavaSoundRecorder();
// creates a new thread that waits for a specified
// of time before stopping
Thread stopper = new Thread(() -> {
try {
Thread.sleep(RECORD_TIME);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
recorder.finish();
});
stopper.start();
// start recording
recorder.start();
// System.out.println(Arrays.toString(AudioSystem.getMixerInfo()));
}
}

View File

@@ -0,0 +1,104 @@
package sound;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.*;
/**
* A utility class provides general functions for recording sound.
* @author www.codejava.net
*
*/
public class SoundRecordingUtil {
private static final int BUFFER_SIZE = 4096;
private ByteArrayOutputStream recordBytes;
private TargetDataLine audioLine;
private AudioFormat format;
private boolean isRunning;
/**
* Defines a default audio format used to record
*/
AudioFormat getAudioFormat() {
float sampleRate = 8000;
int sampleSizeInBits = 16;
int channels = 2;
boolean signed = true;
boolean bigEndian = true;
return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed,
bigEndian);
}
/**
* Start recording sound.
* @throws LineUnavailableException if the system does not support the specified
* audio format nor open the audio data line.
*/
public void start() throws LineUnavailableException {
System.out.println("starting method");
format = getAudioFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
// checks if system supports the data line
if (!AudioSystem.isLineSupported(info)) {
throw new LineUnavailableException(
"The system does not support the specified format.");
}
audioLine = AudioSystem.getTargetDataLine(format);
audioLine.open(format);
audioLine.start();
System.out.println("started line");
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = 0;
recordBytes = new ByteArrayOutputStream();
isRunning = true;
while (isRunning) {
System.out.println("running");
bytesRead = audioLine.read(buffer, 0, buffer.length);
recordBytes.write(buffer, 0, bytesRead);
}
}
/**
* Stop recording sound.
* @throws IOException if any I/O error occurs.
*/
public void stop() throws IOException {
isRunning = false;
System.out.println("running is false");
if (audioLine != null) {
System.out.println("audioline is not null");
// audioLine.drain();
System.out.println("audioline drained");
audioLine.close();
System.out.println("audioline closed");
}
}
/**
* Save recorded sound data into a .wav file format.
* @param wavFile The file to be saved.
* @throws IOException if any I/O error occurs.
*/
public void save(File wavFile) throws IOException {
byte[] audioData = recordBytes.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(audioData);
AudioInputStream audioInputStream = new AudioInputStream(bais, format,
audioData.length / format.getFrameSize());
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, wavFile);
audioInputStream.close();
recordBytes.close();
}
}

View File

@@ -0,0 +1,56 @@
package sound;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.LineUnavailableException;
/**
* A sample program that tests the sound.SoundRecordingUtil utility class.
* @author www.codejava.net
*
*/
public class TestSoundRecordingUtil {
private static final int RECORD_TIME = 10000; // 1 seconds
public static void main(String[] args) {
File wavFile = new File("Record.wav");
final SoundRecordingUtil recorder = new SoundRecordingUtil();
// create a separate thread for recording
Thread recordThread = new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println("Start recording...");
recorder.start();
} catch (LineUnavailableException ex) {
ex.printStackTrace();
System.exit(-1);
}
}
});
recordThread.start();
try {
Thread.sleep(RECORD_TIME);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
System.out.println("time over");
try {
recorder.stop();
System.out.println("stopped");
recorder.save(wavFile);
System.out.println("STOPPED");
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println("DONE");
}
}

0
test/.gitkeep Normal file
View File

16
test/TestStub.java Normal file
View File

@@ -0,0 +1,16 @@
import fi.helsinki.cs.tmc.edutestutils.Points;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@Points("3-5")
public class TestStub {
@Test
public void testCalls()
{
assertTrue("You shall pass", true);
}
}

14
week3-005.Screensaver.iml Normal file
View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="library" name="tmc-junit-runner" level="project" />
</component>
</module>