Browse Source

Merge origin/master

Conflicts:
	src/wuerfelthreads/Start.java
	src/wuerfelthreads/view/WuerfelView.form
	src/wuerfelthreads/view/WuerfelView.java
master
BakeOrDie 3 years ago
parent
commit
ea7e96b32c

+ 2
- 1
src/netz/Client.java View File

@@ -15,6 +15,7 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.logging.Logger;
import ohmlogger.OhmLogger;

/**
* Builder Class
@@ -22,7 +23,7 @@ import java.util.logging.Logger;
*/
public class Client
{
private static final Logger lg = Logger.getLogger("netz");
private static Logger lg = OhmLogger.getLogger();
private static final int PORT = 35000;
private static final String IP_ADRESSE = "127.0.0.1";

+ 2
- 1
src/netz/Server.java View File

@@ -16,6 +16,7 @@ import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Logger;
import ohmlogger.OhmLogger;

/**
* Builder Class
@@ -23,7 +24,7 @@ import java.util.logging.Logger;
*/
public class Server
{
private static final Logger lg = Logger.getLogger("netz");
private static Logger lg = OhmLogger.getLogger();
private static final int PORT = 35000;
public Server() throws IOException

+ 54
- 39
src/netz/Start.java View File

@@ -6,14 +6,16 @@

package netz;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import netz.controller.BtnController;
import netz.controller.ChatController;
import netz.model.ChatModel;
import netz.view.ChatView;

/**
* Builder Class
@@ -21,50 +23,63 @@ import java.net.URL;
*/
public class Start
{
public Start(String urlString, String dateiname) throws MalformedURLException, IOException
public Start() throws MalformedURLException, IOException
{
URL oUrl = new URL(urlString + "/" + dateiname);
InputStream iStream = oUrl.openStream();
BufferedInputStream in = new BufferedInputStream(iStream);
String tmpVerzeichnis = System.getProperty("java.io.tmpdir");
String ausgabeDateiname = tmpVerzeichnis + File.separator + dateiname;
FileOutputStream fos = new FileOutputStream(ausgabeDateiname);
BufferedOutputStream out = new BufferedOutputStream(fos);
// URL oUrl = new URL(urlString + "/" + dateiname);
// InputStream iStream = oUrl.openStream();
// BufferedInputStream in = new BufferedInputStream(iStream);
//
// String tmpVerzeichnis = System.getProperty("java.io.tmpdir");
// String ausgabeDateiname = tmpVerzeichnis + File.separator + dateiname;
//
// FileOutputStream fos = new FileOutputStream(ausgabeDateiname);
// BufferedOutputStream out = new BufferedOutputStream(fos);
//
// int wert = 0;
//
// while ( (wert = in.read()) >= 0)
// {
// out.write(wert);
// }
// in.close();
// out.close(); // flush!
// System.out.println("Datei " + ausgabeDateiname + " erfolgreich erstellt");
int wert = 0;
JFrame frm = new JFrame();
frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

ChatView view = new ChatView();
ChatModel model = new ChatModel();
while ( (wert = in.read()) >= 0)
{
out.write(wert);
}
in.close();
out.close(); // flush!
System.out.println("Datei " + ausgabeDateiname + " erfolgreich erstellt");
BtnController btncontroller = new BtnController(view, model);
ChatController chatcontroller = new ChatController(view, model);
btncontroller.registerEvents();
chatcontroller.registerEvents();
view.setSize(800, 600);
view.setVisible(true);
}

/**
* @param args the command line arguments
*/
public static void main(String[] args)
public static void main()
{
if (args.length != 2)
try
{
new Start();
}
catch (Exception ex)
{
System.err.println(ex);
ex.printStackTrace();
}
try
{
System.err.println("2 Aufrufparameter nötig: URL-String Dateiname");
new Start();
}
else
catch (Exception ex)
{
try
{
new Start(args[0], args[1]);
}
catch (Exception ex)
{
System.err.println(ex);
ex.printStackTrace();
}
System.err.println(ex);
ex.printStackTrace();
}
}
}

+ 50
- 0
src/netz/controller/BtnController.java View File

@@ -0,0 +1,50 @@
/*
* 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 netz.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Logger;
import netz.model.ChatModel;
import netz.view.ChatView;
import ohmlogger.OhmLogger;

/**
*
* @author chris
*/
public class BtnController implements ActionListener
{
private ChatView view;
private ChatModel model;
private static Logger lg = OhmLogger.getLogger();
/**
*
* @param view
* @param model
*/
public BtnController(ChatView view, ChatModel model)
{
this.view = view;
this.model = model;
}

public void registerEvents()
{
view.getBtnSetClient().addActionListener(this);
view.getBtnSetServer().addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent e)
{
}
}

+ 49
- 0
src/netz/controller/ChatController.java View File

@@ -0,0 +1,49 @@
/*
* 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 netz.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Logger;
import netz.model.ChatModel;
import netz.view.ChatView;
import ohmlogger.OhmLogger;

/**
*
* @author chris
*/
public class ChatController implements ActionListener
{
private ChatView view;
private ChatModel model;
private static Logger lg = OhmLogger.getLogger();
/**
*
* @param view
* @param model
*/
public ChatController(ChatView view, ChatModel model)
{
this.view = view;
this.model = model;
}

public void registerEvents()
{
view.getBtnSend().addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent e)
{
}
}

+ 19
- 0
src/netz/model/ChatModel.java View File

@@ -0,0 +1,19 @@
/*
* 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 netz.model;

/**
*
* @author chris
*/
public class ChatModel
{
public ChatModel()
{
}
}

+ 26
- 0
src/ohmlogger/MyFormatter.java View File

@@ -0,0 +1,26 @@
/*
* 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;
}
}

+ 54
- 0
src/ohmlogger/OhmLogger.java View File

@@ -0,0 +1,54 @@
/*
* 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);
}
}
}

Loading…
Cancel
Save