diff --git a/ChatProg/build.xml b/ChatProg/build.xml new file mode 100644 index 0000000..51b7d5e --- /dev/null +++ b/ChatProg/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project ChatProg. + + + diff --git a/ChatProg/manifest.mf b/ChatProg/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/ChatProg/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/ChatProg/nbproject/build-impl.xml b/ChatProg/nbproject/build-impl.xml new file mode 100644 index 0000000..1a61dcd --- /dev/null +++ b/ChatProg/nbproject/build-impl.xml @@ -0,0 +1,1756 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ChatProg/nbproject/genfiles.properties b/ChatProg/nbproject/genfiles.properties new file mode 100644 index 0000000..c26f66e --- /dev/null +++ b/ChatProg/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b5658c92 +build.xml.script.CRC32=8f33d0e4 +build.xml.stylesheet.CRC32=f85dc8f2@1.96.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=b5658c92 +nbproject/build-impl.xml.script.CRC32=24347752 +nbproject/build-impl.xml.stylesheet.CRC32=f89f7d21@1.96.0.48 diff --git a/ChatProg/nbproject/project.properties b/ChatProg/nbproject/project.properties new file mode 100644 index 0000000..7cbf77f --- /dev/null +++ b/ChatProg/nbproject/project.properties @@ -0,0 +1,97 @@ +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 +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}/ChatProg.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/ChatProg +excludes= +file.reference.chat_prog-src=../src +includes=** +jar.compress=false +javac.classpath=\ + ${libs.absolutelayout.classpath}:\ + ${libs.OhmLogger.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=15 +javac.target=15 +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=ChatProg +main.class=netz.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=${file.reference.chat_prog-src} diff --git a/ChatProg/nbproject/project.xml b/ChatProg/nbproject/project.xml new file mode 100644 index 0000000..2c3593a --- /dev/null +++ b/ChatProg/nbproject/project.xml @@ -0,0 +1,13 @@ + + + org.netbeans.modules.java.j2seproject + + + ChatProg + + + + + + + diff --git a/src/netz/Start.java b/src/netz/Start.java index ea5d565..1cd292e 100755 --- a/src/netz/Start.java +++ b/src/netz/Start.java @@ -6,9 +6,6 @@ package netz; - -import java.io.IOException; -import java.net.MalformedURLException; import javax.swing.JFrame; import javax.swing.WindowConstants; import netz.controller.ReceiveAdapter; @@ -66,6 +63,7 @@ public class Start JOptionPane.showMessageDialog(null, ex.toString()); } new Start(); + new Start(); } } \ No newline at end of file diff --git a/src/netz/controller/CommandConnect.java b/src/netz/controller/CommandConnect.java index 68db13a..15bfa31 100644 --- a/src/netz/controller/CommandConnect.java +++ b/src/netz/controller/CommandConnect.java @@ -9,8 +9,6 @@ package netz.controller; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; import java.util.logging.Logger; import ohmlogger.OhmLogger; import netz.model.ChatModel; @@ -52,11 +50,7 @@ public class CommandConnect implements ActionListener synchronized (this){ try { view.getLblType().setText("Server"); - ServerSocket sSocket = new ServerSocket(PORT); - lg.info("Server: Warte auf Verbindung ..."); - Socket s = sSocket.accept(); // Achtung: blockiert! - lg.info("Server: Verbindung akzeptiert"); - model.setSocket(s); + model.setServer(PORT); } catch (IOException ex) { lg.severe(ex.toString()); } @@ -68,10 +62,8 @@ public class CommandConnect implements ActionListener synchronized (this){ try { view.getLblType().setText("Client"); - lg.info("Client: verbinde ..."); - Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert! - lg.info("Client: Verbindung hergestellt"); - model.setSocket(s); + model.setClient(PORT, IP_ADRESSE); + } catch (IOException ex) { lg.severe(ex.toString()); } diff --git a/src/netz/controller/ReceiveAdapter.java b/src/netz/controller/ReceiveAdapter.java index 339436a..69f7c32 100644 --- a/src/netz/controller/ReceiveAdapter.java +++ b/src/netz/controller/ReceiveAdapter.java @@ -48,6 +48,7 @@ public class ReceiveAdapter implements Flow.Subscriber { view.getLblStatusDialog().setText("Nachricht empfangen"); view.getjTextArea().append("Partner: " + item + "\n"); + subscription.request(1); //System.out.println(item); } diff --git a/src/netz/model/ChatModel.java b/src/netz/model/ChatModel.java index 3a8621b..7fd898c 100644 --- a/src/netz/model/ChatModel.java +++ b/src/netz/model/ChatModel.java @@ -16,6 +16,7 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.net.ServerSocket; import java.net.Socket; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -78,8 +79,6 @@ public class ChatModel implements Runnable } public void setSocket(Socket s) throws IOException { - this.socket = s; - InputStream iStream = s.getInputStream(); OutputStream oStream = s.getOutputStream(); @@ -91,6 +90,41 @@ public class ChatModel implements Runnable out = new PrintWriter(osr); start(); } + public void setClient(int PORT, String IP_ADRESSE) throws IOException + { + Thread connectThread = new Thread(new Runnable() { + @Override + public void run() { + try { + lg.info("Client: verbinde ..."); + Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert! + lg.info("Client: Verbindung hergestellt"); + setSocket(s); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + connectThread.start(); + } + public void setServer(int PORT) throws IOException + { + Thread connectThread = new Thread(new Runnable() { + @Override + public void run() { + try { + ServerSocket sSocket = new ServerSocket(PORT); + lg.info("Server: Warte auf Verbindung ..."); + Socket s = sSocket.accept(); // Achtung: blockiert! + lg.info("Server: Verbindung akzeptiert"); + setSocket(s); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + connectThread.start(); + } public void sendMessage(String msg) { diff --git a/src/netz/view/ChatView.form b/src/netz/view/ChatView.form index 4db136e..b439e69 100644 --- a/src/netz/view/ChatView.form +++ b/src/netz/view/ChatView.form @@ -37,9 +37,6 @@ - - - @@ -53,16 +50,6 @@ - - - - - - - - - - @@ -83,23 +70,41 @@ - - - - + - + - + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/netz/view/ChatView.java b/src/netz/view/ChatView.java index e7f06dd..f9c9301 100644 --- a/src/netz/view/ChatView.java +++ b/src/netz/view/ChatView.java @@ -114,18 +114,17 @@ public class ChatView extends javax.swing.JFrame lblType = new javax.swing.JLabel(); btnSetClient = new javax.swing.JButton(); btnSetServer = new javax.swing.JButton(); - txtField = new javax.swing.JTextField(); btnSend = new javax.swing.JButton(); lblStatusDialog = new javax.swing.JLabel(); + jPanel2 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea = new javax.swing.JTextArea(); + txtField = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("ChatTool"); jPanel1.setLayout(new java.awt.GridLayout(1, 0)); - - lblType.setText("Client"); jPanel1.add(lblType); btnSetClient.setText("Client"); @@ -136,6 +135,22 @@ public class ChatView extends javax.swing.JFrame getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_START); + btnSend.setText("Send"); + getContentPane().add(btnSend, java.awt.BorderLayout.LINE_END); + + lblStatusDialog.setText("\"\""); + getContentPane().add(lblStatusDialog, java.awt.BorderLayout.PAGE_END); + + jPanel2.setLayout(new java.awt.GridLayout(2, 1)); + + jTextArea.setEditable(false); + jTextArea.setBackground(new java.awt.Color(204, 204, 204)); + jTextArea.setColumns(20); + jTextArea.setRows(5); + jScrollPane1.setViewportView(jTextArea); + + jPanel2.add(jScrollPane1); + txtField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) @@ -143,19 +158,9 @@ public class ChatView extends javax.swing.JFrame txtFieldActionPerformed(evt); } }); - getContentPane().add(txtField, java.awt.BorderLayout.CENTER); + jPanel2.add(txtField); - btnSend.setText("Send"); - getContentPane().add(btnSend, java.awt.BorderLayout.LINE_END); - - lblStatusDialog.setText("\"\""); - getContentPane().add(lblStatusDialog, java.awt.BorderLayout.PAGE_END); - - jTextArea.setColumns(20); - jTextArea.setRows(5); - jScrollPane1.setViewportView(jTextArea); - - getContentPane().add(jScrollPane1, java.awt.BorderLayout.LINE_START); + getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER); pack(); }// //GEN-END:initComponents @@ -222,6 +227,7 @@ public class ChatView extends javax.swing.JFrame private javax.swing.JButton btnSetClient; private javax.swing.JButton btnSetServer; private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea; private javax.swing.JLabel lblStatusDialog; diff --git a/src/ohmlogger/MyFormatter.java b/src/ohmlogger/MyFormatter.java deleted file mode 100644 index f664e26..0000000 --- a/src/ohmlogger/MyFormatter.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -package ohmlogger; - -import java.util.Date; -import java.util.logging.Formatter; -import java.util.logging.LogRecord; - -/** - * - * @author chris - */ -public class MyFormatter extends Formatter { - - @Override - public String format(LogRecord lr) { - String date = String.format("%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp", new Date(lr.getMillis())); - String s = ("| ")+lr.getMillis()+(" | ")+date+(" | ")+lr.getLevel().toString()+(" | ")+lr.getSourceClassName()+(" | ")+lr.getMessage()+(" | ")+"\n"; - return s; - } - -} \ No newline at end of file diff --git a/src/ohmlogger/OhmLogger.java b/src/ohmlogger/OhmLogger.java deleted file mode 100644 index 1d26989..0000000 --- a/src/ohmlogger/OhmLogger.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package ohmlogger; - - -import java.io.File; -import java.io.IOException; -import java.util.logging.*; - - - -/** - * - * @author chris, hd - */ -public class OhmLogger -{ - public OhmLogger() - { - } - private static Logger lg = null; - public static Logger getLogger() - { - if (lg == null) - { - lg = Logger.getLogger("OhmLogger"); - initLogger(); - } - return lg; - } - - private static void initLogger() - { - try{ - String datei = System.getProperty("java.io.tmpdir") + File.separator + "log.txt"; - FileHandler fh = new FileHandler(datei); - fh.setFormatter(new MyFormatter()); - ConsoleHandler ch = new ConsoleHandler(); - lg.addHandler(fh); - ch.setFormatter(new MyFormatter()); - lg.setUseParentHandlers(false); - lg.addHandler(ch); - lg.setLevel(Level.ALL); - - } - catch(IOException ioex) - { - System.err.println(ioex); - } - } -} diff --git a/src/ohmlogger/OhmLogger.properties b/src/ohmlogger/OhmLogger.properties deleted file mode 100644 index 44a9c20..0000000 --- a/src/ohmlogger/OhmLogger.properties +++ /dev/null @@ -1,4 +0,0 @@ -#Level -LOG_LEVEL=INFO -#Log-Datei -LOG_DATEI=../logOHM.txt \ No newline at end of file diff --git a/src/ohmlogger/logger.properties b/src/ohmlogger/logger.properties deleted file mode 100644 index 82e49d2..0000000 --- a/src/ohmlogger/logger.properties +++ /dev/null @@ -1,4 +0,0 @@ -#Level -LOG_LEVEL=ALL -#Log-Datei -LOG_DATEI= \ No newline at end of file