Conflicts: src/wuerfelthreads/Start.java src/wuerfelthreads/view/WuerfelView.form src/wuerfelthreads/view/WuerfelView.javamaster
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 | ||||
*/ | */ | ||||
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"; | ||||
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 | ||||
*/ | */ | ||||
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 |
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 | ||||
*/ | */ | ||||
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); | |||||
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(); | |||||
} | } | ||||
} | } | ||||
} | } |
/* | |||||
* 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) | |||||
{ | |||||
} | |||||
} |
/* | |||||
* 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) | |||||
{ | |||||
} | |||||
} |
/* | |||||
* 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() | |||||
{ | |||||
} | |||||
} |
/* | |||||
* 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; | |||||
} | |||||
} |
/* | |||||
* 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); | |||||
} | |||||
} | |||||
} |