Conflicts: src/wuerfelthreads/Start.java src/wuerfelthreads/view/WuerfelView.form src/wuerfelthreads/view/WuerfelView.javamaster
@@ -6,11 +6,13 @@ | |||
package grafik; | |||
import grafik.logger.OhmLogger; | |||
import java.awt.BasicStroke; | |||
import java.awt.Color; | |||
import java.awt.Graphics; | |||
import java.awt.Graphics2D; | |||
import java.awt.RenderingHints; | |||
import java.awt.geom.AffineTransform; | |||
import java.awt.geom.Ellipse2D; | |||
import java.awt.geom.Line2D; | |||
import java.util.logging.Logger; | |||
@@ -29,7 +31,9 @@ public class Gerade extends JComponent implements Runnable | |||
private Thread thd; | |||
private long sleepTime; | |||
private static final float DICKE = 8f; | |||
private static Logger lg = Logger.getLogger("grafik"); | |||
private static Logger lg = OhmLogger.getLogger(); | |||
private float x1, x2, y1, y2; | |||
public Gerade(long sleepTime) | |||
{ | |||
@@ -39,14 +43,19 @@ public class Gerade extends JComponent implements Runnable | |||
radius = 100; | |||
pinsel = new BasicStroke(DICKE); | |||
thd = null; | |||
start(); | |||
} | |||
public void start() | |||
{ | |||
if (thd == null) | |||
{ | |||
lg.info("start"); | |||
thd = new Thread(this); | |||
thd.start(); | |||
} | |||
} | |||
@@ -63,14 +72,22 @@ public class Gerade extends JComponent implements Runnable | |||
int breite = this.getWidth() - 1; | |||
int hoehe = this.getHeight() - 1; | |||
float x1 = breite/2f; | |||
float y1 = hoehe/2f; | |||
float x2 = (float) Math.sin(angle); | |||
float y2 = 2; | |||
x1 = breite/2f; | |||
y1 = hoehe/2f; | |||
/** Rotate with Angle, sin and cos */ | |||
// x2 = (float) (radius * Math.cos((2 * Math.PI * angle) / 360) + x1); | |||
// y2 = (float) (radius * Math.sin((2 * Math.PI * angle) / 360) + y1); | |||
line.setLine(x1, y1, x2, y2); | |||
/** Rotate with transforms */ | |||
g2.translate(x1, y1); | |||
g2.rotate(Math.toRadians(angle)); | |||
g2.setStroke(pinsel); | |||
g2.setPaint(Color.RED); |
@@ -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 grafik.logger; | |||
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; | |||
} | |||
} |
@@ -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 grafik.logger; | |||
import grafik.logger.MyFormatter; | |||
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); | |||
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); | |||
} | |||
} | |||
} |