From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/TrustedApplet.java | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/TrustedApplet.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/TrustedApplet.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TrustedApplet.java b/Master/Reference Architectures and Patterns/hjp5/examples/TrustedApplet.java new file mode 100644 index 0000000..30f56a3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TrustedApplet.java @@ -0,0 +1,64 @@ +/* TrustedApplet.java */ + +import java.awt.*; +import java.applet.*; +import java.util.*; +import java.io.*; + +public class TrustedApplet +extends Applet +{ + static final String ALLOWED_DIR = "c:\\tmp\\applets\\"; + static final String FNAME = "TrustedApplet.log"; + static final String LOGMSG = "Erzeugt von Applet: "; + String msg; + + public void init() + { + msg = "Uninitialisiert"; + FileWriter out = null; + try { + //Ausgabedatei erzeugen + out = new FileWriter(ALLOWED_DIR + FNAME); + //Logmessage schreiben + out.write(LOGMSG); + //Zeitstempel schreiben + GregorianCalendar cal = new GregorianCalendar(); + out.write(cal.get(Calendar.DATE) + "."); + out.write((cal.get(Calendar.MONTH) + 1) + "."); + out.write(cal.get(Calendar.YEAR) + " "); + out.write(cal.get(Calendar.HOUR_OF_DAY) + ":"); + out.write(cal.get(Calendar.MINUTE) + ":"); + out.write(cal.get(Calendar.SECOND) + ""); + out.write(System.getProperty("line.separator")); + //System-Properties lesen und in Datei schreiben + out.write(getProp("user.name")); + out.write(getProp("user.home")); + out.write(getProp("user.dir")); + //Datei schließen + msg = "Alle Sicherheitshuerden ueberwunden!"; + } catch (Exception e) { + msg = e.toString(); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + //silently ignore + } + } + } + } + + public void paint(Graphics g) + { + g.drawString(msg, 20, 20); + } + + private String getProp(String prop) + { + return prop + "=" + + System.getProperty(prop) + + System.getProperty("line.separator"); + } +} \ No newline at end of file -- cgit v1.2.3