Merge origin/master
Conflicts: src/wuerfelthreads/Start.java src/wuerfelthreads/view/WuerfelView.form src/wuerfelthreads/view/WuerfelView.java
This commit is contained in:
parent
d94d366315
commit
ea7e96b32c
@ -15,6 +15,7 @@ import java.io.OutputStreamWriter;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import ohmlogger.OhmLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder Class
|
* Builder Class
|
||||||
@ -22,7 +23,7 @@ import java.util.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
public class Client
|
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 int PORT = 35000;
|
||||||
private static final String IP_ADRESSE = "127.0.0.1";
|
private static final String IP_ADRESSE = "127.0.0.1";
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import java.io.PrintWriter;
|
|||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import ohmlogger.OhmLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder Class
|
* Builder Class
|
||||||
@ -23,7 +24,7 @@ import java.util.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
public class Server
|
public class Server
|
||||||
{
|
{
|
||||||
private static final Logger lg = Logger.getLogger("netz");
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
private static final int PORT = 35000;
|
private static final int PORT = 35000;
|
||||||
|
|
||||||
public Server() throws IOException
|
public Server() throws IOException
|
||||||
|
@ -6,14 +6,16 @@
|
|||||||
|
|
||||||
package netz;
|
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.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
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
|
* Builder Class
|
||||||
@ -21,50 +23,63 @@ import java.net.URL;
|
|||||||
*/
|
*/
|
||||||
public class Start
|
public class Start
|
||||||
{
|
{
|
||||||
public Start(String urlString, String dateiname) throws MalformedURLException, IOException
|
public Start() throws MalformedURLException, IOException
|
||||||
{
|
{
|
||||||
URL oUrl = new URL(urlString + "/" + dateiname);
|
// URL oUrl = new URL(urlString + "/" + dateiname);
|
||||||
InputStream iStream = oUrl.openStream();
|
// InputStream iStream = oUrl.openStream();
|
||||||
BufferedInputStream in = new BufferedInputStream(iStream);
|
// 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");
|
||||||
|
|
||||||
String tmpVerzeichnis = System.getProperty("java.io.tmpdir");
|
JFrame frm = new JFrame();
|
||||||
String ausgabeDateiname = tmpVerzeichnis + File.separator + dateiname;
|
frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
FileOutputStream fos = new FileOutputStream(ausgabeDateiname);
|
ChatView view = new ChatView();
|
||||||
BufferedOutputStream out = new BufferedOutputStream(fos);
|
ChatModel model = new ChatModel();
|
||||||
|
|
||||||
int wert = 0;
|
BtnController btncontroller = new BtnController(view, model);
|
||||||
|
ChatController chatcontroller = new ChatController(view, model);
|
||||||
|
btncontroller.registerEvents();
|
||||||
|
chatcontroller.registerEvents();
|
||||||
|
|
||||||
while ( (wert = in.read()) >= 0)
|
view.setSize(800, 600);
|
||||||
{
|
view.setVisible(true);
|
||||||
out.write(wert);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
out.close(); // flush!
|
|
||||||
System.out.println("Datei " + ausgabeDateiname + " erfolgreich erstellt");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static void main()
|
||||||
* @param args the command line arguments
|
|
||||||
*/
|
|
||||||
public static void main(String[] args)
|
|
||||||
{
|
{
|
||||||
if (args.length != 2)
|
try
|
||||||
{
|
{
|
||||||
System.err.println("2 Aufrufparameter nötig: URL-String Dateiname");
|
new Start();
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
try
|
System.err.println(ex);
|
||||||
{
|
ex.printStackTrace();
|
||||||
new Start(args[0], args[1]);
|
}
|
||||||
}
|
try
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
new Start();
|
||||||
System.err.println(ex);
|
}
|
||||||
ex.printStackTrace();
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
|
System.err.println(ex);
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
50
src/netz/controller/BtnController.java
Normal file
50
src/netz/controller/BtnController.java
Normal 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
src/netz/controller/ChatController.java
Normal file
49
src/netz/controller/ChatController.java
Normal 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
src/netz/model/ChatModel.java
Normal file
19
src/netz/model/ChatModel.java
Normal 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
src/ohmlogger/MyFormatter.java
Normal file
26
src/ohmlogger/MyFormatter.java
Normal 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
src/ohmlogger/OhmLogger.java
Normal file
54
src/ohmlogger/OhmLogger.java
Normal 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…
x
Reference in New Issue
Block a user