Init Commit
This commit is contained in:
commit
b88bcdd406
73
build.xml
Normal file
73
build.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?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="Aufgabe7_bandit" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project Aufgabe7_bandit.</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: JAR building
|
||||
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="Aufgabe7_bandit-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>
|
3
manifest.mf
Normal file
3
manifest.mf
Normal file
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
1771
nbproject/build-impl.xml
Normal file
1771
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=ed1b7c08
|
||||
build.xml.script.CRC32=ec768dde
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.108.0.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=ed1b7c08
|
||||
nbproject/build-impl.xml.script.CRC32=6154016a
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48
|
97
nbproject/project.properties
Normal file
97
nbproject/project.properties
Normal file
@ -0,0 +1,97 @@
|
||||
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=Aufgabe7_bandit
|
||||
application.vendor=le
|
||||
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.modulepath=\
|
||||
${run.modulepath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
debug.test.modulepath=\
|
||||
${run.test.modulepath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/Aufgabe7_bandit.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
dist.jlink.dir=${dist.dir}/jlink
|
||||
dist.jlink.output=${dist.jlink.dir}/Aufgabe7_bandit
|
||||
endorsed.classpath=
|
||||
excludes=
|
||||
includes=**
|
||||
jar.compress=false
|
||||
javac.classpath=
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.external.vm=true
|
||||
javac.modulepath=
|
||||
javac.processormodulepath=
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=17
|
||||
javac.target=17
|
||||
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.html5=false
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
# The jlink additional root modules to resolve
|
||||
jlink.additionalmodules=
|
||||
# The jlink additional command line parameters
|
||||
jlink.additionalparam=
|
||||
jlink.launcher=true
|
||||
jlink.launcher.name=Aufgabe7_bandit
|
||||
main.class=bandit.Start
|
||||
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.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
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
|
15
nbproject/project.xml
Normal file
15
nbproject/project.xml
Normal 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>Aufgabe7_bandit</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
45
src/bandit/Start.java
Normal file
45
src/bandit/Start.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
|
||||
*/
|
||||
|
||||
package bandit;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
/**
|
||||
* Builder Class
|
||||
* @author le
|
||||
*/
|
||||
public class Start
|
||||
{
|
||||
public Start()
|
||||
{
|
||||
ZahlenView view = new ZahlenView();
|
||||
Zahlengenerator model = new Zahlengenerator();
|
||||
StartStopController controller = new StartStopController(view, model);
|
||||
WertAdapter adapter = new WertAdapter(view, model);
|
||||
|
||||
controller.registerEvents();
|
||||
model.addWertSubscription(adapter);
|
||||
view.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, ex.toString());
|
||||
}
|
||||
new Start();
|
||||
}
|
||||
}
|
49
src/bandit/StartStopController.java
Normal file
49
src/bandit/StartStopController.java
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package bandit;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.logging.Logger;
|
||||
import bandit.util.OhmLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author le
|
||||
*/
|
||||
public class StartStopController implements ActionListener
|
||||
{
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
private ZahlenView view;
|
||||
private Zahlengenerator model;
|
||||
|
||||
public StartStopController(ZahlenView view, Zahlengenerator model)
|
||||
{
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public void registerEvents()
|
||||
{
|
||||
view.getBtnStart().addActionListener(this);
|
||||
view.getBtnStop().addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent evt)
|
||||
{
|
||||
if (evt.getSource() == view.getBtnStart())
|
||||
{
|
||||
lg.info("Start");
|
||||
model.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
lg.info("Stop");
|
||||
model.stop();
|
||||
}
|
||||
}
|
||||
}
|
55
src/bandit/WertAdapter.java
Normal file
55
src/bandit/WertAdapter.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package bandit;
|
||||
|
||||
import java.util.concurrent.Flow;
|
||||
import java.util.concurrent.Flow.Subscriber;
|
||||
import java.util.concurrent.Flow.Subscription;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author le
|
||||
*/
|
||||
public class WertAdapter implements Subscriber<Integer>
|
||||
{
|
||||
private ZahlenView view;
|
||||
private Zahlengenerator model;
|
||||
private Subscription subscription;
|
||||
|
||||
public WertAdapter(ZahlenView view, Zahlengenerator model)
|
||||
{
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Flow.Subscription subscription)
|
||||
{
|
||||
this.subscription = subscription;
|
||||
this.subscription.request(1);
|
||||
//this.subscription.request(Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Integer item)
|
||||
{
|
||||
String strWert = String.valueOf(item);
|
||||
view.getLblZahl().setText(strWert);
|
||||
this.subscription.request(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
62
src/bandit/ZahlenView.form
Normal file
62
src/bandit/ZahlenView.form
Normal file
@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-125,0,0,2,14"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="lblZahl">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Liberation Sans" size="100" style="0"/>
|
||||
</Property>
|
||||
<Property name="horizontalAlignment" type="int" value="0"/>
|
||||
<Property name="text" type="java.lang.String" value="?"/>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Center"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="jPanel1">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Last"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="btnStart">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Start"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnStop">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Stop"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
132
src/bandit/ZahlenView.java
Normal file
132
src/bandit/ZahlenView.java
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
||||
*/
|
||||
package bandit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author le
|
||||
*/
|
||||
public class ZahlenView extends javax.swing.JFrame
|
||||
{
|
||||
/**
|
||||
* @return the btnStart
|
||||
*/
|
||||
public javax.swing.JButton getBtnStart()
|
||||
{
|
||||
return btnStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the btnStop
|
||||
*/
|
||||
public javax.swing.JButton getBtnStop()
|
||||
{
|
||||
return btnStop;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lblZahl
|
||||
*/
|
||||
public javax.swing.JLabel getLblZahl()
|
||||
{
|
||||
return lblZahl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new form ZahlenView
|
||||
*/
|
||||
public ZahlenView()
|
||||
{
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
lblZahl = new javax.swing.JLabel();
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
btnStart = new javax.swing.JButton();
|
||||
btnStop = new javax.swing.JButton();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
lblZahl.setFont(new java.awt.Font("Liberation Sans", 0, 100)); // NOI18N
|
||||
lblZahl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
||||
lblZahl.setText("?");
|
||||
getContentPane().add(lblZahl, java.awt.BorderLayout.CENTER);
|
||||
|
||||
btnStart.setText("Start");
|
||||
jPanel1.add(btnStart);
|
||||
|
||||
btnStop.setText("Stop");
|
||||
jPanel1.add(btnStop);
|
||||
|
||||
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[])
|
||||
{
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
try
|
||||
{
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
|
||||
{
|
||||
if ("Nimbus".equals(info.getName()))
|
||||
{
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException ex)
|
||||
{
|
||||
java.util.logging.Logger.getLogger(ZahlenView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
catch (InstantiationException ex)
|
||||
{
|
||||
java.util.logging.Logger.getLogger(ZahlenView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
catch (IllegalAccessException ex)
|
||||
{
|
||||
java.util.logging.Logger.getLogger(ZahlenView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
catch (javax.swing.UnsupportedLookAndFeelException ex)
|
||||
{
|
||||
java.util.logging.Logger.getLogger(ZahlenView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
new ZahlenView().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnStart;
|
||||
private javax.swing.JButton btnStop;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JLabel lblZahl;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
129
src/bandit/Zahlengenerator.java
Normal file
129
src/bandit/Zahlengenerator.java
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package bandit;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Flow.Subscriber;
|
||||
import java.util.concurrent.SubmissionPublisher;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Logger;
|
||||
import bandit.util.OhmLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author le
|
||||
*/
|
||||
public class Zahlengenerator implements Runnable // Callable
|
||||
{
|
||||
private static Logger lg = OhmLogger.getLogger(); //Logger sollten immer static sein da sie für alle instanzen loggs ausführen
|
||||
|
||||
private int wert;
|
||||
/** Zustandsvariable !!!
|
||||
* bei 2 Werten boolean sonst enum
|
||||
*/
|
||||
// private volatile boolean laufend;
|
||||
private AtomicBoolean laufend;
|
||||
//private Thread thd;
|
||||
private ExecutorService eService;
|
||||
|
||||
private final Object LOCK;
|
||||
|
||||
private SubmissionPublisher<Integer> wertPublisher;
|
||||
|
||||
public Zahlengenerator()
|
||||
{
|
||||
wert = -1;
|
||||
//laufend = false;
|
||||
laufend = new AtomicBoolean(false);
|
||||
//thd = null;
|
||||
eService = Executors.newSingleThreadExecutor();
|
||||
wertPublisher = new SubmissionPublisher<>();
|
||||
LOCK = new Object();
|
||||
}
|
||||
|
||||
public void addWertSubscription(Subscriber<Integer> subscriber)
|
||||
{
|
||||
wertPublisher.subscribe(subscriber);
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
//laufend = true;
|
||||
laufend.set(true);
|
||||
synchronized (LOCK)
|
||||
{
|
||||
LOCK.notify();
|
||||
}
|
||||
|
||||
|
||||
if (eService.isShutdown())
|
||||
{
|
||||
eService = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
eService.execute(this);
|
||||
//Future task = eService.submit(this); v.a. bei callable
|
||||
// if (thd == null)
|
||||
// {
|
||||
// thd = new Thread(this);
|
||||
// thd.start();
|
||||
// }
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
//laufend = false;
|
||||
laufend.set(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
//while (!laufend)
|
||||
while (!laufend.get())
|
||||
{
|
||||
synchronized (LOCK)
|
||||
{
|
||||
try
|
||||
{
|
||||
lg.info("WAIT");
|
||||
LOCK.wait();
|
||||
}
|
||||
catch (InterruptedException ex)
|
||||
{
|
||||
lg.warning(ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.err.println(ex);
|
||||
}
|
||||
this.berechneWert();
|
||||
wertPublisher.submit(wert);
|
||||
}
|
||||
// thd = null;
|
||||
// eService.shutdown();
|
||||
}
|
||||
|
||||
private synchronized void berechneWert()
|
||||
{
|
||||
wert = (int) (1 + 49*Math.random());
|
||||
}
|
||||
|
||||
public synchronized int getWert()
|
||||
{
|
||||
return wert;
|
||||
}
|
||||
|
||||
}
|
55
src/bandit/util/OhmLogger.java
Normal file
55
src/bandit/util/OhmLogger.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package bandit.util;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.logging.*;
|
||||
/**
|
||||
*
|
||||
* @author le
|
||||
*/
|
||||
public class OhmLogger
|
||||
{
|
||||
private static Logger lg = null;
|
||||
|
||||
private OhmLogger() //Singelton-Patter -> privater ctor -> anlegen nur über klassenmethode möglich
|
||||
{
|
||||
}
|
||||
|
||||
public static Logger getLogger()
|
||||
{
|
||||
if (lg == null)
|
||||
{
|
||||
lg = Logger.getLogger("OhmLogger");
|
||||
initLogger();
|
||||
}
|
||||
return lg;
|
||||
}
|
||||
|
||||
private static void initLogger()
|
||||
{
|
||||
// FileHandler fh = new FileHandler();
|
||||
ConsoleHandler ch = new ConsoleHandler();
|
||||
ch.setFormatter(new OhmFormatter());
|
||||
lg.addHandler(ch);
|
||||
}
|
||||
}
|
||||
|
||||
class OhmFormatter extends SimpleFormatter
|
||||
{
|
||||
@Override
|
||||
public String format(LogRecord record)
|
||||
{
|
||||
String logline = "";
|
||||
|
||||
LocalDateTime ldt = LocalDateTime.now();
|
||||
logline += ldt.toString();
|
||||
logline += ";" + record.getMessage();
|
||||
logline += "\n";
|
||||
|
||||
return logline;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user