diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples | |
| download | Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples')
430 files changed, 16093 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/AssertionTest.java b/Master/Reference Architectures and Patterns/hjp5/examples/AssertionTest.java new file mode 100644 index 0000000..1ac1344 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/AssertionTest.java @@ -0,0 +1,13 @@ +/* AssertionTest.java */
+
+public class AssertionTest
+{
+ public static void main(String[] args)
+ {
+ assert args.length >= 2;
+ int i1 = Integer.parseInt(args[0]);
+ int i2 = Integer.parseInt(args[1]);
+ assert i2 != 0 : "Teilen durch 0 nicht moeglich";
+ System.out.println(i1 + "/" + i2 + "=" + (i1/i2));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Auto.java b/Master/Reference Architectures and Patterns/hjp5/examples/Auto.java new file mode 100644 index 0000000..f11bc2e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Auto.java @@ -0,0 +1,8 @@ +/* Auto.java */
+
+public class Auto
+{
+ public String name;
+ public int erstzulassung;
+ public int leistung;
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Auto2.java b/Master/Reference Architectures and Patterns/hjp5/examples/Auto2.java new file mode 100644 index 0000000..d9f5421 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Auto2.java @@ -0,0 +1,27 @@ +/* Auto2.java */
+
+public class Auto2
+implements Groesse
+{
+ public String name;
+ public int erstzulassung;
+ public int leistung;
+ public int laenge;
+ public int hoehe;
+ public int breite;
+
+ public int laenge()
+ {
+ return this.laenge;
+ }
+
+ public int hoehe()
+ {
+ return this.hoehe;
+ }
+
+ public int breite()
+ {
+ return this.breite;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Auto3.java b/Master/Reference Architectures and Patterns/hjp5/examples/Auto3.java new file mode 100644 index 0000000..6a69a07 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Auto3.java @@ -0,0 +1,38 @@ +/* Auto3.java */
+
+public class Auto3
+implements Groesse, Comparable
+{
+ public String name;
+ public int erstzulassung;
+ public int leistung;
+ public int laenge;
+ public int hoehe;
+ public int breite;
+
+ public int laenge()
+ {
+ return this.laenge;
+ }
+
+ public int hoehe()
+ {
+ return this.hoehe;
+ }
+
+ public int breite()
+ {
+ return this.breite;
+ }
+
+ public int compareTo(Object o)
+ {
+ int ret = 0;
+ if (leistung < ((Auto3)o).leistung) {
+ ret = -1;
+ } else if (leistung > ((Auto3)o).leistung) {
+ ret = 1;
+ }
+ return ret;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Auto4.java b/Master/Reference Architectures and Patterns/hjp5/examples/Auto4.java new file mode 100644 index 0000000..013c972 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Auto4.java @@ -0,0 +1,17 @@ +/* Auto4.java */
+
+public class Auto4
+extends Auto2
+implements Comparable
+{
+ public int compareTo(Object o)
+ {
+ int ret = 0;
+ if (leistung < ((Auto4)o).leistung) {
+ ret = -1;
+ } else if (leistung > ((Auto4)o).leistung) {
+ ret = 1;
+ }
+ return ret;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Auto5.java b/Master/Reference Architectures and Patterns/hjp5/examples/Auto5.java new file mode 100644 index 0000000..75a6d32 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Auto5.java @@ -0,0 +1,31 @@ +/* Auto5.java */
+
+public class Auto5
+implements SimpleTreeNode
+{
+ public String name;
+ public int erstzulassung;
+ public int leistung;
+
+ private SimpleTreeNode treenode = new DefaultTreeNode("");
+
+ public void addChild(SimpleTreeNode child)
+ {
+ treenode.addChild(child);
+ }
+
+ public int getChildCnt()
+ {
+ return treenode.getChildCnt();
+ }
+
+ public SimpleTreeNode getChild(int pos)
+ {
+ return treenode.getChild(pos);
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/BinTreeNode.java b/Master/Reference Architectures and Patterns/hjp5/examples/BinTreeNode.java new file mode 100644 index 0000000..7903ef1 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/BinTreeNode.java @@ -0,0 +1,33 @@ +/* BinTreeNode.java */
+
+class BinTreeNode
+implements Cloneable
+{
+ String name;
+ BinTreeNode leftChild;
+ BinTreeNode rightChild;
+
+ public BinTreeNode(String name)
+ {
+ this.name = name;
+ this.leftChild = null;
+ this.rightChild = null;
+ }
+
+ public Object clone()
+ {
+ try {
+ BinTreeNode newNode = (BinTreeNode)super.clone();
+ if (this.leftChild != null) {
+ newNode.leftChild = (BinTreeNode)this.leftChild.clone();
+ }
+ if (this.rightChild != null) {
+ newNode.rightChild = (BinTreeNode)this.rightChild.clone();
+ }
+ return newNode;
+ } catch (CloneNotSupportedException e) {
+ //Kann eigentlich nicht auftreten...
+ throw new InternalError();
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/BitmapComponent.java b/Master/Reference Architectures and Patterns/hjp5/examples/BitmapComponent.java new file mode 100644 index 0000000..fe767e0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/BitmapComponent.java @@ -0,0 +1,45 @@ +/* BitmapComponent.java */
+
+import java.awt.*;
+
+class BitmapComponent
+extends Canvas
+{
+ private Image img;
+
+ public BitmapComponent(String fname)
+ {
+ img = getToolkit().getImage(fname);
+ MediaTracker mt = new MediaTracker(this);
+
+ mt.addImage(img, 0);
+ try {
+ //Warten, bis das Image vollständig geladen ist,
+ //damit getWidth() und getHeight() funktionieren
+ mt.waitForAll();
+ } catch (InterruptedException e) {
+ //nothing
+ }
+ }
+
+ public void paint(Graphics g)
+ {
+ g.drawImage(img,1,1,this);
+ }
+
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(
+ img.getWidth(this),
+ img.getHeight(this)
+ );
+ }
+
+ public Dimension getMinimumSize()
+ {
+ return new Dimension(
+ img.getWidth(this),
+ img.getHeight(this)
+ );
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/ButtonPanel.java b/Master/Reference Architectures and Patterns/hjp5/examples/ButtonPanel.java new file mode 100644 index 0000000..2125aca --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/ButtonPanel.java @@ -0,0 +1,154 @@ +/* ButtonPanel.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+import java.io.*;
+
+public class ButtonPanel
+extends Panel
+implements Serializable, ItemListener
+{
+ //---Instanzvariablen------------------------------------
+ protected CheckboxGroup cbg;
+ protected Checkbox[] cb;
+ transient protected PropertyChangeSupport pcs;
+
+ //---Methoden--------------------------------------------
+ public ButtonPanel()
+ {
+ cbg = new CheckboxGroup();
+ cb = new Checkbox[0];
+ initTransientState();
+ }
+
+ //---Anzahl der RadioButtons-----------------------------
+ public void setButtonCnt(int cnt)
+ {
+ if (cnt != cb.length) {
+ int oldvalue = cb.length;
+ //Bisherige Buttons entfernen
+ if (cb.length > 0) {
+ removeAll();
+ }
+ cb = new Checkbox[cnt];
+ setLayout(new GridLayout(cnt, 1));
+ for (int i = 0; i < cnt; ++i) {
+ cb[i] = new Checkbox(
+ "RadioButton " + i,
+ cbg,
+ (i == 0 ? true : false)
+ );
+ cb[i].addItemListener(this);
+ add(cb[i]);
+ }
+ //PropertyChangeEvents senden
+ pcs.firePropertyChange("buttonCnt", oldvalue, cnt);
+ if (cnt > 0) {
+ setSelected(0);
+ }
+ //Neu layouten
+ setSize(getPreferredSize());
+ invalidate();
+ doLayout();
+ Container owner = getParent();
+ if (owner != null) {
+ owner.invalidate();
+ owner.doLayout();
+ }
+ }
+ }
+
+ public int getButtonCnt()
+ {
+ return cb.length;
+ }
+
+ //---Beschriftung der Buttons----------------------------
+ public void setLabel(int index, String label)
+ {
+ if (index >= 0 && index < cb.length) {
+ cb[index].setLabel(label);
+ }
+ }
+
+ public String getLabel(int index)
+ {
+ String ret = "***invalid index***";
+ if (index >= 0 && index < cb.length) {
+ ret = cb[index].getLabel();
+ }
+ return ret;
+ }
+
+ //---Selektiertes Element--------------------------------
+ public void setSelected(int index)
+ {
+ if (index >= 0 && index < cb.length) {
+ int oldvalue = getSelected();
+ cb[index].setState(true);
+ pcs.firePropertyChange("selected", oldvalue, index);
+ }
+ }
+
+ public int getSelected()
+ {
+ int ret = -1;
+ for (int i = 0; i < cb.length; ++i) {
+ if (cb[i].getState()) {
+ ret = i;
+ break;
+ }
+ }
+ return ret;
+ }
+
+ //---Verwaltung der PropertyChangeListener---
+ public void addPropertyChangeListener(
+ PropertyChangeListener l
+ )
+ {
+ pcs.addPropertyChangeListener(l);
+ }
+
+ public void removePropertyChangeListener(
+ PropertyChangeListener l
+ )
+ {
+ pcs.removePropertyChangeListener(l);
+ }
+
+ //---Reaktion auf Zustandsänderungen---------------------
+ public void itemStateChanged(ItemEvent event)
+ {
+ Checkbox changedcb = (Checkbox) event.getItemSelectable();
+ if (changedcb.getState()) {
+ for (int i = 0; i < cb.length; ++i) {
+ if (cb[i] == changedcb) {
+ pcs.firePropertyChange("selected", -1, i);
+ break;
+ }
+ }
+ }
+ }
+
+ //---Private Methoden------------------------------------
+ /**
+ * Initialisierung der nicht-persistenten Instanzvariablen.
+ */
+ private void initTransientState()
+ {
+ pcs = new PropertyChangeSupport(this);
+ }
+
+ /**
+ * Wird überlagert, um nach dem Deserialisieren den transienten
+ * Zustand zu initialisieren.
+ */
+ private void readObject(ObjectInputStream stream)
+ throws IOException, ClassNotFoundException
+ {
+ stream.defaultReadObject();
+ initTransientState();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/ByteKit.java b/Master/Reference Architectures and Patterns/hjp5/examples/ByteKit.java new file mode 100644 index 0000000..778a7d8 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/ByteKit.java @@ -0,0 +1,56 @@ +/**
+ * ByteKit
+ *
+ * Einfache Klasse zur Umwandlung zwischen int, char und
+ * vorzeichenlosen Bytes.
+ */
+public class ByteKit
+{
+ /**
+ * Wandelt value (0 <= value <= 255) in ein byte um.
+ */
+ public static byte fromUnsignedInt(int value)
+ {
+ return (byte)value;
+ }
+
+ /**
+ * Wandelt c in ein byte um. Das High-Byte wird ignoriert.
+ */
+ public static byte fromChar(char c)
+ {
+ return (byte)(c & 0xFF);
+ }
+
+ /**
+ * Betrachtet value als vorzeichenloses byte und wandelt
+ * es in eine Ganzzahl im Bereich 0..255 um.
+ */
+ public static int toUnsignedInt(byte value)
+ {
+ return (value & 0x7F) + (value < 0 ? 128 : 0);
+ }
+
+ /**
+ * Betrachtet value als vorzeichenloses byte und wandelt
+ * es in ein Unicode-Zeichen mit High-Byte 0 um.
+ */
+ public static char toChar(byte value)
+ {
+ return (char)toUnsignedInt(value);
+ }
+
+ /**
+ * Liefert die Binaerdarstellung von value.
+ */
+ public static String toBitString(byte value)
+ {
+ char[] chars = new char[8];
+ int mask = 1;
+ for (int i = 0; i < 8; ++i) {
+ chars[7 - i] = (value & mask) != 0 ? '1' : '0';
+ mask <<= 1;
+ }
+ return new String(chars);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/CachedConnection.java b/Master/Reference Architectures and Patterns/hjp5/examples/CachedConnection.java new file mode 100644 index 0000000..4493adb --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/CachedConnection.java @@ -0,0 +1,33 @@ +/* CachedConnection.java */
+
+import java.sql.*;
+import java.util.*;
+
+public class CachedConnection
+{
+ private Connection con;
+ private LinkedList<Statement> cache;
+ private int stmtcnt;
+
+ public CachedConnection(Connection con)
+ {
+ this.con = con;
+ this.cache = new LinkedList<Statement>();
+ this.stmtcnt = 0;
+ }
+
+ public Statement getStatement()
+ throws SQLException
+ {
+ if (cache.size() <= 0) {
+ return con.createStatement();
+ } else {
+ return cache.poll();
+ }
+ }
+
+ public void releaseStatement(Statement statement)
+ {
+ cache.add(statement);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Calculator.java b/Master/Reference Architectures and Patterns/hjp5/examples/Calculator.java new file mode 100644 index 0000000..f23f923 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Calculator.java @@ -0,0 +1,44 @@ +/* Calculator.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Calculator
+extends Frame
+implements ActionListener
+{
+ private TextField tf;
+
+ public Calculator()
+ {
+ super("Calculator");
+ addWindowListener(new WindowClosingAdapter(true));
+ setBackground(Color.lightGray);
+ setLayout(new GridLayout(2, 1));
+ tf = new TextField("777");
+ add(tf);
+ Panel p = new Panel();
+ for (int i = 1; i <= 1000; i *= 10) {
+ Button b = new Button("+" + i);
+ b.addActionListener(this);
+ p.add(b);
+ }
+ add(p);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ int n1 = Integer.parseInt(tf.getText());
+ int n2 = Integer.parseInt(cmd.substring(1));
+ tf.setText("" + (n1 + n2));
+ }
+
+ public static void main(String[] args)
+ {
+ Calculator calc = new Calculator();
+ calc.setLocation(100, 100);
+ calc.setSize(200, 85);
+ calc.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet1.html b/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet1.html new file mode 100644 index 0000000..a9c203a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet1.html @@ -0,0 +1,14 @@ +<html>
+<head>
+<title>CalculatorApplet1</title>
+</head>
+<body>
+
+<h1>CalculatorApplet1</h1>
+
+<applet code="CalculatorApplet1.class" width=200 height=100>
+CalculatorApplet1
+</applet>
+
+</body>
+</html>
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet1.java b/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet1.java new file mode 100644 index 0000000..86a689c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet1.java @@ -0,0 +1,27 @@ +/* CalculatorApplet1.java */
+
+import java.awt.*;
+import java.applet.*;
+
+public class CalculatorApplet1
+extends Applet
+{
+ Calculator calc;
+
+ public void init()
+ {
+ calc = new Calculator();
+ calc.setLocation(100, 100);
+ calc.setSize(200, 130);
+ }
+
+ public void start()
+ {
+ calc.setVisible(true);
+ }
+
+ public void stop()
+ {
+ calc.setVisible(false);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet2.html b/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet2.html new file mode 100644 index 0000000..77755cd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet2.html @@ -0,0 +1,14 @@ +<html>
+<head>
+<title>CalculatorApplet2</title>
+</head>
+<body>
+
+<h1>CalculatorApplet2</h1>
+
+<applet code="CalculatorApplet2.class" width=200 height=85>
+CalculatorApplet2
+</applet>
+
+</body>
+</html>
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet2.java b/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet2.java new file mode 100644 index 0000000..83aca15 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/CalculatorApplet2.java @@ -0,0 +1,35 @@ +/* CalculatorApplet2.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.applet.*;
+
+public class CalculatorApplet2
+extends Applet
+implements ActionListener
+{
+ private TextField tf;
+
+ public void init()
+ {
+ setBackground(Color.lightGray);
+ setLayout(new GridLayout(2, 1));
+ tf = new TextField("777");
+ add(tf);
+ Panel p = new Panel();
+ for (int i = 1; i <= 1000; i *= 10) {
+ Button b = new Button("+" + i);
+ b.addActionListener(this);
+ p.add(b);
+ }
+ add(p);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ int n1 = Integer.parseInt(tf.getText());
+ int n2 = Integer.parseInt(cmd.substring(1));
+ tf.setText("" + (n1 + n2));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/CancelButton.java b/Master/Reference Architectures and Patterns/hjp5/examples/CancelButton.java new file mode 100644 index 0000000..8ce77cf --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/CancelButton.java @@ -0,0 +1,29 @@ +/* CancelButton.java */
+
+import java.awt.event.*;
+import javax.swing.*;
+
+public class CancelButton
+extends JButton
+{
+ public CancelButton(String title)
+ {
+ super(title);
+ ActionListener al = new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("PressedESCAPE")) {
+ doClick();
+ }
+ }
+ };
+ registerKeyboardAction(
+ al,
+ "PressedESCAPE",
+ KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
+ JButton.WHEN_IN_FOCUSED_WINDOW
+ );
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Checkbox1.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Checkbox1.inc new file mode 100644 index 0000000..904f227 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Checkbox1.inc @@ -0,0 +1,15 @@ +/* Checkbox1.inc */
+
+private void customizeLayout(Panel panel)
+{
+ panel.setLayout(new GridLayout(3,1));
+ Checkbox cb = new Checkbox("Checkbox 1");
+ cb.addItemListener(this);
+ panel.add(cb);
+ cb = new Checkbox("Checkbox 2", true);
+ cb.addItemListener(this);
+ panel.add(cb);
+ cb = new Checkbox("Checkbox 3", false);
+ cb.addItemListener(this);
+ panel.add(cb);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Checkbox2.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Checkbox2.inc new file mode 100644 index 0000000..12d023f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Checkbox2.inc @@ -0,0 +1,7 @@ +/* Checkbox2.inc */
+
+public void itemStateChanged(ItemEvent event)
+{
+ Checkbox cb = (Checkbox) event.getItemSelectable();
+ System.out.println(cb.getLabel() + ": " + cb.getState());
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/CheckboxGroup.inc b/Master/Reference Architectures and Patterns/hjp5/examples/CheckboxGroup.inc new file mode 100644 index 0000000..3f02953 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/CheckboxGroup.inc @@ -0,0 +1,14 @@ +/* CheckboxGroup.inc */
+
+private void customizeLayout(Panel panel)
+{
+ panel.setLayout(new GridLayout(3,2));
+ CheckboxGroup cbg1 = new CheckboxGroup();
+ CheckboxGroup cbg2 = new CheckboxGroup();
+ panel.add(new Checkbox("rot",cbg1,true));
+ panel.add(new Checkbox("eckig",cbg2,true));
+ panel.add(new Checkbox("blau",cbg1,false));
+ panel.add(new Checkbox("rund",cbg2,false));
+ panel.add(new Checkbox("gelb",cbg1,false));
+ panel.add(new Checkbox("schief",cbg2,false));
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/ChgNextApplet.java b/Master/Reference Architectures and Patterns/hjp5/examples/ChgNextApplet.java new file mode 100644 index 0000000..5098369 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/ChgNextApplet.java @@ -0,0 +1,41 @@ +/* ChgNextApplet.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.applet.*;
+import java.util.*;
+
+public class ChgNextApplet
+extends Applet
+{
+ private String next;
+
+ public void init()
+ {
+ next = getParameter("next");
+ setBackground(Color.red);
+ addMouseListener(
+ new MouseAdapter()
+ {
+ public void mouseClicked(MouseEvent event)
+ {
+ if (next != null) {
+ Applet applet = getAppletContext().getApplet(next);
+ if (applet != null) {
+ int red = (int)(Math.random() * 256);
+ int green = (int)(Math.random() * 256);
+ int blue = (int)(Math.random() * 256);
+ applet.setBackground(new Color(red, green, blue));
+ applet.repaint();
+ }
+ }
+ }
+ }
+ );
+ }
+
+ public void paint(Graphics g)
+ {
+ g.drawString("Change " + next, 5, 20);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Choice1.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Choice1.inc new file mode 100644 index 0000000..3be2ed4 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Choice1.inc @@ -0,0 +1,15 @@ +/* Choice1.inc */
+
+private void customizeLayout(Panel panel)
+{
+ panel.setLayout(new FlowLayout());
+ Choice choice = new Choice();
+ choice.addItemListener(this);
+ choice.add("rot");
+ choice.add("grün");
+ choice.add("gelb");
+ choice.add("blau");
+ choice.add("rosa");
+ choice.add("lila");
+ panel.add(choice);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Choice2.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Choice2.inc new file mode 100644 index 0000000..4609ca7 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Choice2.inc @@ -0,0 +1,10 @@ +/* Choice2.inc */
+
+public void itemStateChanged(ItemEvent event)
+{
+ Choice choice = (Choice) event.getItemSelectable();
+ String str1 = choice.getSelectedItem();
+ String str2 = (String) event.getItem();
+ System.out.println("choice.getSelectedItem: " + str1);
+ System.out.println("event.getItem: " + str2);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Clipping.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Clipping.inc new file mode 100644 index 0000000..85e6f36 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Clipping.inc @@ -0,0 +1,20 @@ +/* Clipping.inc */
+
+public void paint(Graphics g)
+{
+ int[] arx = {150,175,200,150};
+ int[] ary = {100,150,100,100};
+
+ g.setClip(50,50,150,80);
+ //---J
+ g.fillRect(70,40,20,80);
+ g.fillArc(30,90,60,60,225,180);
+ //---a
+ g.fillOval(100,100,40,50);
+ g.fillRect(120,100,20,50);
+ //---v
+ g.fillPolygon(arx,ary,arx.length);
+ //---a
+ g.fillOval(210,100,40,50);
+ g.fillRect(230,100,20,50);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/ColoredTableCellRenderer.java b/Master/Reference Architectures and Patterns/hjp5/examples/ColoredTableCellRenderer.java new file mode 100644 index 0000000..9249dbf --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/ColoredTableCellRenderer.java @@ -0,0 +1,52 @@ +/* ColoredTableCellRenderer.java */
+
+import java.awt.*;
+import javax.swing.*;
+import javax.swing.border.*;
+import javax.swing.table.*;
+
+public class ColoredTableCellRenderer
+implements TableCellRenderer
+{
+ private Color lightBlue = new Color(160, 160, 255);
+ private Color darkBlue = new Color( 64, 64, 128);
+
+ public Component getTableCellRendererComponent(
+ JTable table,
+ Object value,
+ boolean isSelected,
+ boolean hasFocus,
+ int row,
+ int column
+ )
+ {
+ //Label erzeugen
+ JLabel label = new JLabel((String)value);
+ label.setOpaque(true);
+ Border b = BorderFactory.createEmptyBorder(1, 1, 1, 1);
+ label.setBorder(b);
+ label.setFont(table.getFont());
+ label.setForeground(table.getForeground());
+ label.setBackground(table.getBackground());
+ if (hasFocus) {
+ label.setBackground(darkBlue);
+ label.setForeground(Color.white);
+ } else if (isSelected) {
+ label.setBackground(lightBlue);
+ } else {
+ //Angezeigte Spalte in Modellspalte umwandeln
+ column = table.convertColumnIndexToModel(column);
+ if (column == 1) {
+ int numpages = Integer.parseInt((String)value);
+ if (numpages >= 250) {
+ label.setBackground(Color.red);
+ } else if (numpages >= 200) {
+ label.setBackground(Color.orange);
+ } else {
+ label.setBackground(Color.yellow);
+ }
+ }
+ }
+ return label;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DefaultButton.java b/Master/Reference Architectures and Patterns/hjp5/examples/DefaultButton.java new file mode 100644 index 0000000..ca15058 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/DefaultButton.java @@ -0,0 +1,13 @@ +/* DefaultButton.java */
+
+import javax.swing.*;
+
+public class DefaultButton
+extends JButton
+{
+ public DefaultButton(String title, JRootPane rootpane)
+ {
+ super(title);
+ rootpane.setDefaultButton(this);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DefaultTreeNode.java b/Master/Reference Architectures and Patterns/hjp5/examples/DefaultTreeNode.java new file mode 100644 index 0000000..9d3764d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/DefaultTreeNode.java @@ -0,0 +1,46 @@ +/* DefaultTreeNode.java */
+
+public class DefaultTreeNode
+implements SimpleTreeNode
+{
+ private int CAPACITY;
+ private String name;
+ private SimpleTreeNode[] childs;
+ private int childcnt;
+
+ public DefaultTreeNode(String name)
+ {
+ this.CAPACITY = 5;
+ this.name = name;
+ this.childs = new SimpleTreeNode[CAPACITY];
+ this.childcnt = 0;
+ }
+
+ public void addChild(SimpleTreeNode child)
+ {
+ if (childcnt >= CAPACITY) {
+ CAPACITY *= 2;
+ SimpleTreeNode[] newchilds = new SimpleTreeNode[CAPACITY];
+ for (int i = 0; i < childcnt; ++i) {
+ newchilds[i] = childs[i];
+ }
+ childs = newchilds;
+ }
+ childs[childcnt++] = child;
+ }
+
+ public int getChildCnt()
+ {
+ return childcnt;
+ }
+
+ public SimpleTreeNode getChild(int pos)
+ {
+ return childs[pos];
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DialogBeispiel.java b/Master/Reference Architectures and Patterns/hjp5/examples/DialogBeispiel.java new file mode 100644 index 0000000..94afe8c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/DialogBeispiel.java @@ -0,0 +1,98 @@ +/* DialogBeispiel.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+class MyDialog
+extends Dialog
+implements ActionListener
+{
+ public MyDialog(Frame parent)
+ {
+ super(parent,"MyDialog",true);
+ Point parloc = parent.getLocation();
+ setBounds(parloc.x + 30, parloc.y + 30,400,300);
+ setBackground(Color.lightGray);
+ setLayout(new BorderLayout());
+ //Panel
+ Panel panel = new Panel();
+ customizeLayout(panel);
+ add(panel, BorderLayout.CENTER);
+ //Ende-Button
+ Button button = new Button("Ende");
+ button.addActionListener(this);
+ add(button, BorderLayout.SOUTH);
+ //Window-Listener
+ addWindowListener(
+ new WindowAdapter() {
+ public void windowClosing(WindowEvent event)
+ {
+ endDialog();
+ }
+ }
+ );
+ pack();
+ }
+
+ private void customizeLayout(Panel panel)
+ {
+ //Beispielcode hier
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ if (event.getActionCommand().equals("Ende")) {
+ endDialog();
+ }
+ }
+
+ void endDialog()
+ {
+ setVisible(false);
+ dispose();
+ ((Window)getParent()).toFront();
+ getParent().requestFocus();
+ }
+}
+
+public class DialogBeispiel
+extends Frame
+implements ActionListener
+{
+ public static void main(String[] args)
+ {
+ DialogBeispiel wnd = new DialogBeispiel();
+ wnd.setSize(300,200);
+ wnd.setVisible(true);
+ }
+
+ public DialogBeispiel()
+ {
+ super("Beispiel Dialogelemente");
+ setBackground(Color.lightGray);
+ setLayout(new FlowLayout());
+ //Dialog-Button
+ Button button = new Button("Dialog");
+ button.addActionListener(this);
+ add(button);
+ //Ende-Button
+ button = new Button("Ende");
+ button.addActionListener(this);
+ add(button);
+ //Window-Listener
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("Dialog")) {
+ MyDialog dlg = new MyDialog(this);
+ dlg.setVisible(true);
+ } else if (cmd.equals("Ende")) {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DigitalSignature.java b/Master/Reference Architectures and Patterns/hjp5/examples/DigitalSignature.java new file mode 100644 index 0000000..7a7b809 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/DigitalSignature.java @@ -0,0 +1,47 @@ +/* DigitalSignature.java */
+
+import java.io.*;
+import java.security.cert.Certificate;
+import java.security.*;
+
+public class DigitalSignature
+{
+ static final String KEYSTORE = "c:\\windows\\.keystore";
+ static final char[] KSPASS = {'h','j','p','3','k','s'};
+ static final String ALIAS = "hjp3";
+ static final char[] KEYPASS = {'h','j','p','3','k','e','y'};
+
+ public static void main(String[] args)
+ {
+ try {
+ //Laden der Schlüsseldatenbank
+ KeyStore ks = KeyStore.getInstance("JKS");
+ FileInputStream ksin = new FileInputStream(KEYSTORE);
+ ks.load(ksin, KSPASS);
+ ksin.close();
+ //Privaten Schlüssel "hjp3" lesen
+ Key key = ks.getKey(ALIAS, KEYPASS);
+ //Signatur-Objekt erstellen
+ Signature signature = Signature.getInstance("SHA/DSA");
+ signature.initSign((PrivateKey)key);
+ //Eingabedatei einlesen
+ FileInputStream in = new FileInputStream(args[0]);
+ int len;
+ byte[] data = new byte[1024];
+ while ((len = in.read(data)) > 0) {
+ //Signatur updaten
+ signature.update(data, 0, len);
+ }
+ in.close();
+ //Signatur berechnen
+ byte[] result = signature.sign();
+ //Signatur ausgeben
+ FileOutputStream out = new FileOutputStream(args[1]);
+ out.write(result, 0, result.length);
+ out.close();
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DirDB.java b/Master/Reference Architectures and Patterns/hjp5/examples/DirDB.java new file mode 100644 index 0000000..cd22d1c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/DirDB.java @@ -0,0 +1,421 @@ +/*
+ * File........: c:/arc/prog/java/misc/dbtest/DirDB.java
+ * Package.....: Default
+ * Created.....: 98/10/02, Guido Krueger
+ * RCS.........: $Revision$
+ * $Date$ $Author$
+ *
+ * Copyright (c) 1998 Guido Krueger. All Rights Reserved.
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for NON-COMMERCIAL purposes
+ * and without fee is hereby granted provided that this
+ * copyright notice appears in all copies.
+ *
+ * THE AUTHOR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
+ * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ * NON-INFRINGEMENT. THE AUTHOR SHALL NOT BE LIABLE FOR ANY
+ * DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
+ * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
+ */
+import java.util.*;
+import java.io.*;
+import java.sql.*;
+import java.text.*;
+import gk.util.*;
+
+public class DirDB
+{
+ //---Constants-----------------------------------------------
+ static int INSTANT185 = 1;
+ static int ACCESS95 = 2;
+ static int HSQLDB = 3;
+
+ //---Pseudo constants----------------------------------------
+ static String FILESEP = System.getProperty("file.separator");
+
+ //---Static Variables----------------------------------------
+ static int db = INSTANT185;
+ static Connection con;
+ static Statement stmt;
+ static Statement stmt1;
+ static DatabaseMetaData dmd;
+ static int nextdid = 1;
+ static int nextfid = 1;
+
+ /**
+ * Öffnet die Datenbank.
+ */
+ public static void open()
+ throws Exception
+ {
+ //Treiber laden und Connection erzeugen
+ if (db == INSTANT185) {
+ Class.forName("jdbc.idbDriver");
+ con = DriverManager.getConnection(
+ "jdbc:idb=dirdb.prp",
+ new Properties()
+ );
+ } else if (db == HSQLDB) {
+ Class.forName("org.hsqldb.jdbcDriver");
+ con = DriverManager.getConnection(
+ "jdbc:hsqldb:hsqldbtest",
+ "SA",
+ ""
+ );
+ } else {
+ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
+ con = DriverManager.getConnection("jdbc:odbc:DirDB");
+ }
+ //Metadaten ausgeben
+ dmd = con.getMetaData();
+ System.out.println("");
+ System.out.println("Connection URL: " + dmd.getURL());
+ System.out.println("Driver Name: " + dmd.getDriverName());
+ System.out.println("Driver Version: " + dmd.getDriverVersion());
+ System.out.println("");
+ //Statementobjekte erzeugen
+ stmt = con.createStatement();
+ stmt1 = con.createStatement();
+ }
+
+ /**
+ * Legt die Tabellen an.
+ */
+ public static void createTables()
+ throws SQLException
+ {
+ //Anlegen der Tabelle dir
+ try {
+ stmt.executeUpdate("DROP TABLE dir");
+ } catch (SQLException e) {
+ //Nichts zu tun
+ }
+ stmt.executeUpdate("CREATE TABLE dir (" +
+ "did INT," +
+ "dname CHAR(100)," +
+ "fatherdid INT," +
+ "entries INT)"
+ );
+ stmt.executeUpdate("CREATE INDEX idir1 ON dir ( did )");
+ stmt.executeUpdate("CREATE INDEX idir2 ON dir ( fatherdid )");
+ //Anlegen der Tabelle file
+ try {
+ stmt.executeUpdate("DROP TABLE file");
+ } catch (SQLException e) {
+ //Nichts zu tun
+ }
+ stmt.executeUpdate("CREATE TABLE file (" +
+ "fid INT ," +
+ "did INT," +
+ "fname CHAR(100)," +
+ "fsize INT," +
+ "fdate DATE," +
+ "ftime CHAR(5))"
+ );
+ stmt.executeUpdate("CREATE INDEX ifile1 ON file ( fid )");
+ }
+
+ /**
+ * Durchläuft den Verzeichnisbaum rekursiv und schreibt
+ * Verzeichnis- und Dateinamen in die Datenbank.
+ */
+ public static void populate(String dir)
+ throws Exception
+ {
+ addDirectory(0, "", dir);
+ }
+
+ /**
+ * Fügt das angegebene Verzeichnis und alle
+ * Unterverzeichnisse mit allen darin enthaltenen
+ * Dateien zur Datenbank hinzu.
+ */
+ public static void addDirectory(
+ int fatherdid, String parent, String name
+ )
+ throws Exception
+ {
+ String dirname = "";
+ if (parent.length() > 0) {
+ dirname = parent;
+ if (!parent.endsWith(FILESEP)) {
+ dirname += FILESEP;
+ }
+ }
+ dirname += name;
+ System.out.println("processing " + dirname);
+ File dir = new File(dirname);
+ if (!dir.isDirectory()) {
+ throw new Exception("not a directory: " + dirname);
+ }
+ //Verzeichnis anlegen
+ int did = nextdid++;
+ stmt.executeUpdate(
+ "INSERT INTO dir VALUES (" +
+ did + "," +
+ "\'" + name + "\'," +
+ fatherdid + "," +
+ "0)"
+ );
+ //Verzeichniseinträge lesen
+ File entries[] = dir.listFiles();
+ //Verzeichnis durchlaufen
+ for (int i = 0; i < entries.length; ++i) {
+ if (entries[i].isDirectory()) {
+ addDirectory(did, dirname, entries[i].getName());
+ } else {
+ java.util.Date d = new java.util.Date(
+ entries[i].lastModified()
+ );
+ SimpleDateFormat sdf;
+ //Datum
+ sdf = new SimpleDateFormat("yyyy-MM-dd");
+ String date = sdf.format(d);
+ //Zeit
+ sdf = new SimpleDateFormat("HH:mm");
+ String time = sdf.format(d);
+ //Satz anhängen
+ stmt.executeUpdate(
+ "INSERT INTO file VALUES (" +
+ (nextfid++) + "," +
+ did + "," +
+ "\'" + entries[i].getName() + "\'," +
+ entries[i].length() + "," +
+ "{d \'" + date + "\'}," +
+ "\'" + time + "\')"
+ );
+ System.out.println(" " + entries[i].getName());
+ }
+ }
+ //Anzahl der Einträge aktualisieren
+ stmt.executeUpdate(
+ "UPDATE dir SET entries = " + entries.length +
+ " WHERE did = " + did
+ );
+ }
+
+ /**
+ * Gibt die Anzahl der Dateien und Verzeichnisse aus.
+ */
+ public static void countRecords()
+ throws SQLException
+ {
+ ResultSet rs = stmt.executeQuery(
+ "SELECT count(*) FROM dir"
+ );
+ if (!rs.next()) {
+ throw new SQLException("SELECT COUNT(*): no result");
+ }
+ System.out.println("Directories: " + rs.getInt(1));
+ rs = stmt.executeQuery("SELECT count(*) FROM file");
+ if (!rs.next()) {
+ throw new SQLException("SELECT COUNT(*): no result");
+ }
+ System.out.println("Files: " + rs.getInt(1));
+ rs.close();
+ }
+
+ /**
+ * Liefert den Pfadnamen zu dem Verzeichnis mit dem
+ * angegebenen Schlüssel.
+ */
+ public static String getDirPath(int did)
+ throws SQLException
+ {
+ String ret = "";
+ while (true) {
+ ResultSet rs = stmt1.executeQuery(
+ "SELECT * FROM dir WHERE did = " + did
+ );
+ if (!rs.next()) {
+ throw new SQLException(
+ "no dir record found with did = " + did
+ );
+ }
+ ret = rs.getString("dname").trim() +
+ (ret.length() > 0 ? FILESEP + ret : "");
+ if ((did = rs.getInt("fatherdid")) == 0) {
+ break;
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * Gibt eine Liste aller Files auf dem Bildschirm aus,
+ * die zu dem angegebenen Dateinamen passen. Darin dürfen
+ * die üblichen SQL-Wildcards % und _ enthalten sein.
+ */
+ public static void findFile(String name)
+ throws SQLException
+ {
+ String query = "SELECT * FROM file " +
+ "WHERE fname LIKE \'" + name + "\'";
+ if (db == INSTANT185) {
+ query += " IGNORE CASE";
+ }
+ ResultSet rs = stmt.executeQuery(query);
+ while (rs.next()) {
+ String path = getDirPath(rs.getInt("did"));
+ System.out.println(
+ path + FILESEP +
+ rs.getString("fname").trim()
+ );
+ }
+ rs.close();
+ }
+
+ /**
+ * Gibt eine Liste aller Verzeichnisse auf dem Bildschirm
+ * aus, die zu dem angegebenen Verzeichnisnamen passen.
+ * Darin dürfen die üblichen SQL-Wildcards % und _
+ * enthalten sein.
+ */
+ public static void findDir(String name)
+ throws SQLException
+ {
+ String query = "SELECT * FROM dir " +
+ "WHERE dname LIKE \'" + name + "\'";
+ if (db == INSTANT185) {
+ query += " IGNORE CASE";
+ }
+ ResultSet rs = stmt.executeQuery(query);
+ while (rs.next()) {
+ System.out.println(
+ getDirPath(rs.getInt("did")) +
+ " (" + rs.getInt("entries") + " entries)"
+ );
+ }
+ rs.close();
+ }
+
+ /**
+ * Gibt die howmany größten Dateien aus.
+ */
+ public static void biggestFiles(int howmany)
+ throws SQLException
+ {
+ ResultSet rs = stmt.executeQuery(
+ "SELECT * FROM file ORDER BY fsize DESC"
+ );
+ for (int i = 0; i < howmany; ++i) {
+ if (rs.next()) {
+ System.out.print(
+ getDirPath(rs.getInt("did")) +
+ FILESEP + rs.getString("fname").trim()
+ );
+ System.out.println(
+ Str.getFormatted("%10d", rs.getInt("fsize"))
+ );
+ }
+ }
+ rs.close();
+ }
+
+ /**
+ * Summiert einerseits die tatsächliche Größe aller
+ * Dateien und andererseits die Größe, die sie durch
+ * das Clustering mit der angegebenen Clustergröße
+ * belegen. Zusätzlich wird der durch das Clustering
+ * "verschwendete" Speicherplatz ausgegeben.
+ */
+ public static void clustering(int clustersize)
+ throws SQLException
+ {
+ int truesize = 0;
+ int clusteredsize = 0;
+ double wasted;
+ ResultSet rs = stmt.executeQuery(
+ "SELECT * FROM file"
+ );
+ while (rs.next()) {
+ int fsize = rs.getInt("fsize");
+ truesize += fsize;
+ if (fsize % clustersize == 0) {
+ clusteredsize += fsize;
+ } else {
+ clusteredsize += ((fsize / clustersize) + 1) * clustersize;
+ }
+ }
+ System.out.println("true size = " + truesize);
+ System.out.println("clustered size = " + clusteredsize);
+ wasted = 100 * (1 - ((double)truesize / clusteredsize));
+ System.out.println("wasted space = " + wasted + " %");
+ }
+
+ /**
+ * Schließt die Datenbank.
+ */
+ public static void close()
+ throws SQLException
+ {
+ stmt.close();
+ stmt1.close();
+ con.close();
+ }
+
+ //---main-------------------------------------------------
+ public static void main(String args[])
+ {
+ if (args.length < 1) {
+ System.out.println("usage: java DirDB [A|I|H] <command> [<options>]");
+ System.out.println("");
+ System.out.println("command options");
+ System.out.println("-----------------------------------------");
+ System.out.println("POPULATE <directory>");
+ System.out.println("COUNT");
+ System.out.println("FINDFILE <name>");
+ System.out.println("FINDDIR <name>");
+ System.out.println("BIGGESTFILES <howmany>");
+ System.out.println("CLUSTERING <clustersize>");
+ System.exit(1);
+ }
+ if (args[0].equalsIgnoreCase("A")) {
+ db = ACCESS95;
+ } else if (args[0].equalsIgnoreCase("H")) {
+ db = HSQLDB;
+ }
+ try {
+ if (args[1].equalsIgnoreCase("populate")) {
+ open();
+ createTables();
+ populate(args[2]);
+ close();
+ } else if (args[1].equalsIgnoreCase("count")) {
+ open();
+ countRecords();
+ close();
+ } else if (args[1].equalsIgnoreCase("findfile")) {
+ open();
+ findFile(args[2]);
+ close();
+ } else if (args[1].equalsIgnoreCase("finddir")) {
+ open();
+ findDir(args[2]);
+ close();
+ } else if (args[1].equalsIgnoreCase("biggestfiles")) {
+ open();
+ biggestFiles(Integer.parseInt(args[2]));
+ close();
+ } else if (args[1].equalsIgnoreCase("clustering")) {
+ open();
+ clustering(Integer.parseInt(args[2]));
+ close();
+ }
+ } catch (SQLException e) {
+ while (e != null) {
+ System.err.println(e.toString());
+ System.err.println("SQL-State: " + e.getSQLState());
+ System.err.println("ErrorCode: " + e.getErrorCode());
+ e = e.getNextException();
+ }
+ System.exit(1);
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Directory.java b/Master/Reference Architectures and Patterns/hjp5/examples/Directory.java new file mode 100644 index 0000000..ec95b0b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Directory.java @@ -0,0 +1,90 @@ +import javax.persistence.*;
+
+/**
+ * Diese Klasse repräsentiert die Tabelle 'dir' der 'DirDB'
+ * Jede Instanz der Klasse repräsentiert wiederum einen
+ * Datensatz
+ */
+@Entity
+@Table( name = "dir" )
+public class Directory {
+
+ // Variablen die den Attributen der Tabelle entsprechen
+ private int did;
+ private String dname;
+ private int fatherid;
+ private int entries;
+
+ /**
+ * Ein einfacher Konstruktor ohne Initialisierung der
+ * Objektvariablen
+ */
+ public Directory() {
+ }
+
+ /**
+ * Konstruktor mit Initialisierung der Variablen
+ */
+ public Directory(int did,
+ String dname,
+ int fatherid,
+ int entries)
+ {
+ this.did = did;
+ this.dname = dname;
+ this.fatherid = fatherid;
+ this.entries = entries;
+ }
+
+ // Zugriffsmethoden, um die Daten der Klasse
+ // Auslesen und Schreiben zu können
+ @Id
+ @Column( name = "id" )
+ public int getDid()
+ {
+ return did;
+ }
+
+ public void setDid(int did)
+ {
+ this.did = did;
+ }
+
+ @Column( name = "dname", nullable = false )
+ public String getDname()
+ {
+ return dname;
+ }
+
+ public void setDname(String dname)
+ {
+ this.dname = dname;
+ }
+
+ @Column ( name = "fatherid" )
+ public int getFatherid()
+ {
+ return fatherid;
+ }
+
+ public void setFatherid(int fatherid)
+ {
+ this.fatherid = fatherid;
+ }
+
+ @Column ( name = "entries" )
+ public int getEntries()
+ {
+ return entries;
+ }
+
+ public void setEntries(int entries)
+ {
+ this.entries = entries;
+ }
+
+ public String toString()
+ {
+ return "Directory[id:"+ did + ", name:" + dname + "]";
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DirectoryPrintVisitor.java b/Master/Reference Architectures and Patterns/hjp5/examples/DirectoryPrintVisitor.java new file mode 100644 index 0000000..af3fdc0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/DirectoryPrintVisitor.java @@ -0,0 +1,25 @@ +/* DirectoryPrintVisitor.java */
+
+import java.io.*;
+
+public class DirectoryPrintVisitor
+implements DirectoryVisitor
+{
+ String indent = "";
+
+ public void enterDirectory(File dir)
+ {
+ System.out.println(indent + "[" + dir.getName() + "]");
+ indent += " ";
+ }
+
+ public void leaveDirectory(File dir)
+ {
+ indent = indent.substring(2);
+ }
+
+ public void visitFile(File file)
+ {
+ System.out.println(indent + file.getName());
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DirectorySizeVisitor.java b/Master/Reference Architectures and Patterns/hjp5/examples/DirectorySizeVisitor.java new file mode 100644 index 0000000..8996d8c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/DirectorySizeVisitor.java @@ -0,0 +1,41 @@ +/* DirectorySizeVisitor.java */
+
+import java.io.*;
+
+public class DirectorySizeVisitor
+implements DirectoryVisitor
+{
+ int files = 0;
+ int dirs = 0;
+ long size = 0;
+
+ public void enterDirectory(File dir)
+ {
+ ++dirs;
+ }
+
+ public void leaveDirectory(File dir)
+ {
+ }
+
+ public void visitFile(File file)
+ {
+ ++files;
+ size += file.length();
+ }
+
+ public int getDirs()
+ {
+ return dirs;
+ }
+
+ public int getFiles()
+ {
+ return files;
+ }
+
+ public long getSize()
+ {
+ return size;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DirectoryVisitor.java b/Master/Reference Architectures and Patterns/hjp5/examples/DirectoryVisitor.java new file mode 100644 index 0000000..89c0a88 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/DirectoryVisitor.java @@ -0,0 +1,10 @@ +/* DirectoryVisitor.java */
+
+import java.io.*;
+
+public interface DirectoryVisitor
+{
+ public void enterDirectory(File dir);
+ public void leaveDirectory(File dir);
+ public void visitFile(File file);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DoubleMethod.java b/Master/Reference Architectures and Patterns/hjp5/examples/DoubleMethod.java new file mode 100644 index 0000000..a14ce7b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/DoubleMethod.java @@ -0,0 +1,6 @@ +/* DoubleMethod.java */
+
+public interface DoubleMethod
+{
+ public double compute(double value);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DoubleMethodFactory.java b/Master/Reference Architectures and Patterns/hjp5/examples/DoubleMethodFactory.java new file mode 100644 index 0000000..7503455 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/DoubleMethodFactory.java @@ -0,0 +1,33 @@ +public class DoubleMethodFactory
+{
+ public DoubleMethodFactory()
+ {
+ //Hier wird die Factory selbst erzeugt und konfiguriert
+ }
+
+ public DoubleMethod createFromClassFile(String name)
+ {
+ //Lädt die Klassendatei mit dem angegebenen Namen,
+ //prüft, ob sie DoubleMethod implementiert, und
+ //instanziert sie gegebenenfalls...
+ return null;
+ }
+
+ public DoubleMethod createFromStatic(String clazz,
+ String method)
+ {
+ //Erzeugt ein Wrapper-Objekt, das das Interface
+ //DoubleMethod implementiert und beim Aufruf von
+ //compute die angegebene Methode der vorgegebenen
+ //Klasse aufruft...
+ return null;
+ }
+
+ public DoubleMethod createFromPolynom(String expr)
+ {
+ //Erzeugt aus dem angegebenen Polynom-Ausdruck ein
+ //DoubleMethod-Objekt, in dem ein äquivalentes
+ //Polynom implementiert wird...
+ return null;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/EchoClient.java b/Master/Reference Architectures and Patterns/hjp5/examples/EchoClient.java new file mode 100644 index 0000000..4b99b0b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/EchoClient.java @@ -0,0 +1,95 @@ +/* EchoClient.java */
+
+import java.net.*;
+import java.io.*;
+
+public class EchoClient
+{
+ public static void main(String[] args)
+ {
+ if (args.length != 1) {
+ System.err.println("Usage: java EchoClient <host>");
+ System.exit(1);
+ }
+ try {
+ Socket sock = new Socket(args[0], 7);
+ InputStream in = sock.getInputStream();
+ OutputStream out = sock.getOutputStream();
+ //Timeout setzen
+ sock.setSoTimeout(300);
+ //Ausgabethread erzeugen
+ OutputThread th = new OutputThread(in);
+ th.start();
+ //Schleife für Benutzereingaben
+ BufferedReader conin = new BufferedReader(
+ new InputStreamReader(System.in));
+ String line = "";
+ while (true) {
+ //Eingabezeile lesen
+ line = conin.readLine();
+ if (line.equalsIgnoreCase("QUIT")) {
+ break;
+ }
+ //Eingabezeile an ECHO-Server schicken
+ out.write(line.getBytes());
+ out.write('\r');
+ out.write('\n');
+ //Ausgabe abwarten
+ th.yield();
+ }
+ //Programm beenden
+ System.out.println("terminating output thread...");
+ th.requestStop();
+ th.yield();
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+ in.close();
+ out.close();
+ sock.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
+
+class OutputThread
+extends Thread
+{
+ InputStream in;
+ boolean stoprequested;
+
+ public OutputThread(InputStream in)
+ {
+ super();
+ this.in = in;
+ stoprequested = false;
+ }
+
+ public synchronized void requestStop()
+ {
+ stoprequested = true;
+ }
+
+ public void run()
+ {
+ int len;
+ byte[] b = new byte[100];
+ try {
+ while (!stoprequested) {
+ try {
+ if ((len = in.read(b)) == -1) {
+ break;
+ }
+ System.out.write(b, 0, len);
+ } catch (InterruptedIOException e) {
+ //nochmal versuchen
+ }
+ }
+ } catch (IOException e) {
+ System.err.println("OutputThread: " + e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/EchoServer.java b/Master/Reference Architectures and Patterns/hjp5/examples/EchoServer.java new file mode 100644 index 0000000..d0d93e0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/EchoServer.java @@ -0,0 +1,56 @@ +/* EchoServer.java */
+
+import java.net.*;
+import java.io.*;
+
+public class EchoServer
+{
+ public static void main(String[] args)
+ {
+ int cnt = 0;
+ try {
+ System.out.println("Warte auf Verbindungen auf Port 7...");
+ ServerSocket echod = new ServerSocket(7);
+ while (true) {
+ Socket socket = echod.accept();
+ (new EchoClientThread(++cnt, socket)).start();
+ }
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
+
+class EchoClientThread
+extends Thread
+{
+ private int name;
+ private Socket socket;
+
+ public EchoClientThread(int name, Socket socket)
+ {
+ this.name = name;
+ this.socket = socket;
+ }
+
+ public void run()
+ {
+ String msg = "EchoServer: Verbindung " + name;
+ System.out.println(msg + " hergestellt");
+ try {
+ InputStream in = socket.getInputStream();
+ OutputStream out = socket.getOutputStream();
+ out.write((msg + "\r\n").getBytes());
+ int c;
+ while ((c = in.read()) != -1) {
+ out.write((char)c);
+ System.out.print((char)c);
+ }
+ System.out.println("Verbindung " + name + " wird beendet");
+ socket.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/ExperimentalWebServer.java b/Master/Reference Architectures and Patterns/hjp5/examples/ExperimentalWebServer.java new file mode 100644 index 0000000..58aedc5 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/ExperimentalWebServer.java @@ -0,0 +1,241 @@ +/* ExperimentalWebServer.java */
+
+import java.io.*;
+import java.util.*;
+import java.net.*;
+
+/**
+ * Ein ganz einfacher Web-Server auf TCP und einem
+ * beliebigen Port. Der Server ist in der Lage,
+ * Seitenanforderungen lokal zu dem Verzeichnis,
+ * aus dem er gestartet wurde, zu bearbeiten. Wurde
+ * der Server z.B. im Verzeichnis c:\tmp gestartet, so
+ * würde eine Seitenanforderung
+ * http://localhost:80/test/index.html die Datei
+ * c:\tmp\test\index.html laden. CGIs, SSIs, Servlets
+ * oder ähnliches wird nicht unterstützt.
+ * <p>
+ * Die Dateitypen .htm, .html, .gif, .jpg und .jpeg werden
+ * erkannt und mit korrekten MIME-Headern übertragen, alle
+ * anderen Dateien werden als "application/octet-stream"
+ * übertragen. Jeder Request wird durch einen eigenen
+ * Client-Thread bearbeitet, nach Übertragung der Antwort
+ * schließt der Server den Socket. Antworten werden mit
+ * HTTP/1.0-Header gesendet.
+ */
+public class ExperimentalWebServer
+{
+ public static void main(String[] args)
+ {
+ if (args.length != 1) {
+ System.err.println(
+ "Usage: java ExperimentalWebServer <port>"
+ );
+ System.exit(1);
+ }
+ try {
+ int port = Integer.parseInt(args[0]);
+ System.out.println("Listening to port " + port);
+ int calls = 0;
+ ServerSocket httpd = new ServerSocket(port);
+ while (true) {
+ Socket socket = httpd.accept();
+ (new BrowserClientThread(++calls, socket)).start();
+ }
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
+
+/**
+ * Die Thread-Klasse für die Client-Verbindung.
+ */
+class BrowserClientThread
+extends Thread
+{
+ static final String[][] mimetypes = {
+ {"html", "text/html"},
+ {"htm", "text/html"},
+ {"txt", "text/plain"},
+ {"gif", "image/gif"},
+ {"jpg", "image/jpeg"},
+ {"jpeg", "image/jpeg"},
+ {"jnlp", "application/x-java-jnlp-file"}
+ };
+
+ private Socket socket;
+ private int id;
+ private PrintStream out;
+ private InputStream in;
+ private String cmd;
+ private String url;
+ private String httpversion;
+
+ /**
+ * Erzeugt einen neuen Client-Thread mit der angegebenen
+ * id und dem angegebenen Socket.
+ */
+ public BrowserClientThread(int id, Socket socket)
+ {
+ this.id = id;
+ this.socket = socket;
+ }
+
+ /**
+ * Hauptschleife für den Thread.
+ */
+ public void run()
+ {
+ try {
+ System.out.println(id + ": Incoming call...");
+ out = new PrintStream(socket.getOutputStream());
+ in = socket.getInputStream();
+ readRequest();
+ createResponse();
+ socket.close();
+ System.out.println(id + ": Closed.");
+ } catch (IOException e) {
+ System.out.println(id + ": " + e.toString());
+ System.out.println(id + ": Aborted.");
+ }
+ }
+
+ /**
+ * Liest den nächsten HTTP-Request vom Browser ein.
+ */
+ private void readRequest()
+ throws IOException
+ {
+ //Request-Zeilen lesen
+ Vector request = new Vector(10);
+ StringBuffer sb = new StringBuffer(100);
+ int c;
+ while ((c = in.read()) != -1) {
+ if (c == '\r') {
+ //ignore
+ } else if (c == '\n') { //line terminator
+ if (sb.length() <= 0) {
+ break;
+ } else {
+ request.addElement(sb);
+ sb = new StringBuffer(100);
+ }
+ } else {
+ sb.append((char)c);
+ }
+ }
+ //Request-Zeilen auf der Konsole ausgeben
+ Enumeration e = request.elements();
+ while (e.hasMoreElements()) {
+ sb = (StringBuffer)e.nextElement();
+ System.out.println("< " + sb.toString());
+ }
+ //Kommando, URL und HTTP-Version extrahieren
+ String s = ((StringBuffer)request.elementAt(0)).toString();
+ cmd = "";
+ url = "";
+ httpversion = "";
+ int pos = s.indexOf(' ');
+ if (pos != -1) {
+ cmd = s.substring(0, pos).toUpperCase();
+ s = s.substring(pos + 1);
+ //URL
+ pos = s.indexOf(' ');
+ if (pos != -1) {
+ url = s.substring(0, pos);
+ s = s.substring(pos + 1);
+ //HTTP-Version
+ pos = s.indexOf('\r');
+ if (pos != -1) {
+ httpversion = s.substring(0, pos);
+ } else {
+ httpversion = s;
+ }
+ } else {
+ url = s;
+ }
+ }
+ }
+
+ /**
+ * Request bearbeiten und Antwort erzeugen.
+ */
+ private void createResponse()
+ {
+ if (cmd.equals("GET") || cmd.equals("HEAD")) {
+ if (!url.startsWith("/")) {
+ httpError(400, "Bad Request");
+ } else {
+ //MIME-Typ aus Dateierweiterung bestimmen
+ String mimestring = "application/octet-stream";
+ for (int i = 0; i < mimetypes.length; ++i) {
+ if (url.endsWith(mimetypes[i][0])) {
+ mimestring = mimetypes[i][1];
+ break;
+ }
+ }
+ //URL in lokalen Dateinamen konvertieren
+ String fsep = System.getProperty("file.separator", "/");
+ StringBuffer sb = new StringBuffer(url.length());
+ for (int i = 1; i < url.length(); ++i) {
+ char c = url.charAt(i);
+ if (c == '/') {
+ sb.append(fsep);
+ } else {
+ sb.append(c);
+ }
+ }
+ try {
+ FileInputStream is = new FileInputStream(sb.toString());
+ //HTTP-Header senden
+ out.print("HTTP/1.0 200 OK\r\n");
+ System.out.println("> HTTP/1.0 200 OK");
+ out.print("Server: ExperimentalWebServer 0.5\r\n");
+ System.out.println(
+ "> Server: ExperimentalWebServer 0.5"
+ );
+ out.print("Content-type: " + mimestring + "\r\n\r\n");
+ System.out.println("> Content-type: " + mimestring);
+ if (cmd.equals("GET")) {
+ //Dateiinhalt senden
+ byte[] buf = new byte[256];
+ int len;
+ while ((len = is.read(buf)) != -1) {
+ out.write(buf, 0, len);
+ }
+ }
+ is.close();
+ } catch (FileNotFoundException e) {
+ httpError(404, "Error Reading File");
+ } catch (IOException e) {
+ httpError(404, "Not Found");
+ } catch (Exception e) {
+ httpError(404, "Unknown exception");
+ }
+ }
+ } else {
+ httpError(501, "Not implemented");
+ }
+ }
+
+ /**
+ * Eine Fehlerseite an den Browser senden.
+ */
+ private void httpError(int code, String description)
+ {
+ System.out.println("> ***" + code + ": " + description + "***");
+ out.print("HTTP/1.0 " + code + " " + description + "\r\n");
+ out.print("Content-type: text/html\r\n\r\n");
+ out.println("<html>");
+ out.println("<head>");
+ out.println("<title>ExperimentalWebServer-Error</title>");
+ out.println("</head>");
+ out.println("<body>");
+ out.println("<h1>HTTP/1.0 " + code + "</h1>");
+ out.println("<h3>" + description + "</h3>");
+ out.println("</body>");
+ out.println("</html>");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Farbe2.java b/Master/Reference Architectures and Patterns/hjp5/examples/Farbe2.java new file mode 100644 index 0000000..792a64d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Farbe2.java @@ -0,0 +1,32 @@ +/* Farbe2.java */
+
+public enum Farbe2
+{
+ ROT(255, 0 , 0),
+ GRUEN(0, 255, 0),
+ BLAU(0, 0, 255),
+ GELB(255, 255, 0);
+
+ private final int r;
+ private final int g;
+ private final int b;
+
+ Farbe2(int r, int g, int b)
+ {
+ this.r = r;
+ this.g = g;
+ this.b = b;
+ }
+
+ public String toRGB()
+ {
+ return "(" + r + "," + g + "," + b + ")";
+ }
+
+ public static void main(String[] args)
+ {
+ for (Farbe2 f : Farbe2.values()) {
+ System.out.println(f + ":" + f.toRGB());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/FileCopy.java b/Master/Reference Architectures and Patterns/hjp5/examples/FileCopy.java new file mode 100644 index 0000000..deb3309 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/FileCopy.java @@ -0,0 +1,27 @@ +/* FileCopy.java */
+
+import java.io.*;
+
+public class FileCopy
+{
+ public static void main(String[] args)
+ {
+ if (args.length != 2) {
+ System.out.println("java FileCopy inputfile outputfile");
+ System.exit(1);
+ }
+ try {
+ FileInputStream in = new FileInputStream(args[0]);
+ FileOutputStream out = new FileOutputStream(args[1]);
+ byte[] buf = new byte[4096];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ out.close();
+ in.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/FilePrintHelper.java b/Master/Reference Architectures and Patterns/hjp5/examples/FilePrintHelper.java new file mode 100644 index 0000000..e93ee46 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/FilePrintHelper.java @@ -0,0 +1,52 @@ +/* FilePrintHelper.java */
+
+import java.util.*;
+
+public class FilePrintHelper
+{
+ //---Membervariablen----------------------------------
+ Vector pageinfo;
+
+ //---Konstruktor--------------------------------------
+ public FilePrintHelper()
+ {
+ pageinfo = new Vector();
+ }
+
+ //---Seitendefinition und -abfrage--------------------
+ public void createPage(int page)
+ {
+ for (int i = pageinfo.size(); i <= page; ++i) {
+ pageinfo.addElement(new Entry());
+ }
+ }
+
+ public boolean knownPage(int page)
+ {
+ return page < pageinfo.size();
+ }
+
+ //---Verwaltung der Offsets---------------------------
+ public long getFileOffset(int page)
+ {
+ Entry entry = (Entry)pageinfo.elementAt(page);
+ return entry.fileoffset;
+ }
+
+ public void setFileOffset(int page, long fileoffset)
+ {
+ Entry entry = (Entry)pageinfo.elementAt(page);
+ entry.fileoffset = fileoffset;
+ }
+
+ //---Lokale Klasse Entry------------------------------
+ static class Entry
+ {
+ public long fileoffset;
+
+ public Entry()
+ {
+ this.fileoffset = -1;
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/FloatTables.java b/Master/Reference Architectures and Patterns/hjp5/examples/FloatTables.java new file mode 100644 index 0000000..25ea516 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/FloatTables.java @@ -0,0 +1,54 @@ +/* FloatTables.java */
+
+import java.lang.reflect.*;
+
+public class FloatTables
+{
+ public static double times2(double value)
+ {
+ return 2 * value;
+ }
+
+ public static double sqr(double value)
+ {
+ return value * value;
+ }
+
+ public static void printTable(String methname)
+ {
+ try {
+ System.out.println("Wertetabelle fuer " + methname);
+ int pos = methname.lastIndexOf('.');
+ Class clazz;
+ if (pos == -1) {
+ clazz = FloatTables.class;
+ } else {
+ clazz = Class.forName(methname.substring(0, pos));
+ methname = methname.substring(pos + 1);
+ }
+ Class[] formparas = new Class[1];
+ formparas[0] = Double.TYPE;
+ Method meth = clazz.getMethod(methname, formparas);
+ if (!Modifier.isStatic(meth.getModifiers())) {
+ throw new Exception(methname + " ist nicht static");
+ }
+ Object[] actargs = new Object[1];
+ for (double x = 0.0; x <= 5.0; x += 1) {
+ actargs[0] = new Double(x);
+ Double ret = (Double)meth.invoke(null, actargs);
+ double result = ret.doubleValue();
+ System.out.println(" " + x + " -> " + result);
+ }
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ printTable("times2");
+ printTable("java.lang.Math.exp");
+ printTable("sqr");
+ printTable("java.lang.Math.sqrt");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Fontmetriken.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Fontmetriken.inc new file mode 100644 index 0000000..708333a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Fontmetriken.inc @@ -0,0 +1,33 @@ +/* Fontmetriken.inc */
+
+public void paint(Graphics g)
+{
+ Font font = new Font("TimesRoman",Font.PLAIN,72);
+
+ //---Linien
+ g.setColor(Color.blue);
+ for (int x = 10; x <= 260; x += 10) {
+ g.drawLine(x,30,x,130);
+ }
+ for (int y = 30; y <= 130; y += 10) {
+ g.drawLine(10,y,260,y);
+ }
+ //---Schrift
+ g.setColor(Color.black);
+ g.drawLine(0,100,270,100);
+ g.setFont(font);
+ g.drawString("mgdAW",10,100);
+ //---Font-Metriken
+ FontMetrics fm = getFontMetrics(font);
+ System.out.println("Oberlänge = " + fm.getAscent());
+ System.out.println("Unterlänge = " + fm.getDescent());
+ System.out.println("Höhe = " + fm.getHeight());
+ System.out.println("Zeilenabstand = " + fm.getLeading());
+ System.out.println("---");
+ System.out.println("Breite(m) = " + fm.charWidth('m'));
+ System.out.println("Breite(g) = " + fm.charWidth('g'));
+ System.out.println("Breite(d) = " + fm.charWidth('d'));
+ System.out.println("Breite(A) = " + fm.charWidth('A'));
+ System.out.println("Breite(W) = " + fm.charWidth('W'));
+ System.out.println("---");
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/FussballPlatz.java b/Master/Reference Architectures and Patterns/hjp5/examples/FussballPlatz.java new file mode 100644 index 0000000..f76c9dc --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/FussballPlatz.java @@ -0,0 +1,18 @@ +public class FussballPlatz
+implements Groesse
+{
+ public int laenge()
+ {
+ return 105000;
+ }
+
+ public int hoehe()
+ {
+ return 0;
+ }
+
+ public int breite()
+ {
+ return 70000;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/GefuellteFlaechen.inc b/Master/Reference Architectures and Patterns/hjp5/examples/GefuellteFlaechen.inc new file mode 100644 index 0000000..0fbf069 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/GefuellteFlaechen.inc @@ -0,0 +1,19 @@ +/* GefuellteFlaechen.inc */
+
+public void paint(Graphics g)
+{
+ int[] arx = {150,175,200,150};
+ int[] ary = {100,150,100,100};
+
+ //---J
+ g.fillRect(70,40,20,80);
+ g.fillArc(30,90,60,60,225,180);
+ //---a
+ g.fillOval(100,100,40,50);
+ g.fillRect(120,100,20,50);
+ //---v
+ g.fillPolygon(arx,ary,arx.length);
+ //---a
+ g.fillOval(210,100,40,50);
+ g.fillRect(230,100,20,50);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Gehaltsberechnung.java b/Master/Reference Architectures and Patterns/hjp5/examples/Gehaltsberechnung.java new file mode 100644 index 0000000..71e6d83 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Gehaltsberechnung.java @@ -0,0 +1,90 @@ +/* Gehaltsberechnung.java */
+
+import java.util.Date;
+
+abstract class Mitarbeiter
+{
+ int persnr;
+ String name;
+ Date eintritt;
+
+ public Mitarbeiter()
+ {
+ }
+
+ public abstract double monatsBrutto();
+}
+
+class Arbeiter
+extends Mitarbeiter
+{
+ double stundenlohn;
+ double anzahlstunden;
+ double ueberstundenzuschlag;
+ double anzahlueberstunden;
+ double schichtzulage;
+
+ public double monatsBrutto()
+ {
+ return stundenlohn*anzahlstunden+
+ ueberstundenzuschlag*anzahlueberstunden+
+ schichtzulage;
+ }
+}
+
+class Angestellter
+extends Mitarbeiter
+{
+ double grundgehalt;
+ double ortszuschlag;
+ double zulage;
+
+ public double monatsBrutto()
+ {
+ return grundgehalt+
+ ortszuschlag+
+ zulage;
+ }
+}
+
+class Manager
+extends Mitarbeiter
+{
+ double fixgehalt;
+ double provision1;
+ double provision2;
+ double umsatz1;
+ double umsatz2;
+
+ public double monatsBrutto()
+ {
+ return fixgehalt+
+ umsatz1*provision1/100+
+ umsatz2*provision2/100;
+ }
+}
+
+public class Gehaltsberechnung
+{
+ private static final int ANZ_MA = 100;
+ private static Mitarbeiter[] ma;
+ private static double bruttosumme;
+
+ public static void main(String[] args)
+ {
+ ma = new Mitarbeiter[ANZ_MA];
+
+ //Mitarbeiter-Array füllen, z.B.
+ //ma[0] = new Manager();
+ //ma[1] = new Arbeiter();
+ //ma[2] = new Angestellter();
+ //...
+
+ //Bruttosumme berechnen
+ bruttosumme = 0.0;
+ for (int i=0; i<ma.length; ++i) {
+ bruttosumme += ma[i].monatsBrutto();
+ }
+ System.out.println("Bruttosumme = "+bruttosumme);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/GrafikBeispiel.java b/Master/Reference Architectures and Patterns/hjp5/examples/GrafikBeispiel.java new file mode 100644 index 0000000..802a330 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/GrafikBeispiel.java @@ -0,0 +1,27 @@ +/* GrafikBeispiel.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class GrafikBeispiel
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ GrafikBeispiel wnd = new GrafikBeispiel();
+ }
+
+ public GrafikBeispiel()
+ {
+ super("GrafikBeispiel");
+ addWindowListener(new WindowClosingAdapter(true));
+ setBackground(Color.lightGray);
+ setSize(300,200);
+ setVisible(true);
+ }
+
+ public void paint(Graphics g)
+ {
+ //wird in den folgenden Beispielen überlagert
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Groesse.java b/Master/Reference Architectures and Patterns/hjp5/examples/Groesse.java new file mode 100644 index 0000000..1f7b8ee --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Groesse.java @@ -0,0 +1,8 @@ +/* Groesse.java */
+
+public interface Groesse
+{
+ public int laenge();
+ public int hoehe();
+ public int breite();
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/HWApplet.html b/Master/Reference Architectures and Patterns/hjp5/examples/HWApplet.html new file mode 100644 index 0000000..2a55752 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/HWApplet.html @@ -0,0 +1,15 @@ +<html>
+<head>
+<title>HWApplet</title>
+</head>
+<body>
+<h1>HWApplet</h1>
+<applet
+ code=HWApplet.class
+ archive=hello.jar
+ width=300
+ height=200>
+Hier steht das Applet HWApplet.class
+</applet>
+</body>
+</html>
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/HWApplet.java b/Master/Reference Architectures and Patterns/hjp5/examples/HWApplet.java new file mode 100644 index 0000000..c7c7f19 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/HWApplet.java @@ -0,0 +1,39 @@ +/* HWApplet.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.applet.*;
+
+public class HWApplet
+extends Applet
+implements ActionListener
+{
+ Button hello;
+ Button world;
+ AudioClip helloClip;
+ AudioClip worldClip;
+
+ public void init()
+ {
+ super.init();
+ setLayout(new FlowLayout());
+ hello = new Button("Hello");
+ hello.addActionListener(this);
+ add(hello);
+ world = new Button("World");
+ world.addActionListener(this);
+ add(world);
+ helloClip = getAudioClip(getCodeBase(),"hello.au");
+ worldClip = getAudioClip(getCodeBase(),"world.au");
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("Hello")) {
+ helloClip.play();
+ } else if (cmd.equals("World")) {
+ worldClip.play();
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Hello.java b/Master/Reference Architectures and Patterns/hjp5/examples/Hello.java new file mode 100644 index 0000000..35f2894 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Hello.java @@ -0,0 +1,9 @@ +/* Hello.java */
+
+public class Hello
+{
+ public static void main(String[] args)
+ {
+ System.out.println("Hello, world");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Icon.java b/Master/Reference Architectures and Patterns/hjp5/examples/Icon.java new file mode 100644 index 0000000..6f35b08 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Icon.java @@ -0,0 +1,20 @@ +public class Icon
+{
+ private Icon()
+ {
+ //Verhindert das manuelle Instanzieren
+ }
+
+ public static Icon loadFromFile(String name)
+ {
+ Icon ret = null;
+ if (name.endsWith(".gif")) {
+ //Code zum Erzeugen eines Icons aus einer gif-Datei...
+ } else if (name.endsWith(".jpg")) {
+ //Code zum Erzeugen eines Icons aus einer jpg-Datei...
+ } else if (name.endsWith(".png")) {
+ //Code zum Erzeugen eines Icons aus einer png-Datei...
+ }
+ return ret;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/ImageResource.inc b/Master/Reference Architectures and Patterns/hjp5/examples/ImageResource.inc new file mode 100644 index 0000000..56cfefd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/ImageResource.inc @@ -0,0 +1,33 @@ +/* ImageResource.inc */
+
+import java.io.*;
+import java.awt.*;
+
+//...
+
+public Image loadImageResource(String pkgname, String fname)
+throws IOException
+{
+ Image ret = null;
+ InputStream is = getResourceStream(pkgname, fname);
+ if (is != null) {
+ byte[] buffer = new byte[0];
+ byte[] tmpbuf = new byte[1024];
+ while (true) {
+ int len = is.read(tmpbuf);
+ if (len <= 0) {
+ break;
+ }
+ byte[] newbuf = new byte[buffer.length + len];
+ System.arraycopy(buffer, 0, newbuf, 0, buffer.length);
+ System.arraycopy(tmpbuf, 0, newbuf, buffer.length, len);
+ buffer = newbuf;
+ }
+ //create image
+ ret = Toolkit.getDefaultToolkit().createImage(buffer);
+ is.close();
+ }
+ return ret;
+}
+
+//...
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Immutable.java b/Master/Reference Architectures and Patterns/hjp5/examples/Immutable.java new file mode 100644 index 0000000..a6c0f3e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Immutable.java @@ -0,0 +1,21 @@ +public class Immutable
+{
+ private int value1;
+ private String[] value2;
+
+ public Immutable(int value1, String[] value2)
+ {
+ this.value1 = value1;
+ this.value2 = (String[])value2.clone();
+ }
+
+ public int getValue1()
+ {
+ return value1;
+ }
+
+ public String getValue2(int index)
+ {
+ return value2[index];
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/JAppletTest.java b/Master/Reference Architectures and Patterns/hjp5/examples/JAppletTest.java new file mode 100644 index 0000000..c1f699e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/JAppletTest.java @@ -0,0 +1,18 @@ +/* JAppletTest.java */
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+public class JAppletTest
+extends JApplet
+{
+ public void init()
+ {
+ Container contentPane = getContentPane();
+ contentPane.setLayout(new GridLayout(3, 1));
+ contentPane.add(new JButton("Button 1"));
+ contentPane.add(new JButton("Button 2"));
+ contentPane.add(new JButton("Button 3"));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Kopieren.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Kopieren.inc new file mode 100644 index 0000000..d60eb15 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Kopieren.inc @@ -0,0 +1,21 @@ +/* Kopieren.inc */
+
+public void paint(Graphics g)
+{
+ int xorg = 4;
+ int yorg = 28;
+ int[] arx = {0,6,6,2,2,4,4,0,0};
+ int[] ary = {0,0,6,6,4,4,2,2,8};
+ for (int i = 0; i < arx.length; ++i) {
+ arx[i] += xorg;
+ ary[i] += yorg;
+ }
+ g.drawPolyline(arx,ary,arx.length);
+ for (int x = 0; x <= 300; x += 8) {
+ for (int y = 0; y <= 160; y += 8) {
+ if (x != 0 || y != 0) {
+ g.copyArea(xorg,yorg,8,8,x,y);
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/KreisBoegen.inc b/Master/Reference Architectures and Patterns/hjp5/examples/KreisBoegen.inc new file mode 100644 index 0000000..c09ce1f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/KreisBoegen.inc @@ -0,0 +1,13 @@ +/* KreisBoegen.inc */
+
+public void paint(Graphics g)
+{
+ int line = 4;
+ int gap = 3;
+ int angle = 0;
+
+ while (angle < 360) {
+ g.drawArc(20,40,250,140,angle,line);
+ angle += gap + line;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Kreise.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Kreise.inc new file mode 100644 index 0000000..2a413bf --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Kreise.inc @@ -0,0 +1,17 @@ +/* Kreise.inc */
+
+public void paint(Graphics g)
+{
+ int r = 8;
+ int i, j;
+ int x, y;
+
+ for (i=1; i<=10; ++i) {
+ x = 150 - r * i;
+ y = (int) (40 + (i - 1) * 1.7321 * r);
+ for (j=1; j<=i; ++j) {
+ g.drawOval(x,y,2*r,2*r);
+ x += 2 * r;
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Label.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Label.inc new file mode 100644 index 0000000..ca9775a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Label.inc @@ -0,0 +1,10 @@ +/* Label.inc */
+
+private void customizeLayout(Panel panel)
+{
+ panel.setLayout(new GridLayout(4,1));
+ panel.add(new Label("Default"));
+ panel.add(new Label("Links",Label.LEFT));
+ panel.add(new Label("Zentriert",Label.CENTER));
+ panel.add(new Label("Rechts",Label.RIGHT));
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/LightBulb.java b/Master/Reference Architectures and Patterns/hjp5/examples/LightBulb.java new file mode 100644 index 0000000..961fef3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/LightBulb.java @@ -0,0 +1,99 @@ +/* LightBulb.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import java.beans.*;
+
+public class LightBulb
+extends Canvas
+implements Serializable
+{
+ //Instanzvariablen
+ protected boolean lighton;
+ transient protected Image offimage;
+ transient protected Image onimage;
+
+ //Methoden
+ public LightBulb()
+ {
+ lighton = false;
+ initTransientState();
+ }
+
+ //Getter/Setter Licht an/aus
+ public void setLightOn(boolean on)
+ {
+ if (on != this.lighton) {
+ this.lighton = on;
+ repaint();
+ }
+ }
+
+ public boolean getLightOn()
+ {
+ return this.lighton;
+ }
+
+ public void toggleLight()
+ {
+ setLightOn(!getLightOn());
+ }
+
+ //Implementierung der Oberfläche
+ public void paint(Graphics g)
+ {
+ int width = getSize().width;
+ int height = getSize().height;
+ int xpos = 0;
+ if (width > 40) {
+ xpos = (width - 40) / 2;
+ }
+ int ypos = 0;
+ if (height > 40) {
+ ypos = (height - 40) / 2;
+ }
+ g.drawImage(
+ (this.lighton ? onimage : offimage),
+ xpos,
+ ypos,
+ this
+ );
+ }
+
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(40, 40);
+ }
+
+ public Dimension getMinimumSize()
+ {
+ return new Dimension(40, 40);
+ }
+
+ //Private Methoden
+ private void initTransientState()
+ {
+ offimage = getImageResource("bulb1.gif");
+ onimage = getImageResource("bulb2.gif");
+ }
+
+ private void readObject(ObjectInputStream stream)
+ throws IOException, ClassNotFoundException
+ {
+ stream.defaultReadObject();
+ initTransientState();
+ }
+
+ private Image getImageResource(String name)
+ {
+ Image img = null;
+ try {
+ java.net.URL url = getClass().getResource(name);
+ img = getToolkit().createImage(url);
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ }
+ return img;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbBeanInfo.java b/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbBeanInfo.java new file mode 100644 index 0000000..7c81745 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbBeanInfo.java @@ -0,0 +1,49 @@ +/* LightBulbBeanInfo.java */
+
+import java.awt.*;
+import java.beans.*;
+import java.lang.reflect.*;
+
+public class LightBulbBeanInfo
+extends SimpleBeanInfo
+{
+ public Image getIcon(int iconKind)
+ {
+ String imgname = "bulbico16.gif";
+ if (iconKind == BeanInfo.ICON_MONO_32x32 ||
+ iconKind == BeanInfo.ICON_COLOR_32x32) {
+ imgname = "bulbico32.gif";
+ }
+ return loadImage(imgname);
+ }
+
+ public PropertyDescriptor[] getPropertyDescriptors()
+ {
+ try {
+ PropertyDescriptor pd1 = new PropertyDescriptor(
+ "lightOn",
+ LightBulb.class
+ );
+ //pd1.setPropertyEditorClass(LightBulbLightOnEditor1.class);
+ PropertyDescriptor[] ret = {pd1};
+ return ret;
+ } catch (IntrospectionException e) {
+ System.err.println(e.toString());
+ return null;
+ }
+ }
+
+ public MethodDescriptor[] getMethodDescriptors()
+ {
+ MethodDescriptor[] ret = null;
+ try {
+ Class bulbclass = LightBulb.class;
+ Method meth1 = bulbclass.getMethod("toggleLight", null);
+ ret = new MethodDescriptor[1];
+ ret[0] = new MethodDescriptor(meth1);
+ } catch (NoSuchMethodException e) {
+ //ret bleibt null
+ }
+ return ret;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbLightOnEditor1.java b/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbLightOnEditor1.java new file mode 100644 index 0000000..da8274f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbLightOnEditor1.java @@ -0,0 +1,38 @@ +/* LightBulbLightOnEditor1.java */
+
+import java.awt.*;
+import java.beans.*;
+
+public class LightBulbLightOnEditor1
+extends PropertyEditorSupport
+{
+ boolean currentvalue;
+
+ public void setValue(Object value)
+ {
+ currentvalue = ((Boolean)value).booleanValue();
+ }
+
+ public Object getValue()
+ {
+ return new Boolean(currentvalue);
+ }
+
+ public String getAsText()
+ {
+ return "" + (currentvalue ? "an" : "aus");
+ }
+
+ public void setAsText(String text)
+ throws java.lang.IllegalArgumentException
+ {
+ if (text.equalsIgnoreCase("an")) {
+ currentvalue = true;
+ } else if (text.equalsIgnoreCase("aus")) {
+ currentvalue = false;
+ } else {
+ throw new IllegalArgumentException(text);
+ }
+ firePropertyChange();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbLightOnEditor2.java b/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbLightOnEditor2.java new file mode 100644 index 0000000..196f10f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbLightOnEditor2.java @@ -0,0 +1,44 @@ +/* LightBulbLightOnEditor2.java */
+
+import java.awt.*;
+import java.beans.*;
+
+public class LightBulbLightOnEditor2
+extends PropertyEditorSupport
+{
+ boolean currentvalue;
+
+ public void setValue(Object value)
+ {
+ currentvalue = ((Boolean)value).booleanValue();
+ }
+
+ public Object getValue()
+ {
+ return new Boolean(currentvalue);
+ }
+
+ public String getAsText()
+ {
+ return "" + (currentvalue ? "an" : "aus");
+ }
+
+ public void setAsText(String text)
+ throws java.lang.IllegalArgumentException
+ {
+ System.out.println("setAsText(" + text + ")");
+ if (text.equalsIgnoreCase("an")) {
+ currentvalue = true;
+ } else if (text.equalsIgnoreCase("aus")) {
+ currentvalue = false;
+ } else {
+ throw new IllegalArgumentException(text);
+ }
+ firePropertyChange();
+ }
+
+ public String[] getTags()
+ {
+ return new String[]{"aus", "an"};
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbLightOnEditor3.java b/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbLightOnEditor3.java new file mode 100644 index 0000000..3ff07ba --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbLightOnEditor3.java @@ -0,0 +1,85 @@ +/* LightBulbLightOnEditor3.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+
+public class LightBulbLightOnEditor3
+extends PropertyEditorSupport
+{
+ boolean currentvalue;
+
+ public void setValue(Object value)
+ {
+ currentvalue = ((Boolean)value).booleanValue();
+ }
+
+ public Object getValue()
+ {
+ return new Boolean(currentvalue);
+ }
+
+ public boolean isPaintable()
+ {
+ return true;
+ }
+
+ public boolean supportsCustomEditor()
+ {
+ return true;
+ }
+
+ public Component getCustomEditor()
+ {
+ return new LightOnCustomEditor();
+ }
+
+ public void paintValue(Graphics g, Rectangle box)
+ {
+ //Linke Box: blau, Lampe ausgeschaltet
+ g.setColor(Color.blue);
+ g.fillRect(box.x, box.y, box.width / 2, box.height);
+ //Rechte Box: blau, Lampe angeschaltet
+ g.setColor(Color.yellow);
+ g.fillRect(box.x + box.width / 2, box.y, box.width / 2, box.height);
+ //Rahmen
+ g.setColor(Color.black);
+ for (int i = 0; i < 2; ++i) {
+ g.drawRect(
+ box.x + (currentvalue ? box.width / 2 : 0) + i,
+ box.y + i,
+ box.width / 2 - 1 - (2 * i),
+ box.height - 1 - (2 * i)
+ );
+ }
+ }
+
+ //---Private Klassen----------------------------------------
+ class LightOnCustomEditor
+ extends Canvas
+ {
+ public LightOnCustomEditor()
+ {
+ addMouseListener(
+ new MouseAdapter() {
+ public void mouseClicked(MouseEvent event)
+ {
+ currentvalue = (event.getX() > getSize().width / 2);
+ LightBulbLightOnEditor3.this.firePropertyChange();
+ repaint();
+ }
+ }
+ );
+ }
+
+ public void paint(Graphics g)
+ {
+ paintValue(g, new Rectangle(0, 0, getSize().width, getSize().height));
+ }
+
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(120, 60);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/LightedPushButton.java b/Master/Reference Architectures and Patterns/hjp5/examples/LightedPushButton.java new file mode 100644 index 0000000..1d63754 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/LightedPushButton.java @@ -0,0 +1,134 @@ +/* LightedPushButton.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import java.beans.*;
+
+public class LightedPushButton
+extends Canvas
+implements Serializable
+{
+ //---Instanzvariablen----------------------------------------
+ protected Color linecolor;
+ protected Color framecolor;
+ protected Color lightoncolor;
+ protected Color lightoffcolor;
+ protected boolean lighton;
+ transient protected PropertyChangeSupport pchglisteners;
+ transient protected VetoableChangeSupport vchglisteners;
+
+ //---Methoden------------------------------------------------
+ public LightedPushButton()
+ {
+ linecolor = Color.black;
+ framecolor = Color.darkGray;
+ lightoncolor = Color.red;
+ lightoffcolor = new Color(127, 0, 0); //dark red
+ lighton = false;
+ initTransientState();
+ }
+
+ //---Zustandsumschaltung Licht an/aus---
+ public void setLightOn(boolean on)
+ throws PropertyVetoException
+ {
+ boolean oldvalue = this.lighton;
+ vchglisteners.fireVetoableChange("lighton", oldvalue, on);
+ this.lighton = on;
+ if (oldvalue != on) {
+ repaint();
+ }
+ pchglisteners.firePropertyChange("lighton", oldvalue, on);
+ }
+
+ public boolean getLightOn()
+ {
+ return this.lighton;
+ }
+
+ //---Verwaltung der PropertyChangeListener---
+ public void addPropertyChangeListener(PropertyChangeListener l)
+ {
+ pchglisteners.addPropertyChangeListener(l);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener l)
+ {
+ pchglisteners.removePropertyChangeListener(l);
+ }
+
+ //---Verwaltung der VetoableChangeListener---
+ public void addVetoableChangeListener(VetoableChangeListener l)
+ {
+ vchglisteners.addVetoableChangeListener(l);
+ }
+
+ public void removeVetoableChangeListener(VetoableChangeListener l)
+ {
+ vchglisteners.removeVetoableChangeListener(l);
+ }
+
+ //---Implementierung der Oberfläche---
+ public void paint(Graphics g)
+ {
+ int width = getSize().width;
+ int height = getSize().height;
+ //Rahmen
+ g.setColor(framecolor);
+ g.fillOval(0, 0, width, height);
+ //Beleuchtung
+ g.setColor(lighton ? lightoncolor : lightoffcolor);
+ g.fillOval(4, 4, width - 8, height - 8);
+ //Konturlinien
+ g.setColor(linecolor);
+ g.drawOval(0, 0, width - 1, height - 1);
+ g.drawOval(3, 3, width - 7, height - 7);
+ }
+
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(32, 32);
+ }
+
+ public Dimension getMinimumSize()
+ {
+ return new Dimension(16, 16);
+ }
+
+ //---Private Klassen---------------------------------------
+ /**
+ * Initialisierung der nicht-persistenten Instanzvariablen.
+ */
+ private void initTransientState()
+ {
+ pchglisteners = new PropertyChangeSupport(this);
+ vchglisteners = new VetoableChangeSupport(this);
+ addMouseListener(new MouseClickAdapter());
+ }
+
+ /**
+ * Wird überlagert, um nach dem Deserialisieren den transienten
+ * Zustand zu initialisieren.
+ */
+ private void readObject(ObjectInputStream stream)
+ throws IOException, ClassNotFoundException
+ {
+ stream.defaultReadObject();
+ initTransientState();
+ }
+
+ //---Lokale Klassen----------------------------------------
+ class MouseClickAdapter
+ extends MouseAdapter
+ {
+ public void mouseClicked(MouseEvent event)
+ {
+ try {
+ setLightOn(!getLightOn());
+ } catch (PropertyVetoException e) {
+ //no change if vetoed
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Linien.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Linien.inc new file mode 100644 index 0000000..fa625cc --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Linien.inc @@ -0,0 +1,12 @@ +/* Linien.inc */
+
+public void paint(Graphics g)
+{
+ int i;
+ int x = 80;
+
+ for (i=0; i<60; ++i) {
+ g.drawLine(x,40,x,100);
+ x += 1+3*Math.random();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/List1.inc b/Master/Reference Architectures and Patterns/hjp5/examples/List1.inc new file mode 100644 index 0000000..027373e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/List1.inc @@ -0,0 +1,21 @@ +/* List1.inc */
+
+private void customizeLayout(Panel panel)
+{
+ panel.setLayout(new FlowLayout(FlowLayout.LEFT));
+ List list = new List(6,false);
+ list.addActionListener(this);
+ list.addItemListener(this);
+ list.add("Äpfel");
+ list.add("Birnen");
+ list.add("Bananen");
+ list.add("Pfirsiche");
+ list.add("Kirschen");
+ list.add("Kiwis");
+ list.add("Ananas");
+ list.add("Erdbeeren");
+ list.add("Blaubeeren");
+ list.add("Mandarinen");
+ panel.add(list);
+ list.select(1);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/List2.inc b/Master/Reference Architectures and Patterns/hjp5/examples/List2.inc new file mode 100644 index 0000000..a6b3ae4 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/List2.inc @@ -0,0 +1,22 @@ +/* List2.inc */
+
+public void itemStateChanged(ItemEvent event)
+{
+ List list = (List) event.getItemSelectable();
+ String str1 = list.getSelectedItem();
+ int pos = ((Integer) event.getItem()).intValue();
+ System.out.println("list.getSelectedItem: " + str1);
+ System.out.println("event.getItem: " + pos);
+}
+
+public void actionPerformed(ActionEvent event)
+{
+ Object obj = event.getSource();
+ if (obj instanceof List) {
+ System.out.println("ListAction: "+event.getActionCommand());
+ } else if (obj instanceof Button) {
+ if (event.getActionCommand().equals("Ende")) {
+ endDialog();
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0202.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0202.java new file mode 100644 index 0000000..ce1045e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0202.java @@ -0,0 +1,9 @@ +/* Listing0202.java */
+
+public class Listing0202
+{
+ public static void main(String[] args)
+ {
+ System.out.println("1+2=" + (1+2));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0203.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0203.java new file mode 100644 index 0000000..b3afc79 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0203.java @@ -0,0 +1,22 @@ +/* Listing0203.java */
+
+import java.util.Scanner;
+import java.io.IOException;
+
+public class Listing0203
+{
+ public static void main(String[] args)
+ throws IOException
+ {
+ int a, b, c;
+
+ Scanner scanner = new Scanner(System.in);
+
+ System.out.println("Bitte a eingeben: ");
+ a = scanner.nextInt();
+ System.out.println("Bitte b eingeben: ");
+ b = scanner.nextInt();
+ c = a + b;
+ System.out.println("a+b="+c);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0402.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0402.java new file mode 100644 index 0000000..d6be514 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0402.java @@ -0,0 +1,17 @@ +/* Listing0402.java */
+
+public class Listing0402
+{
+ public static void main(String[] args)
+ {
+ int a;
+ a = 1;
+ char b = 'x';
+ System.out.println(a);
+ double c = 3.1415;
+ System.out.println(b);
+ System.out.println(c);
+ boolean d = false;
+ System.out.println(d);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0408.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0408.java new file mode 100644 index 0000000..7abb098 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0408.java @@ -0,0 +1,25 @@ +/* Listing0408.java */
+
+public class Listing0408
+{
+ public static void main(String[] args)
+ {
+ int[] prim = new int[5];
+ boolean[] b = {true,false};
+ prim[0] = 2;
+ prim[1] = 3;
+ prim[2] = 5;
+ prim[3] = 7;
+ prim[4] = 11;
+
+ System.out.println("prim hat "+prim.length+" Elemente");
+ System.out.println("b hat "+b.length+" Elemente");
+ System.out.println(prim[0]);
+ System.out.println(prim[1]);
+ System.out.println(prim[2]);
+ System.out.println(prim[3]);
+ System.out.println(prim[4]);
+ System.out.println(b[0]);
+ System.out.println(b[1]);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0409.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0409.java new file mode 100644 index 0000000..579a37c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0409.java @@ -0,0 +1,18 @@ +/* Listing0409.java */
+
+public class Listing0409
+{
+ public static void main(String[] args)
+ {
+ int[][] a = new int[2][3];
+
+ a[0][0] = 1;
+ a[0][1] = 2;
+ a[0][2] = 3;
+ a[1][0] = 4;
+ a[1][1] = 5;
+ a[1][2] = 6;
+ System.out.println(""+a[0][0]+a[0][1]+a[0][2]);
+ System.out.println(""+a[1][0]+a[1][1]+a[1][2]);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0410.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0410.java new file mode 100644 index 0000000..27e7cad --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0410.java @@ -0,0 +1,19 @@ +/* Listing0410.java */
+
+public class Listing0410
+{
+ public static void main(String[] args)
+ {
+ int[][] a = { {0},
+ {1,2},
+ {3,4,5},
+ {6,7,8,9}
+ };
+ for (int i=0; i<a.length; ++i) {
+ for (int j=0; j<a[i].length; ++j) {
+ System.out.print(a[i][j]);
+ }
+ System.out.println();
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0413.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0413.java new file mode 100644 index 0000000..850af53 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0413.java @@ -0,0 +1,16 @@ +/* Listing0413 */
+
+public class Listing0413
+{
+ public static void main(String[] args)
+ {
+ for (int i = 0; i < 256; ++i) {
+ System.out.print("i=" + i);
+ byte b = ByteKit.fromUnsignedInt(i);
+ System.out.print(" b=" + ByteKit.toBitString(b));
+ char c = ByteKit.toChar(b);
+ System.out.print(" c=" + (c >= 32 ? c : '.'));
+ System.out.println();
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0503.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0503.java new file mode 100644 index 0000000..5a5db89 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0503.java @@ -0,0 +1,13 @@ +/* Listing0503.java */
+
+public class Listing0503
+{
+ public static void main(String[] args)
+ {
+ int a = 5;
+ double x = 3.14;
+
+ System.out.println("a = " + a);
+ System.out.println("x = " + x);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0504.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0504.java new file mode 100644 index 0000000..126badd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0504.java @@ -0,0 +1,11 @@ +/* Listing0504.java */
+
+public class Listing0504
+{
+ public static void main(String[] args)
+ {
+ // Die +-Operatoren werden von innen nach außen und von
+ // links nach rechts ausgewertet
+ System.out.println("3 + 4 = " + 3 + 4);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0505.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0505.java new file mode 100644 index 0000000..0d4c92c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0505.java @@ -0,0 +1,11 @@ +/* Listing0505.java */
+
+public class Listing0505
+{
+ public static void main(String[] args)
+ {
+ // Die +-Operatoren werden von innen nach außen und von
+ // links nach rechts ausgewertet
+ System.out.println("3 + 4 = " + (3 + 4));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0506.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0506.java new file mode 100644 index 0000000..4372510 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0506.java @@ -0,0 +1,12 @@ +/* Listing0506.java */
+
+public class Listing0506
+{
+ public static void main(String[] args)
+ {
+ String a = new String("hallo");
+ String b = new String("hallo");
+ System.out.println("a == b liefert " + (a == b));
+ System.out.println("a != b liefert " + (a != b));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0507.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0507.java new file mode 100644 index 0000000..211c50e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0507.java @@ -0,0 +1,11 @@ +/* Listing0507.java */
+
+public class Listing0507
+{
+ public static void main(String[] args)
+ {
+ String a = new String("hallo");
+ String b = new String("hallo");
+ System.out.println("a.equals(b) liefert " + a.equals(b));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0509.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0509.java new file mode 100644 index 0000000..4b120f5 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0509.java @@ -0,0 +1,15 @@ +/* Listing0509.java */
+
+public class Listing0509
+{
+ public static void main(String[] args)
+ {
+ int i = 55;
+ int j = 97;
+ if ((i & 15) < (j & 15)) {
+ System.out.println("LowByte(55) < LowByte(97)");
+ } else {
+ System.out.println("LowByte(55) >= LowByte(97)");
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0606.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0606.java new file mode 100644 index 0000000..d5cd353 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0606.java @@ -0,0 +1,29 @@ +/* Listing0606.java */
+
+import java.io.*;
+
+public class Listing0606
+{
+ public static void main(String[] args)
+ {
+ int[][] data = new int[10][10];
+
+ //Multiplikationstafel erstellen
+ for (int i = 1; i <= 10; ++i) {
+ for (int j = 1; j <= 10; ++j) {
+ data[i - 1][j - 1] = i * j;
+ }
+ }
+
+ //Produkt größer 43 suchen
+ loop1:
+ for (int i = 1; i <= 10; ++i) {
+ for (int j = 1; j <= 10; ++j) {
+ if (data[i - 1][j - 1] > 43) {
+ System.out.println(i + "*" + j + "=" + (i*j));
+ break loop1;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0712.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0712.java new file mode 100644 index 0000000..d42bf24 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0712.java @@ -0,0 +1,29 @@ +/* Listing0712.java */
+
+public class Listing0712
+{
+ public static void registrierKasse(Object... args)
+ {
+ double zwischensumme = 0;
+ double gesamtsumme = 0;
+ for (int i = 0; i < args.length; ++i) {
+ if (args[i] instanceof Number) {
+ zwischensumme += ((Number)args[i]).doubleValue();
+ } else {
+ System.out.println(args[i] + ": " + zwischensumme);
+ gesamtsumme += zwischensumme;
+ zwischensumme = 0;
+ }
+ }
+ System.out.println("Gesamtsumme: " + gesamtsumme);
+ }
+
+ public static void main(String[] args)
+ {
+ registrierKasse(
+ 1.45, 0.79, 19.90, "Ware",
+ -3.00, 1.50, "Pfand",
+ -10, "Gutschein"
+ );
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0718.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0718.java new file mode 100644 index 0000000..9ca5a50 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0718.java @@ -0,0 +1,36 @@ +/* Listing0718.java */
+
+public class Listing0718
+{
+ public static String getAndPrint(String s)
+ {
+ System.out.println(s);
+ return s;
+ }
+
+ public static void main(String[] args)
+ {
+ Son son = new Son();
+ }
+}
+
+class Father
+{
+ private String s1 = Listing0718.getAndPrint("Father.s1");
+
+ public Father()
+ {
+ Listing0718.getAndPrint("Father.<init>");
+ }
+}
+
+class Son
+extends Father
+{
+ private String s1 = Listing0718.getAndPrint("Son.s1");
+
+ public Son()
+ {
+ Listing0718.getAndPrint("Son.<init>");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0806.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0806.java new file mode 100644 index 0000000..e861322 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0806.java @@ -0,0 +1,33 @@ +/* Listing0806.java */
+
+public class Listing0806
+{
+ public static void main(String[] args)
+ {
+ ClassWithPrivateA a1 = new ClassWithPrivateA(7);
+ ClassWithPrivateA a2 = new ClassWithPrivateA(11);
+ a2.setOtherA(a1, 999);
+ System.out.println("a1 = " + a1.toString());
+ System.out.println("a2 = " + a2.toString());
+ }
+}
+
+class ClassWithPrivateA
+{
+ private int a;
+
+ public ClassWithPrivateA(int a)
+ {
+ this.a = a;
+ }
+
+ public void setOtherA(ClassWithPrivateA other, int newvalue)
+ {
+ other.a = newvalue;
+ }
+
+ public String toString()
+ {
+ return "" + a;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0809.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0809.java new file mode 100644 index 0000000..eeeec36 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0809.java @@ -0,0 +1,13 @@ +/* Listing0809.java */
+
+public class Listing0809
+{
+ public static void main(String[] args)
+ {
+ double x, y;
+ for (x = 0.0; x <= 10.0; x = x + 1.0) {
+ y = Math.sqrt(x);
+ System.out.println("sqrt("+x+") = "+y);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0813.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0813.java new file mode 100644 index 0000000..9309a46 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0813.java @@ -0,0 +1,44 @@ +/* Listing0813.java */
+
+class SingleValue
+{
+ protected int value1;
+
+ public SingleValue(int value1)
+ {
+ this.value1 = value1;
+ print();
+ }
+
+ public void print()
+ {
+ System.out.println("value = " + value1);
+ }
+}
+
+class ValuePair
+extends SingleValue
+{
+ protected int value2;
+
+ public ValuePair(int value1, int value2)
+ {
+ super(value1);
+ this.value2 = value2;
+ }
+
+ public void print()
+ {
+ System.out.println(
+ "value = (" + value1 + "," + value2 + ")"
+ );
+ }
+}
+
+public class Listing0813
+{
+ public static void main(String[] args)
+ {
+ new ValuePair(10,20);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0905.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0905.java new file mode 100644 index 0000000..8f84d86 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0905.java @@ -0,0 +1,27 @@ +/* Listing0905.java */
+
+public class Listing0905
+{
+ public static long grundflaeche(Groesse g)
+ {
+ return (long)g.laenge() * g.breite();
+ }
+
+ public static void main(String[] args)
+ {
+ //Zuerst erzeugen wir ein Auto2...
+ Auto2 auto = new Auto2();
+ auto.laenge = 4235;
+ auto.hoehe = 1650;
+ auto.breite = 1820;
+ //Nun ein DIN A4-Blatt...
+ PapierBlatt blatt = new PapierBlatt();
+ blatt.format = 4;
+ //Und zum Schluß einen Fußballplatz...
+ FussballPlatz platz = new FussballPlatz();
+ //Nun werden sie ausgegeben
+ System.out.println("Auto: " + grundflaeche(auto));
+ System.out.println("Blatt: " + grundflaeche(blatt));
+ System.out.println("Platz: " + grundflaeche(platz));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0907.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0907.java new file mode 100644 index 0000000..1b83b14 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0907.java @@ -0,0 +1,49 @@ +/* Listing0907.java */
+
+public class Listing0907
+{
+ public static Object getSmallest(Comparable[] objects)
+ {
+ Object smallest = objects[0];
+ for (int i = 1; i < objects.length; ++i) {
+ if (objects[i].compareTo(smallest) < 0) {
+ smallest = objects[i];
+ }
+ }
+ return smallest;
+ }
+
+ public static void bubbleSort(Comparable[] objects)
+ {
+ boolean sorted;
+ do {
+ sorted = true;
+ for (int i = 0; i < objects.length - 1; ++i) {
+ if (objects[i].compareTo(objects[i + 1]) > 0) {
+ Comparable tmp = objects[i];
+ objects[i] = objects[i + 1];
+ objects[i + 1] = tmp;
+ sorted = false;
+ }
+ }
+ } while (!sorted);
+ }
+
+ public static void main(String[] args)
+ {
+ //Erzeugen eines String-Arrays
+ Comparable[] objects = new Comparable[4];
+ objects[0] = "STRINGS";
+ objects[1] = "SIND";
+ objects[2] = "PAARWEISE";
+ objects[3] = "VERGLEICHBAR";
+ //Ausgeben des kleinsten Elements
+ System.out.println((String)getSmallest(objects));
+ System.out.println("--");
+ //Sortieren und Ausgaben
+ bubbleSort(objects);
+ for (int i = 0; i < objects.length; ++i) {
+ System.out.println((String)objects[i]);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0910.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0910.java new file mode 100644 index 0000000..f4bc403 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0910.java @@ -0,0 +1,33 @@ +/* Listing0910.java */
+
+interface EinDimensional
+{
+ public int laenge();
+}
+
+interface ZweiDimensional
+extends EinDimensional
+{
+ public int breite();
+}
+
+interface DreiDimensional
+extends ZweiDimensional
+{
+ public int hoehe();
+}
+
+interface VierDimensional
+extends DreiDimensional
+{
+ public int lebensdauer();
+}
+
+public class Listing0910
+implements VierDimensional
+{
+ public int laenge() { return 0; }
+ public int breite() { return 0; }
+ public int hoehe() { return 0; }
+ public int lebensdauer() { return 0; }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0911.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0911.java new file mode 100644 index 0000000..86e89c2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0911.java @@ -0,0 +1,26 @@ +/* Listing0911.java */
+
+interface Debug
+{
+ public static final boolean FUNCTIONALITY1 = false;
+ public static final boolean FUNCTIONALITY2 = true;
+ public static final boolean FUNCTIONALITY3 = false;
+ public static final boolean FUNCTIONALITY4 = false;
+}
+
+public class Listing0911
+implements Debug
+{
+ public static void main(String[] args)
+ {
+ //...
+ if (FUNCTIONALITY1) {
+ System.out.println("...");
+ }
+ //...
+ if (FUNCTIONALITY2) {
+ System.out.println("...");
+ }
+ //...
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0912.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0912.java new file mode 100644 index 0000000..4e64409 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0912.java @@ -0,0 +1,12 @@ +/* Listing0912.java */
+
+import static java.lang.Math.*;
+
+public class Listing0912
+{
+ public static void main(String[] args)
+ {
+ System.out.println(sqrt(2));
+ System.out.println(sin(PI));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing0915.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0915.java new file mode 100644 index 0000000..45aae85 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing0915.java @@ -0,0 +1,56 @@ +/* Listing0915.java */
+
+class MathExp
+implements DoubleMethod
+{
+ public double compute(double value)
+ {
+ return Math.exp(value);
+ }
+}
+
+class MathSqrt
+implements DoubleMethod
+{
+ public double compute(double value)
+ {
+ return Math.sqrt(value);
+ }
+}
+
+class Times2
+implements DoubleMethod
+{
+ public double compute(double value)
+ {
+ return 2 * value;
+ }
+}
+
+class Sqr
+implements DoubleMethod
+{
+ public double compute(double value)
+ {
+ return value * value;
+ }
+}
+
+public class Listing0915
+{
+ public static void printTable(DoubleMethod meth)
+ {
+ System.out.println("Wertetabelle " + meth.toString());
+ for (double x = 0.0; x <= 5.0; x += 1) {
+ System.out.println(" " + x + "->" + meth.compute(x));
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ printTable(new Times2());
+ printTable(new MathExp());
+ printTable(new Sqr());
+ printTable(new MathSqrt());
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1001.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1001.java new file mode 100644 index 0000000..71318bc --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1001.java @@ -0,0 +1,35 @@ +/* Listing1001.java */
+
+class Outer
+{
+ String name;
+ int number;
+
+ public void createAndPrintInner(String iname)
+ {
+ Inner inner = new Inner();
+ inner.name = iname;
+ System.out.println(inner.getQualifiedName());
+ }
+
+ class Inner
+ {
+ private String name;
+
+ private String getQualifiedName()
+ {
+ return number + ":" + Outer.this.name + "." + name;
+ }
+ }
+}
+
+public class Listing1001
+{
+ public static void main(String[] args)
+ {
+ Outer outer = new Outer();
+ outer.name = "Outer";
+ outer.number = 77;
+ outer.createAndPrintInner("Inner");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1002.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1002.java new file mode 100644 index 0000000..69e2e1c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1002.java @@ -0,0 +1,29 @@ +/* Listing1002.java */
+
+class Outer2
+{
+ public void print()
+ {
+ final int value = 10;
+
+ class Inner2
+ {
+ public void print()
+ {
+ System.out.println("value = " + value);
+ }
+ }
+
+ Inner2 inner = new Inner2();
+ inner.print();
+ }
+}
+
+public class Listing1002
+{
+ public static void main(String[] args)
+ {
+ Outer2 outer = new Outer2();
+ outer.print();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1003.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1003.java new file mode 100644 index 0000000..d9b9ea9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1003.java @@ -0,0 +1,25 @@ +/* Listing1003.java */
+
+public class Listing1003
+{
+ public static void printTable(DoubleMethod meth)
+ {
+ System.out.println("Wertetabelle " + meth.toString());
+ for (double x = 0.0; x <= 5.0; x += 1) {
+ System.out.println(" " + x + "->" + meth.compute(x));
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ printTable(
+ new DoubleMethod()
+ {
+ public double compute(double value)
+ {
+ return Math.sqrt(value);
+ }
+ }
+ );
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1004.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1004.java new file mode 100644 index 0000000..4c51207 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1004.java @@ -0,0 +1,21 @@ +/* Listing1004.java */
+
+class Outer3
+{
+ static class Inner3
+ {
+ public void print()
+ {
+ System.out.println("Inner3");
+ }
+ }
+}
+
+public class Listing1004
+{
+ public static void main(String[] args)
+ {
+ Outer3.Inner3 inner = new Outer3.Inner3();
+ inner.print();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1005.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1005.java new file mode 100644 index 0000000..1795fa7 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1005.java @@ -0,0 +1,16 @@ +/* Listing1005.java */
+
+public class Listing1005
+{
+ public static void ohneAutoboxing(int arg)
+ {
+ Integer i = new Integer(arg);
+ int j = i.intValue() + 1;
+ System.out.println(i + " " + j);
+ }
+
+ public static void main(String[] args)
+ {
+ ohneAutoboxing(17);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1006.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1006.java new file mode 100644 index 0000000..01fabbf --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1006.java @@ -0,0 +1,38 @@ +/* Listing1006.java */
+
+class IntWrapper
+{
+ public int value;
+
+ public IntWrapper(int value)
+ {
+ this.value = value;
+ }
+}
+
+public class Listing1006
+{
+ public static void inc1(IntWrapper w)
+ {
+ ++w.value;
+ }
+
+ public static void inc2(int[] i)
+ {
+ ++i[0];
+ }
+
+ public static void main(String[] args)
+ {
+ //Variante 1: Übergabe in einem veränderlichen Wrapper
+ IntWrapper i = new IntWrapper(10);
+ System.out.println("i = " + i.value);
+ inc1(i);
+ System.out.println("i = " + i.value);
+ //Variante 2: Übergabe als Array-Element
+ int[] j = new int[] {10};
+ System.out.println("j = " + j[0]);
+ inc2(j);
+ System.out.println("j = " + j[0]);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1007.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1007.java new file mode 100644 index 0000000..592aa3e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1007.java @@ -0,0 +1,16 @@ +/* Listing1007.java */
+
+public class Listing1007
+{
+ public static void mitAutoboxing(int arg)
+ {
+ Integer i = arg;
+ int j = i + 1;
+ System.out.println(i + " " + j);
+ }
+
+ public static void main(String[] args)
+ {
+ mitAutoboxing(new Integer(17));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1008.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1008.java new file mode 100644 index 0000000..bcaa0c6 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1008.java @@ -0,0 +1,49 @@ +/* Listing1008.java */
+
+public class Listing1008
+{
+ enum Farbe {ROT, GRUEN, BLAU, GELB};
+
+ public static void farbVergleich(Farbe f1, Farbe f2)
+ {
+ System.out.print(f1);
+ System.out.print(f1.equals(f2) ? " = " : " != ");
+ System.out.println(f2);
+ }
+
+ public static String toRGB(Farbe f)
+ {
+ String ret = "?";
+ switch (f) {
+ case ROT: ret = "(255,0,0)"; break;
+ case GRUEN: ret = "(0,255,0)"; break;
+ case BLAU: ret = "(0,0,255)"; break;
+ case GELB: ret = "(255,255,0)"; break;
+ }
+ return ret;
+ }
+
+ public static void main(String[] args)
+ {
+ //Aufzählungsvariablen
+ Farbe f1 = Farbe.ROT;
+ Farbe f2 = Farbe.BLAU;
+ Farbe f3 = Farbe.ROT;
+ //toString() liefert den Namen
+ System.out.println("--");
+ System.out.println(f1);
+ System.out.println(f2);
+ System.out.println(f3);
+ //equals funktioniert auch
+ System.out.println("--");
+ farbVergleich(f1, f2);
+ farbVergleich(f1, f3);
+ farbVergleich(f2, f3);
+ farbVergleich(f1, f1);
+ //Die Methode values()
+ System.out.println("--");
+ for (Farbe f : Farbe.values()) {
+ System.out.println(f + "=" + toRGB(f));
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1014.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1014.java new file mode 100644 index 0000000..bbc6fe3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1014.java @@ -0,0 +1,111 @@ +/* Listing1014.java */
+
+//------------------------------------------------------------------
+//Abstrakte Produkte
+//------------------------------------------------------------------
+abstract class Product1
+{
+}
+
+abstract class Product2
+{
+}
+
+//------------------------------------------------------------------
+//Abstrakte Factory
+//------------------------------------------------------------------
+abstract class ProductFactory
+{
+ public abstract Product1 createProduct1();
+
+ public abstract Product2 createProduct2();
+
+ public static ProductFactory getFactory(String variant)
+ {
+ ProductFactory ret = null;
+ if (variant.equals("A")) {
+ ret = new ConcreteFactoryVariantA();
+ } else if (variant.equals("B")) {
+ ret = new ConcreteFactoryVariantB();
+ }
+ return ret;
+ }
+
+ public static ProductFactory getDefaultFactory()
+ {
+ return getFactory("A");
+ }
+}
+
+//------------------------------------------------------------------
+//Konkrete Produkte für Implementierungsvariante A
+//------------------------------------------------------------------
+class Product1VariantA
+extends Product1
+{
+}
+
+class Product2VariantA
+extends Product2
+{
+}
+
+//------------------------------------------------------------------
+//Konkrete Factory für Implementierungsvariante A
+//------------------------------------------------------------------
+class ConcreteFactoryVariantA
+extends ProductFactory
+{
+ public Product1 createProduct1()
+ {
+ return new Product1VariantA();
+ }
+
+ public Product2 createProduct2()
+ {
+ return new Product2VariantA();
+ }
+}
+
+//------------------------------------------------------------------
+//Konkrete Produkte für Implementierungsvariante B
+//------------------------------------------------------------------
+class Product1VariantB
+extends Product1
+{
+}
+
+class Product2VariantB
+extends Product2
+{
+}
+
+//------------------------------------------------------------------
+//Konkrete Factory für Implementierungsvariante B
+//------------------------------------------------------------------
+class ConcreteFactoryVariantB
+extends ProductFactory
+{
+ public Product1 createProduct1()
+ {
+ return new Product1VariantB();
+ }
+
+ public Product2 createProduct2()
+ {
+ return new Product2VariantB();
+ }
+}
+
+//------------------------------------------------------------------
+//Beispielanwendung
+//------------------------------------------------------------------
+public class Listing1014
+{
+ public static void main(String[] args)
+ {
+ ProductFactory fact = ProductFactory.getDefaultFactory();
+ Product1 prod1 = fact.createProduct1();
+ Product2 prod2 = fact.createProduct2();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1015.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1015.java new file mode 100644 index 0000000..388a152 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1015.java @@ -0,0 +1,49 @@ +/* Listing1015.java */
+
+interface StringIterator
+{
+ public boolean hasNext();
+ public String next();
+}
+
+class StringArray
+{
+ String[] data;
+
+ public StringArray(String[] data)
+ {
+ this.data = data;
+ }
+
+ public StringIterator getElements()
+ {
+ return new StringIterator()
+ {
+ int index = 0;
+ public boolean hasNext()
+ {
+ return index < data.length;
+ }
+ public String next()
+ {
+ return data[index++];
+ }
+ };
+ }
+}
+
+public class Listing1015
+{
+ static final String[] SAYHI = {"Hi", "Iterator", "Buddy"};
+
+ public static void main(String[] args)
+ {
+ //Collection erzeugen
+ StringArray strar = new StringArray(SAYHI);
+ //Iterator beschaffen und Elemente durchlaufen
+ StringIterator it = strar.getElements();
+ while (it.hasNext()) {
+ System.out.println(it.next());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1016.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1016.java new file mode 100644 index 0000000..0d80613 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1016.java @@ -0,0 +1,79 @@ +/* Listing1016.java */
+
+class Delegate
+{
+ private Delegator delegator;
+
+ public Delegate(Delegator delegator)
+ {
+ this.delegator = delegator;
+ }
+
+ public void service1()
+ {
+ }
+
+ public void service2()
+ {
+ }
+}
+
+interface Delegator
+{
+ public void commonDelegatorServiceA();
+ public void commonDelegatorServiceB();
+}
+
+class Client1
+implements Delegator
+{
+ private Delegate delegate;
+
+ public Client1()
+ {
+ delegate = new Delegate(this);
+ }
+
+ public void service1()
+ {
+ //implementiert einen Service und benutzt
+ //dazu eigene Methoden und die des
+ //Delegate-Objekts
+ }
+
+ public void commonDelegatorServiceA()
+ {
+ }
+
+ public void commonDelegatorServiceB()
+ {
+ }
+}
+
+class Client2
+implements Delegator
+{
+ private Delegate delegate;
+
+ public Client2()
+ {
+ delegate = new Delegate(this);
+ }
+
+ public void commonDelegatorServiceA()
+ {
+ }
+
+ public void commonDelegatorServiceB()
+ {
+ }
+}
+
+public class Listing1016
+{
+ public static void main(String[] args)
+ {
+ Client1 client = new Client1();
+ client.service1();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1017.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1017.java new file mode 100644 index 0000000..78f572c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1017.java @@ -0,0 +1,89 @@ +/* Listing1017.java */
+
+class MenuEntry1
+{
+ protected String name;
+
+ public MenuEntry1(String name)
+ {
+ this.name = name;
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+}
+
+class IconizedMenuEntry1
+extends MenuEntry1
+{
+ private String iconName;
+
+ public IconizedMenuEntry1(String name, String iconName)
+ {
+ super(name);
+ this.iconName = iconName;
+ }
+}
+
+class CheckableMenuEntry1
+extends MenuEntry1
+{
+ private boolean checked;
+
+ public CheckableMenuEntry1(String name, boolean checked)
+ {
+ super(name);
+ this.checked = checked;
+ }
+}
+
+class Menu1
+extends MenuEntry1
+{
+ MenuEntry1[] entries;
+ int entryCnt;
+
+ public Menu1(String name, int maxElements)
+ {
+ super(name);
+ this.entries = new MenuEntry1[maxElements];
+ entryCnt = 0;
+ }
+
+ public void add(MenuEntry1 entry)
+ {
+ entries[entryCnt++] = entry;
+ }
+
+ public String toString()
+ {
+ String ret = "(";
+ for (int i = 0; i < entryCnt; ++i) {
+ ret += (i != 0 ? "," : "") + entries[i].toString();
+ }
+ return ret + ")";
+ }
+}
+
+public class Listing1017
+{
+ public static void main(String[] args)
+ {
+ Menu1 filemenu = new Menu1("Datei", 5);
+ filemenu.add(new MenuEntry1("Neu"));
+ filemenu.add(new MenuEntry1("Laden"));
+ filemenu.add(new MenuEntry1("Speichern"));
+
+ Menu1 confmenu = new Menu1("Konfiguration", 3);
+ confmenu.add(new MenuEntry1("Farben"));
+ confmenu.add(new MenuEntry1("Fenster"));
+ confmenu.add(new MenuEntry1("Pfade"));
+ filemenu.add(confmenu);
+
+ filemenu.add(new MenuEntry1("Beenden"));
+
+ System.out.println(filemenu.toString());
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1018.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1018.java new file mode 100644 index 0000000..8613621 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1018.java @@ -0,0 +1,106 @@ +/* Listing1018.java */
+
+interface MenuVisitor
+{
+ abstract void visitMenuEntry(MenuEntry2 entry);
+ abstract void visitMenuStarted(Menu2 menu);
+ abstract void visitMenuEnded(Menu2 menu);
+}
+
+class MenuEntry2
+{
+ protected String name;
+
+ public MenuEntry2(String name)
+ {
+ this.name = name;
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+
+ public void accept(MenuVisitor visitor)
+ {
+ visitor.visitMenuEntry(this);
+ }
+}
+
+class Menu2
+extends MenuEntry2
+{
+ MenuEntry2[] entries;
+ int entryCnt;
+
+ public Menu2(String name, int maxElements)
+ {
+ super(name);
+ this.entries = new MenuEntry2[maxElements];
+ entryCnt = 0;
+ }
+
+ public void add(MenuEntry2 entry)
+ {
+ entries[entryCnt++] = entry;
+ }
+
+ public String toString()
+ {
+ String ret = "(";
+ for (int i = 0; i < entryCnt; ++i) {
+ ret += (i != 0 ? "," : "") + entries[i].toString();
+ }
+ return ret + ")";
+ }
+
+ public void accept(MenuVisitor visitor)
+ {
+ visitor.visitMenuStarted(this);
+ for (int i = 0; i < entryCnt; ++i) {
+ entries[i].accept(visitor);
+ }
+ visitor.visitMenuEnded(this);
+ }
+}
+
+class MenuPrintVisitor
+implements MenuVisitor
+{
+ String indent = "";
+
+ public void visitMenuEntry(MenuEntry2 entry)
+ {
+ System.out.println(indent + entry.name);
+ }
+
+ public void visitMenuStarted(Menu2 menu)
+ {
+ System.out.println(indent + menu.name);
+ indent += " ";
+ }
+
+ public void visitMenuEnded(Menu2 menu)
+ {
+ indent = indent.substring(1);
+ }
+}
+
+public class Listing1018
+{
+ public static void main(String[] args)
+ {
+ Menu2 filemenu = new Menu2("Datei", 5);
+ filemenu.add(new MenuEntry2("Neu"));
+ filemenu.add(new MenuEntry2("Laden"));
+ filemenu.add(new MenuEntry2("Speichern"));
+ Menu2 confmenu = new Menu2("Konfiguration", 3);
+ confmenu.add(new MenuEntry2("Farben"));
+ confmenu.add(new MenuEntry2("Fenster"));
+ confmenu.add(new MenuEntry2("Pfade"));
+ filemenu.add(confmenu);
+ filemenu.add(new MenuEntry2("Beenden"));
+
+ filemenu.accept(new MenuPrintVisitor());
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1019.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1019.java new file mode 100644 index 0000000..4784334 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1019.java @@ -0,0 +1,81 @@ +/* Listing1019.java */
+
+interface Observer
+{
+ public void update(Subject subject);
+}
+
+class Subject
+{
+ Observer[] observers = new Observer[5];
+ int observerCnt = 0;
+
+ public void attach(Observer observer)
+ {
+ observers[observerCnt++] = observer;
+ }
+
+ public void detach(Observer observer)
+ {
+ for (int i = 0; i < observerCnt; ++i) {
+ if (observers[i] == observer) {
+ --observerCnt;
+ for (;i < observerCnt; ++i) {
+ observers[i] = observers[i + 1];
+ }
+ break;
+ }
+ }
+ }
+
+ public void fireUpdate()
+ {
+ for (int i = 0; i < observerCnt; ++i) {
+ observers[i].update(this);
+ }
+ }
+}
+
+class Counter
+{
+ int cnt = 0;
+ Subject subject = new Subject();
+
+ public void attach(Observer observer)
+ {
+ subject.attach(observer);
+ }
+
+ public void detach(Observer observer)
+ {
+ subject.detach(observer);
+ }
+
+ public void inc()
+ {
+ if (++cnt % 3 == 0) {
+ subject.fireUpdate();
+ }
+ }
+}
+
+public class Listing1019
+{
+ public static void main(String[] args)
+ {
+ Counter counter = new Counter();
+ counter.attach(
+ new Observer()
+ {
+ public void update(Subject subject)
+ {
+ System.out.print("divisible by 3: ");
+ }
+ }
+ );
+ while (counter.cnt < 10) {
+ counter.inc();
+ System.out.println(counter.cnt);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1101.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1101.java new file mode 100644 index 0000000..721b190 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1101.java @@ -0,0 +1,18 @@ +/* Listing1101.java */
+
+public class Listing1101
+{
+ public static void main(String[] args)
+ {
+ String s1;
+ s1 = "Auf der Mauer";
+ s1 += ", auf der Lauer";
+ s1 += ", sitzt \'ne kleine Wanze";
+ System.out.println(s1);
+
+ for (int i = 1; i <= 5; ++i) {
+ s1 = s1.substring(0,s1.length()-1);
+ System.out.println(s1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1102.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1102.java new file mode 100644 index 0000000..e6c162c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1102.java @@ -0,0 +1,24 @@ +/* Listing1102.java */
+
+public class Listing1102
+{
+ public static void main(String[] args)
+ {
+ System.out.println(
+ "Grüße aus Hamburg".regionMatches(
+ 8,
+ "Greetings from Australia",
+ 8,
+ 2
+ )
+ );
+ System.out.println(
+ "Grüße aus Hamburg".regionMatches(
+ 6,
+ "Greetings from Australia",
+ 15,
+ 3
+ )
+ );
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1103.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1103.java new file mode 100644 index 0000000..9bed2a5 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1103.java @@ -0,0 +1,13 @@ +/* Listing1103.java */
+
+public class Listing1103
+{
+ public static void main(String[] args)
+ {
+ String satz = "Dies ist nur ein Test";
+ String[] result = satz.split("\\s");
+ for (int x=0; x<result.length; x++) {
+ System.out.println(result[x]);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1104.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1104.java new file mode 100644 index 0000000..338e8e0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1104.java @@ -0,0 +1,21 @@ +/* Listing1104.java */
+
+public class Listing1104
+{
+ public static void main(String[] args)
+ {
+ String a, b, c;
+
+ //Konventionelle Verkettung
+ a = "Hallo";
+ b = "Welt";
+ c = a + ", " + b;
+ System.out.println(c);
+
+ //So könnte es der Compiler übersetzen
+ a = "Hallo";
+ b = "Welt";
+ c =(new StringBuilder(a)).append(", ").append(b).toString();
+ System.out.println(c);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1105.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1105.java new file mode 100644 index 0000000..4ca1750 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1105.java @@ -0,0 +1,10 @@ +/* Listing1105.java */
+
+public class Listing1105
+{
+ public void out(CharSequence text)
+ {
+ // Ausgabe einer beliebigen
+ System.out.println("Ausgabe: " + text);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1106.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1106.java new file mode 100644 index 0000000..c0eabea --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1106.java @@ -0,0 +1,11 @@ +/* Listing1106.java */
+
+public class Listing1106
+{
+ public static void main(String[] args)
+ {
+ for (int i = 5; i < 199; i += 37) {
+ System.out.format("Aktueller Wert: %3d%n", i);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1107.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1107.java new file mode 100644 index 0000000..9562b55 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1107.java @@ -0,0 +1,36 @@ +/* Listing1107.java */
+
+import java.util.*;
+
+public class Listing1107
+{
+ public static void main(String[] args)
+ {
+ //Boolesche Werte
+ System.out.format("%b %b %2$b %1$b%n", true, false);
+ //Ganzzahlen
+ System.out.format("[%d]%n", -2517);
+ System.out.format("[%7d]%n", -2517);
+ System.out.format("[%-7d]%n", -2517);
+ System.out.format("[%(7d]%n", -2517);
+ System.out.format("[%07d]%n", -2517);
+ System.out.format("[%,7d]%n", -2517);
+ System.out.format("%1$d %<o %<x %<X%n", 127);
+ //Fließkommazahlen
+ System.out.format("%f%n", 0.000314);
+ System.out.format("%1$6.2f %1$6.2e %1$6.2E %1$6.2G%n", 3.141592);
+ System.out.format("%,8.2f%n", 31415.92);
+ System.out.format(Locale.ENGLISH, "%,8.2f%n", 31415.92);
+ //Zeichen und Strings
+ System.out.format("%c%c%c\n", 97, 64, 98);
+ System.out.format("%s nein\n", "ja");
+ //Datum/Uhrzeit
+ Calendar now = Calendar.getInstance();
+ System.out.format(
+ "%1$td.%1$tm.%1$tY %1$tH:%1$tM:%1$tS%n",
+ now
+ );
+ System.out.format("%tF%n", now);
+ System.out.format("%tc%n", now);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1203.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1203.java new file mode 100644 index 0000000..7f856a2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1203.java @@ -0,0 +1,20 @@ +/* Listing1203.java */
+
+public class Listing1203
+{
+ public static void main(String[] args)
+ {
+ int i, base = 0;
+
+ try {
+ for (base = 10; base >= 2; --base) {
+ i = Integer.parseInt("40",base);
+ System.out.println("40 base "+base+" = "+i);
+ }
+ } catch (NumberFormatException e) {
+ System.out.println(
+ "40 ist keine Zahl zur Basis "+base
+ );
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1205.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1205.java new file mode 100644 index 0000000..852902f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1205.java @@ -0,0 +1,20 @@ +/* Listing1205.java */
+
+public class Listing1205
+{
+ public static void main(String[] args)
+ {
+ int i, base = 0;
+
+ for (base = 10; base >= 2; --base) {
+ try {
+ i = Integer.parseInt("40",base);
+ System.out.println("40 base "+base+" = "+i);
+ } catch (NumberFormatException e) {
+ System.out.println(
+ "40 ist keine Zahl zur Basis "+base
+ );
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1206.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1206.java new file mode 100644 index 0000000..e9a7727 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1206.java @@ -0,0 +1,32 @@ +/* Listing1206.java */
+
+public class Listing1206
+{
+ public static void main(String[] args)
+ {
+ int i, j, base = 0;
+ String[] numbers = new String[3];
+
+ numbers[0] = "10";
+ numbers[1] = "20";
+ numbers[2] = "30";
+ try {
+ for (base = 10; base >= 2; --base) {
+ for (j = 0; j <= 3; ++j) {
+ i = Integer.parseInt(numbers[j],base);
+ System.out.println(
+ numbers[j]+" base "+base+" = "+i
+ );
+ }
+ }
+ } catch (IndexOutOfBoundsException e1) {
+ System.out.println(
+ "***IndexOutOfBoundsException: " + e1.toString()
+ );
+ } catch (NumberFormatException e2) {
+ System.out.println(
+ "***NumberFormatException: " + e2.toString()
+ );
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1207.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1207.java new file mode 100644 index 0000000..7992aaa --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1207.java @@ -0,0 +1,25 @@ +/* Listing1207.java */
+
+public class Listing1207
+{
+ public static void main(String[] args)
+ {
+ int i, base = 0;
+
+ try {
+ for (base = 10; base >= 2; --base) {
+ i = Integer.parseInt("40",base);
+ System.out.println("40 base "+base+" = "+i);
+ }
+ } catch (NumberFormatException e) {
+ System.out.println(
+ "40 ist keine Zahl zur Basis "+base
+ );
+ } finally {
+ System.out.println(
+ "Sie haben ein einfaches Beispiel " +
+ "sehr glücklich gemacht."
+ );
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1302.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1302.java new file mode 100644 index 0000000..97b9323 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1302.java @@ -0,0 +1,21 @@ +/* Listing1302.java */
+
+public class Listing1302
+{
+ private int cnt = 0;
+
+ public void printNext()
+ {
+ int value = cnt;
+ System.out.println("value = " + value);
+ int cnt = value + 1;
+ }
+
+ public static void main(String[] args)
+ {
+ Listing1302 obj = new Listing1302();
+ obj.printNext();
+ obj.printNext();
+ obj.printNext();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1401.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1401.java new file mode 100644 index 0000000..aca92ca --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1401.java @@ -0,0 +1,18 @@ +/* Listing1401.java */
+
+import java.util.*;
+
+public class Listing1401
+{
+ public static void main(String[] args)
+ {
+ Vector v = new Vector();
+
+ v.addElement("eins");
+ v.addElement("drei");
+ v.insertElementAt("zwei",1);
+ for (Enumeration el=v.elements(); el.hasMoreElements(); ) {
+ System.out.println((String)el.nextElement());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1402.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1402.java new file mode 100644 index 0000000..3ccbc2c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1402.java @@ -0,0 +1,22 @@ +/* Listing1402.java */
+
+import java.util.*;
+
+public class Listing1402
+{
+ public static void main(String[] args)
+ {
+ Stack s = new Stack();
+
+ s.push("Erstes Element");
+ s.push("Zweites Element");
+ s.push("Drittes Element");
+ while (true) {
+ try {
+ System.out.println(s.pop());
+ } catch (EmptyStackException e) {
+ break;
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1403.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1403.java new file mode 100644 index 0000000..4849313 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1403.java @@ -0,0 +1,26 @@ +/* Listing1403.java */
+
+import java.util.*;
+
+public class Listing1403
+{
+ public static void main(String[] args)
+ {
+ Hashtable h = new Hashtable();
+
+ //Pflege der Aliase
+ h.put("Fritz","f.mueller@test.de");
+ h.put("Franz","fk@b-blabla.com");
+ h.put("Paula","user0125@mail.uofm.edu");
+ h.put("Lissa","lb3@gateway.fhdto.northsurf.dk");
+
+ //Ausgabe
+ Enumeration e = h.keys();
+ while (e.hasMoreElements()) {
+ String alias = (String)e.nextElement();
+ System.out.println(
+ alias + " --> " + h.get(alias)
+ );
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1404.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1404.java new file mode 100644 index 0000000..91b4ea9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1404.java @@ -0,0 +1,34 @@ +/* Listing1404.java */
+
+import java.util.*;
+
+public class Listing1404
+{
+ private final static int MAXNUM = 20;
+
+ public static void main(String[] args)
+ {
+ BitSet b;
+ boolean ok;
+
+ System.out.println("Die Primzahlen <= " + MAXNUM + ":");
+ b = new BitSet();
+ for (int i = 2; i <= MAXNUM; ++i) {
+ ok = true;
+ for (int j = 2; j < i; ++j) {
+ if (b.get(j) && i % j == 0) {
+ ok = false;
+ break;
+ }
+ }
+ if (ok) {
+ b.set(i);
+ }
+ }
+ for (int i = 1; i <= MAXNUM; ++i) {
+ if (b.get(i)) {
+ System.out.println(" " + i);
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1501.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1501.java new file mode 100644 index 0000000..0133701 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1501.java @@ -0,0 +1,39 @@ +/* Listing1501.java */
+
+import java.util.*;
+
+public class Listing1501
+{
+ static void fillList(List list)
+ {
+ for (int i = 0; i < 10; ++i) {
+ list.add("" + i);
+ }
+ list.remove(3);
+ list.remove("5");
+ }
+
+ static void printList(List list)
+ {
+ for (int i = 0; i < list.size(); ++i) {
+ System.out.println((String)list.get(i));
+ }
+ System.out.println("---");
+ }
+
+ public static void main(String[] args)
+ {
+ //Erzeugen der LinkedList
+ LinkedList list1 = new LinkedList();
+ fillList(list1);
+ printList(list1);
+ //Erzeugen der ArrayList
+ ArrayList list2 = new ArrayList();
+ fillList(list2);
+ printList(list2);
+ //Test von removeAll
+ list2.remove("0");
+ list1.removeAll(list2);
+ printList(list1);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1502.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1502.java new file mode 100644 index 0000000..ce65fd4 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1502.java @@ -0,0 +1,28 @@ +/* Listing1502.java */
+
+import java.util.*;
+
+public class Listing1502
+{
+ public static void main(String[] args)
+ {
+ //Füllen der Liste
+ ArrayList list = new ArrayList();
+ for (int i = 1; i <= 20; ++i) {
+ list.add("" + i);
+ }
+ //Löschen von Elementen über Iterator
+ Iterator it = list.iterator();
+ while (it.hasNext()) {
+ String s = (String) it.next();
+ if (s.startsWith("1")) {
+ it.remove();
+ }
+ }
+ //Ausgeben der verbleibenden Elemente
+ it = list.iterator();
+ while (it.hasNext()) {
+ System.out.println((String) it.next());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1503.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1503.java new file mode 100644 index 0000000..f71e2ce --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1503.java @@ -0,0 +1,25 @@ +/* Listing1503.java */
+
+import java.util.*;
+
+public class Listing1503
+{
+ public static void main(String[] args)
+ {
+ HashSet set = new HashSet(10);
+ int doubletten = 0;
+ //Lottozahlen erzeugen
+ while (set.size() < 6) {
+ int num = (int)(Math.random() * 49) + 1;
+ if (!set.add(new Integer(num))) {
+ ++doubletten;
+ }
+ }
+ //Lottozahlen ausgeben
+ Iterator it = set.iterator();
+ while (it.hasNext()) {
+ System.out.println(((Integer)it.next()).toString());
+ }
+ System.out.println("Ignorierte Doubletten: " + doubletten);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1504.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1504.java new file mode 100644 index 0000000..1a757cb --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1504.java @@ -0,0 +1,27 @@ +/* Listing1504.java */
+
+import java.util.*;
+
+public class Listing1504
+{
+ public static void main(String[] args)
+ {
+ HashMap h = new HashMap();
+
+ //Pflege der Aliase
+ h.put("Fritz","f.mueller@test.de");
+ h.put("Franz","fk@b-blabla.com");
+ h.put("Paula","user0125@mail.uofm.edu");
+ h.put("Lissa","lb3@gateway.fhdto.northsurf.dk");
+
+ //Ausgabe
+ Iterator it = h.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry entry = (Map.Entry)it.next();
+ System.out.println(
+ (String)entry.getKey() + " --> " +
+ (String)entry.getValue()
+ );
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1505.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1505.java new file mode 100644 index 0000000..ea82f54 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1505.java @@ -0,0 +1,23 @@ +/* Listing1505.java */
+
+import java.util.*;
+
+public class Listing1505
+{
+ public static void main(String[] args)
+ {
+ //Konstruieren des Sets
+ TreeSet s = new TreeSet();
+ s.add("Kiwi");
+ s.add("Kirsche");
+ s.add("Ananas");
+ s.add("Zitrone");
+ s.add("Grapefruit");
+ s.add("Banane");
+ //Sortierte Ausgabe
+ Iterator it = s.iterator();
+ while (it.hasNext()) {
+ System.out.println((String)it.next());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1506.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1506.java new file mode 100644 index 0000000..81db9c3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1506.java @@ -0,0 +1,32 @@ +/* Listing1506.java */
+
+import java.util.*;
+
+public class Listing1506
+{
+ public static void main(String[] args)
+ {
+ //Konstruieren des Sets
+ TreeSet s = new TreeSet(new ReverseStringComparator());
+ s.add("Kiwi");
+ s.add("Kirsche");
+ s.add("Ananas");
+ s.add("Zitrone");
+ s.add("Grapefruit");
+ s.add("Banane");
+ //Rückwärts sortierte Ausgabe
+ Iterator it = s.iterator();
+ while (it.hasNext()) {
+ System.out.println((String)it.next());
+ }
+ }
+}
+
+class ReverseStringComparator
+implements Comparator
+{
+ public int compare(Object o1, Object o2)
+ {
+ return ((String)o2).compareTo((String)o1);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1507.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1507.java new file mode 100644 index 0000000..6004318 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1507.java @@ -0,0 +1,30 @@ +/* Listing1507.java */
+
+import java.util.*;
+
+public class Listing1507
+{
+ public static void main(String[] args)
+ {
+ //Konstruieren des Sets
+ List l = new ArrayList();
+ l.add("Kiwi");
+ l.add("Kirsche");
+ l.add("Ananas");
+ l.add("Zitrone");
+ l.add("Grapefruit");
+ l.add("Banane");
+ //Unsortierte Ausgabe
+ Iterator it = l.iterator();
+ while (it.hasNext()) {
+ System.out.println((String)it.next());
+ }
+ System.out.println("---");
+ //Sortierte Ausgabe
+ Collections.sort(l);
+ it = l.iterator();
+ while (it.hasNext()) {
+ System.out.println((String)it.next());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1601.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1601.java new file mode 100644 index 0000000..3d83220 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1601.java @@ -0,0 +1,28 @@ +/* Listing1601.java */
+
+import java.util.*;
+
+public class Listing1601
+{
+ public static void main(String[] args)
+ {
+ BitSet b = new BitSet();
+ Random r = new Random();
+
+ System.out.print("Mein Lottotip: ");
+ int cnt = 0;
+ while (cnt < 6) {
+ int num = 1 + Math.abs(r.nextInt()) % 49;
+ if (!b.get(num)) {
+ b.set(num);
+ ++cnt;
+ }
+ }
+ for (int i = 1; i <= 49; ++i) {
+ if (b.get(i)) {
+ System.out.print(i + " ");
+ }
+ }
+ System.out.println("");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1602.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1602.java new file mode 100644 index 0000000..c6a3557 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1602.java @@ -0,0 +1,118 @@ +/* Listing1602.java */
+
+import java.util.*;
+
+public class Listing1602
+{
+ public static void main(String[] args)
+ {
+ //Zuerst Ausgabe des aktuellen Datums
+ GregorianCalendar cal = new GregorianCalendar();
+ //cal.setTimeZone(TimeZone.getTimeZone("ECT"));
+ printCalendarInfo(cal);
+ System.out.println("---");
+
+ //Nun Ausgabe der Informationen zum 22.6.1910,
+ //dem Geburtstag von Konrad Zuse
+ cal.set(Calendar.DATE, 22);
+ cal.set(Calendar.MONTH, 6 - 1);
+ cal.set(Calendar.YEAR, 1910);
+ printCalendarInfo(cal);
+ //cal.setTime(cal.getTime());
+ }
+
+ public static void printCalendarInfo(GregorianCalendar cal)
+ {
+ //Aera
+ int value = cal.get(Calendar.ERA);
+ if (value == cal.BC) {
+ System.out.println("Aera.......: vor Christi Geburt");
+ } else if (value == cal.AD) {
+ System.out.println("Aera.......: Anno Domini");
+ } else {
+ System.out.println("Aera.......: unbekannt");
+ }
+ //Datum
+ System.out.println(
+ "Datum......: " +
+ cal.get(Calendar.DATE) + "." +
+ (cal.get(Calendar.MONTH)+1) + "." +
+ cal.get(Calendar.YEAR)
+ );
+ //Zeit
+ System.out.println(
+ "Zeit.......: " +
+ cal.get(Calendar.HOUR_OF_DAY) + ":" +
+ cal.get(Calendar.MINUTE) + ":" +
+ cal.get(Calendar.SECOND) + " (+" +
+ cal.get(Calendar.MILLISECOND) + " ms)"
+ );
+ //Zeit, amerikanisch
+ System.out.print(
+ "Am.Zeit....: " +
+ cal.get(Calendar.HOUR) + ":" +
+ cal.get(Calendar.MINUTE) + ":" +
+ cal.get(Calendar.SECOND)
+ );
+ value = cal.get(Calendar.AM_PM);
+ if (value == cal.AM) {
+ System.out.println(" AM");
+ } else if (value == cal.PM) {
+ System.out.println(" PM");
+ }
+ //Tag
+ System.out.println(
+ "Tag........: " +
+ cal.get(Calendar.DAY_OF_YEAR) + ". im Jahr"
+ );
+ System.out.println(
+ " " +
+ cal.get(Calendar.DAY_OF_MONTH) + ". im Monat"
+ );
+ //Woche
+ System.out.println(
+ "Woche......: " +
+ cal.get(Calendar.WEEK_OF_YEAR) + ". im Jahr"
+ );
+ System.out.println(
+ " " +
+ cal.get(Calendar.WEEK_OF_MONTH) + ". im Monat"
+ );
+ //Wochentag
+ System.out.print(
+ "Wochentag..: " +
+ cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) +
+ ". "
+ );
+ value = cal.get(Calendar.DAY_OF_WEEK);
+ if (value == cal.SUNDAY) {
+ System.out.print("Sonntag");
+ } else if (value == cal.MONDAY) {
+ System.out.print("Montag");
+ } else if (value == cal.TUESDAY) {
+ System.out.print("Dienstag");
+ } else if (value == cal.WEDNESDAY) {
+ System.out.print("Mittwoch");
+ } else if (value == cal.THURSDAY) {
+ System.out.print("Donnerstag");
+ } else if (value == cal.FRIDAY) {
+ System.out.print("Freitag");
+ } else if (value == cal.SATURDAY) {
+ System.out.print("Samstag");
+ } else {
+ System.out.print("unbekannt");
+ }
+ System.out.println(" im Monat");
+ //Zeitzone
+ System.out.println(
+ "Zeitzone...: " +
+ cal.get(Calendar.ZONE_OFFSET)/3600000 +
+ " Stunden"
+ );
+ System.out.println(
+ "Sommerzeit.: " +
+ cal.get(Calendar.DST_OFFSET)/3600000 +
+ " Stunden"
+ );
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1603.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1603.java new file mode 100644 index 0000000..2e1c78f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1603.java @@ -0,0 +1,67 @@ +/* Listing1603.java */
+
+import java.util.*;
+
+public class Listing1603
+{
+ public static void main(String[] args)
+ {
+ GregorianCalendar cal = new GregorianCalendar();
+ cal.set(Calendar.DATE, 30);
+ cal.set(Calendar.MONTH, 10 - 1);
+ cal.set(Calendar.YEAR, 1908);
+ showDate(cal);
+ addOne(cal, Calendar.DATE);
+ addOne(cal, Calendar.DATE);
+ addOne(cal, Calendar.MONTH);
+ addOne(cal, Calendar.MONTH);
+ addOne(cal, Calendar.YEAR);
+ addOne(cal, Calendar.YEAR);
+
+ cal.add(Calendar.DATE, -2);
+ cal.add(Calendar.MONTH, -2);
+ cal.add(Calendar.YEAR, -2);
+ showDate(cal);
+ }
+
+ public static void addOne(Calendar cal, int field)
+ {
+ cal.add(field,1);
+ showDate(cal);
+ }
+
+ public static void showDate(Calendar cal)
+ {
+ String ret = "";
+ int value = cal.get(Calendar.DAY_OF_WEEK);
+
+ switch (value) {
+ case Calendar.SUNDAY:
+ ret += "Sonntag";
+ break;
+ case Calendar.MONDAY:
+ ret += "Montag";
+ break;
+ case Calendar.TUESDAY:
+ ret += "Dienstag";
+ break;
+ case Calendar.WEDNESDAY:
+ ret += "Mittwoch";
+ break;
+ case Calendar.THURSDAY:
+ ret += "Donnerstag";
+ break;
+ case Calendar.FRIDAY:
+ ret += "Freitag";
+ break;
+ case Calendar.SATURDAY:
+ ret += "Samstag";
+ break;
+ }
+ ret += ", den ";
+ ret += cal.get(Calendar.DATE) + ".";
+ ret += (cal.get(Calendar.MONTH)+1) + ".";
+ ret += cal.get(Calendar.YEAR);
+ System.out.println(ret);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1604.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1604.java new file mode 100644 index 0000000..8f519d8 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1604.java @@ -0,0 +1,18 @@ +/* Listing1604.java */
+
+import java.util.*;
+
+public class Listing1604
+{
+ public static void main(String[] args)
+ {
+ Properties sysprops = System.getProperties();
+ Enumeration propnames = sysprops.propertyNames();
+ while (propnames.hasMoreElements()) {
+ String propname = (String)propnames.nextElement();
+ System.out.println(
+ propname + "=" + System.getProperty(propname)
+ );
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1605.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1605.java new file mode 100644 index 0000000..2ddb862 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1605.java @@ -0,0 +1,31 @@ +/* Listing1605.java */
+
+public class Listing1605
+{
+ public static void main(String[] args)
+ {
+ long t1, t2;
+ int actres, sumres = 0, i = 0;
+ while (true) {
+ ++i;
+ t1 = System.currentTimeMillis();
+ while (true) {
+ t2 = System.currentTimeMillis();
+ if (t2 != t1) {
+ actres = (int)(t2 - t1);
+ break;
+ }
+ }
+ sumres += actres;
+ System.out.print("it="+i+", ");
+ System.out.print("actres="+actres+" msec., ");
+ System.out.print("avgres="+(sumres/i)+" msec.");
+ System.out.println("");
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1606.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1606.java new file mode 100644 index 0000000..3bfe00f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1606.java @@ -0,0 +1,31 @@ +/* Listing1606.java */
+
+public class Listing1606
+{
+ public static long testSleep(int millis)
+ {
+ final int MINDURATION = 3000;
+ int cnt = (millis >= MINDURATION ? 1 : MINDURATION/millis);
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < cnt; ++i) {
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException e) {
+ }
+ }
+ long end = System.currentTimeMillis();
+ return (end - start) / cnt;
+ }
+
+ public static void main(String[] args)
+ {
+ final int DATA[] = {345, 27, 1, 1962, 2, 8111, 6, 89, 864};
+ for (int i = 0; i < DATA.length; ++i) {
+ System.out.println("Aufruf von sleep(" + DATA[i] + ")");
+ long result = testSleep(DATA[i]);
+ System.out.print(" Ergebnis: " + result);
+ double prec = ((double)result / DATA[i] - 1.0) * 100;
+ System.out.println(" (" + (prec > 0 ? "+": "") + prec + " %)");
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1607.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1607.java new file mode 100644 index 0000000..a3457d0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1607.java @@ -0,0 +1,19 @@ +/* Listing1607.java */
+
+public class Listing1607
+{
+ public static void main(String[] args)
+ {
+ int[] ar = {0,0,0,0,0,0,0,0,0,0};
+
+ for (int i = 0; i < 10; ++i) {
+ System.arraycopy(ar,0,ar,1,9);
+ ar[0] = i;
+ }
+ System.out.print("ar = ");
+ for (int i = 0; i < 10; ++i) {
+ System.out.print(ar[i] + " ");
+ }
+ System.out.println("");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1608.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1608.java new file mode 100644 index 0000000..3532d14 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1608.java @@ -0,0 +1,15 @@ +/* Listing1608.java */
+
+import java.io.*;
+
+public class Listing1608
+{
+ public static void main(String[] args)
+ {
+ try {
+ Runtime.getRuntime().exec("notepad");
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1610.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1610.java new file mode 100644 index 0000000..8e955ec --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1610.java @@ -0,0 +1,27 @@ +/* Listing1610.java */
+
+import java.util.*;
+
+public class Listing1610
+{
+ public static void main(String[] args)
+ {
+ final int SIZE = 20;
+ int[] values = new int[SIZE];
+ Random rand = new Random();
+ //Erzeugen und Ausgeben des unsortierten Arrays
+ for (int i = 0; i < SIZE; ++i) {
+ values[i] = rand.nextInt(10 * SIZE);
+ }
+ for (int i = 0; i < SIZE; ++i) {
+ System.out.println(values[i]);
+ }
+ //Sortieren des Arrays
+ Arrays.sort(values);
+ //Ausgeben der Daten
+ System.out.println("---");
+ for (int i = 0; i < SIZE; ++i) {
+ System.out.println(values[i]);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1701.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1701.java new file mode 100644 index 0000000..0616328 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1701.java @@ -0,0 +1,18 @@ +/* Listing1701.java */
+
+import java.util.regex.*;
+
+public class Listing1701
+{
+ public static void main(String[] args)
+ {
+ // Erzeugen eines Pattern-Objektes für den Ausdruck a*b
+ Pattern p = Pattern.compile("a*b");
+
+ // Erzeugen eines Matcher-Objektes für die Zeichenkette
+ Matcher m = p.matcher("aaaaab");
+
+ // Test, ob die Zeichenkette vom Ausdruck beschrieben wird
+ boolean b = m.matches();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1702.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1702.java new file mode 100644 index 0000000..dad8acf --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1702.java @@ -0,0 +1,12 @@ +/* Listing1702.java */
+
+import java.util.regex.*;
+
+public class Listing1702
+{
+ public static void main(String[] args)
+ {
+ // Testet die Zeichenkette auf das Pattern
+ boolean b = Pattern.matches("a*b", "aaaaab");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1703.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1703.java new file mode 100644 index 0000000..cb88750 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1703.java @@ -0,0 +1,10 @@ +/* Listing1703.java */
+
+public class Listing1703
+{
+ public static void main(String[] args)
+ {
+ // Testet die Zeichenkette auf das Pattern
+ boolean b = "aaaaab".matches("a*b");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1704.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1704.java new file mode 100644 index 0000000..f58195d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1704.java @@ -0,0 +1,22 @@ +/* Listing1704.java */
+
+import java.util.regex.*;
+
+public class Listing1704
+{
+ public static void main(String[] args)
+ {
+ // Der zu verwendende Testsatz
+ String satz = "Dies ist nur ein Test";
+
+ // Jedes Whitespace-Zeichen soll zur
+ // Trennung verwendet werden
+ Pattern p = Pattern.compile("\\s");
+
+ // Verwendung der Methode split
+ String[] result = p.split(satz);
+ for (int x=0; x<result.length; x++) {
+ System.out.println(result[x]);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1705.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1705.java new file mode 100644 index 0000000..b0b61a5 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1705.java @@ -0,0 +1,22 @@ +/* Listing1705.java */
+
+import java.math.*;
+
+public class Listing1705
+{
+ public static void printFaculty(int n)
+ {
+ BigInteger bi = new BigInteger("1");
+ for (int i = 2; i <= n; ++i) {
+ bi = bi.multiply(new BigInteger("" + i));
+ }
+ System.out.println(n + "! is " + bi.toString());
+ }
+
+ public static void main(String[] args)
+ {
+ for (int i = 30; i <= 40; ++i) {
+ printFaculty(i);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1706.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1706.java new file mode 100644 index 0000000..4f1c41d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1706.java @@ -0,0 +1,43 @@ +/* Listing1706.java */
+
+import java.math.*;
+
+public class Listing1706
+{
+ public static final BigDecimal ZERO = new BigDecimal("0");
+ public static final BigDecimal ONE = new BigDecimal("1");
+ public static final BigDecimal TWO = new BigDecimal("2");
+
+ public static BigDecimal sqrt(BigDecimal x, int digits)
+ {
+ BigDecimal zero = ZERO.setScale(digits + 10);
+ BigDecimal one = ONE.setScale(digits + 10);
+ BigDecimal two = TWO.setScale(digits + 10);
+ BigDecimal maxerr = one.movePointLeft(digits);
+ BigDecimal lower = zero;
+ BigDecimal upper = x.compareTo(one) <= 0 ? one : x;
+ BigDecimal mid;
+ while (true) {
+ mid = lower.add(upper).divide(two, BigDecimal.ROUND_HALF_UP);
+ BigDecimal sqr = mid.multiply(mid);
+ BigDecimal error = x.subtract(sqr).abs();
+ if (error.compareTo(maxerr) <= 0) {
+ break;
+ }
+ if (sqr.compareTo(x) < 0) {
+ lower = mid;
+ } else {
+ upper = mid;
+ }
+ }
+ return mid;
+ }
+
+ public static void main(String[] args)
+ {
+ BigDecimal sqrtTwo = sqrt(TWO, 100);
+ BigDecimal apxTwo = sqrtTwo.multiply(sqrtTwo);
+ System.out.println("sqrt(2): " + sqrtTwo.toString());
+ System.out.println("check : " + apxTwo.toString());
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1707.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1707.java new file mode 100644 index 0000000..0b241bf --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1707.java @@ -0,0 +1,14 @@ +/* Listing1707.java */
+
+import java.util.*;
+
+public class Listing1707
+{
+ public static void main(String[] args)
+ {
+ System.out.println("Default: " + Locale.getDefault());
+ System.out.println("GERMANY: " + Locale.GERMANY);
+ System.out.println("UK : " + Locale.UK);
+ System.out.println("US : " + Locale.US);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1708.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1708.java new file mode 100644 index 0000000..612fbcf --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1708.java @@ -0,0 +1,22 @@ +/* Listing1708.java */
+
+import java.text.*;
+
+public class Listing1708
+{
+ public static void print(double value, String format)
+ {
+ DecimalFormat df = new DecimalFormat(format);
+ System.out.println(df.format(value));
+ }
+ public static void main(String[] args)
+ {
+ double value = 1768.3518;
+ print(value, "#0.0");
+ print(value, "#0.000");
+ print(value, "000000.000");
+ print(value, "#.000000");
+ print(value, "#,###,##0.000");
+ print(value, "0.000E00");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1709.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1709.java new file mode 100644 index 0000000..1a9007f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1709.java @@ -0,0 +1,26 @@ +/* Listing1709.java */
+
+import java.util.*;
+import java.text.*;
+
+public class Listing1709
+{
+ public static void print(Calendar cal, int style)
+ {
+ DateFormat df;
+ df = DateFormat.getDateInstance(style);
+ System.out.print(df.format(cal.getTime()) + " / ");
+ df = DateFormat.getTimeInstance(style);
+ System.out.println(df.format(cal.getTime()));
+ }
+
+ public static void main(String[] args)
+ {
+ GregorianCalendar cal = new GregorianCalendar();
+ print(cal, DateFormat.SHORT);
+ print(cal, DateFormat.MEDIUM);
+ print(cal, DateFormat.LONG);
+ print(cal, DateFormat.FULL);
+ print(cal, DateFormat.DEFAULT);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1714.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1714.java new file mode 100644 index 0000000..b9f7d0b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1714.java @@ -0,0 +1,27 @@ +/* Listing1714.java */
+
+import java.util.*;
+
+public class Listing1714
+{
+ public static void sayHello(Locale locale)
+ {
+ System.out.print(locale + ": ");
+ ResourceBundle textbundle = ResourceBundle.getBundle(
+ "MyTextResource",
+ locale
+ );
+ if (textbundle != null) {
+ System.out.print(textbundle.getString("Hi") + ", ");
+ System.out.println(textbundle.getString("To"));
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ sayHello(Locale.getDefault());
+ sayHello(new Locale("de", "CH"));
+ sayHello(Locale.US);
+ sayHello(Locale.FRANCE);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1801.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1801.java new file mode 100644 index 0000000..8188bec --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1801.java @@ -0,0 +1,20 @@ +/* Listing1801.java */
+
+import java.io.*;
+
+public class Listing1801
+{
+ public static void main(String[] args)
+ {
+ String hello = "Hallo JAVA\r\n";
+ FileWriter f1;
+
+ try {
+ f1 = new FileWriter("hallo.txt");
+ f1.write(hello);
+ f1.close();
+ } catch (IOException e) {
+ System.out.println("Fehler beim Erstellen der Datei");
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1802.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1802.java new file mode 100644 index 0000000..a0a4c38 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1802.java @@ -0,0 +1,27 @@ +/* Listing1802.java */
+
+import java.io.*;
+
+public class Listing1802
+{
+ public static void main(String[] args)
+ {
+ Writer f1;
+ BufferedWriter f2;
+ String s;
+
+ try {
+ f1 = new FileWriter("buffer.txt");
+ f2 = new BufferedWriter(f1);
+ for (int i = 1; i <= 10000; ++i) {
+ s = "Dies ist die " + i + ". Zeile";
+ f2.write(s);
+ f2.newLine();
+ }
+ f2.close();
+ f1.close();
+ } catch (IOException e) {
+ System.out.println("Fehler beim Erstellen der Datei");
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1803.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1803.java new file mode 100644 index 0000000..2ceee5f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1803.java @@ -0,0 +1,25 @@ +/* Listing1803.java */
+
+import java.io.*;
+
+public class Listing1803
+{
+ public static void main(String[] args)
+ {
+ BufferedWriter f;
+ String s;
+
+ try {
+ f = new BufferedWriter(
+ new FileWriter("buffer.txt"));
+ for (int i = 1; i <= 10000; ++i) {
+ s = "Dies ist die " + i + ". Zeile";
+ f.write(s);
+ f.newLine();
+ }
+ f.close();
+ } catch (IOException e) {
+ System.out.println("Fehler beim Erstellen der Datei");
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1804.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1804.java new file mode 100644 index 0000000..428c6e4 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1804.java @@ -0,0 +1,30 @@ +/* Listing1804.java */
+
+import java.io.*;
+
+public class Listing1804
+{
+ public static void main(String[] args)
+ {
+ PrintWriter f;
+ double sum = 0.0;
+ int nenner;
+
+ try {
+ f = new PrintWriter(
+ new BufferedWriter(
+ new FileWriter("zwei.txt")));
+
+ for (nenner = 1; nenner <= 1024; nenner *= 2) {
+ sum += 1.0 / nenner;
+ f.print("Summand: 1/");
+ f.print(nenner);
+ f.print(" Summe: ");
+ f.println(sum);
+ }
+ f.close();
+ } catch (IOException e) {
+ System.out.println("Fehler beim Erstellen der Datei");
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1805.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1805.java new file mode 100644 index 0000000..f7de539 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1805.java @@ -0,0 +1,65 @@ +/* Listing1805.java */
+
+import java.io.*;
+
+class UpCaseWriter
+extends FilterWriter
+{
+ public UpCaseWriter(Writer out)
+ {
+ super(out);
+ }
+
+ public void write(int c)
+ throws IOException
+ {
+ super.write(Character.toUpperCase((char)c));
+ }
+
+ public void write(char[] cbuf, int off, int len)
+ throws IOException
+ {
+ for (int i = 0; i < len; ++i) {
+ write(cbuf[off + i]);
+ }
+ }
+
+ public void write(String str, int off, int len)
+ throws IOException
+ {
+ write(str.toCharArray(), off, len);
+ }
+}
+
+public class Listing1805
+{
+ public static void main(String[] args)
+ {
+ PrintWriter f;
+ String s = "und dieser String auch";
+
+ try {
+ f = new PrintWriter(
+ new UpCaseWriter(
+ new FileWriter("upcase.txt")));
+ //Aufruf von außen
+ f.println("Diese Zeile wird schön groß geschrieben");
+ //Test von write(int)
+ f.write('a');
+ f.println();
+ //Test von write(String)
+ f.write(s);
+ f.println();
+ //Test von write(String, int, int)
+ f.write(s,0,17);
+ f.println();
+ //Test von write(char[], int, int)
+ f.write(s.toCharArray(),0,10);
+ f.println();
+ //---
+ f.close();
+ } catch (IOException e) {
+ System.out.println("Fehler beim Erstellen der Datei");
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1806.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1806.java new file mode 100644 index 0000000..f933f34 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1806.java @@ -0,0 +1,22 @@ +/* Listing1806.java */
+
+import java.io.*;
+
+public class Listing1806
+{
+ public static void main(String[] args)
+ {
+ FileReader f;
+ int c;
+
+ try {
+ f = new FileReader("c:\\config.sys");
+ while ((c = f.read()) != -1) {
+ System.out.print((char)c);
+ }
+ f.close();
+ } catch (IOException e) {
+ System.out.println("Fehler beim Lesen der Datei");
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1807.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1807.java new file mode 100644 index 0000000..339a83b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1807.java @@ -0,0 +1,27 @@ +/* Listing1807.java */
+
+import java.io.*;
+
+public class Listing1807
+{
+ public static void main(String[] args)
+ {
+ Reader f;
+ int c;
+ String s;
+
+ s = "Das folgende Programm zeigt die Verwendung\r\n";
+ s += "der Klasse StringReader am Beispiel eines\r\n";
+ s += "Programms, das einen Reader konstruiert, der\r\n";
+ s += "den Satz liest, der hier an dieser Stelle steht:\r\n";
+ try {
+ f = new StringReader(s);
+ while ((c = f.read()) != -1) {
+ System.out.print((char)c);
+ }
+ f.close();
+ } catch (IOException e) {
+ System.out.println("Fehler beim Lesen des Strings");
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1808.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1808.java new file mode 100644 index 0000000..1b1354f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1808.java @@ -0,0 +1,23 @@ +/* Listing1808.java */
+
+import java.io.*;
+
+public class Listing1808
+{
+ public static void main(String[] args)
+ {
+ BufferedReader f;
+ String line;
+
+ try {
+ f = new BufferedReader(
+ new FileReader("c:\\config.sys"));
+ while ((line = f.readLine()) != null) {
+ System.out.println(line);
+ }
+ f.close();
+ } catch (IOException e) {
+ System.out.println("Fehler beim Lesen der Datei");
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1809.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1809.java new file mode 100644 index 0000000..3a6dde3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1809.java @@ -0,0 +1,24 @@ +/* Listing1809.java */
+
+import java.io.*;
+
+public class Listing1809
+{
+ public static void main(String[] args)
+ {
+ LineNumberReader f;
+ String line;
+
+ try {
+ f = new LineNumberReader(
+ new FileReader("c:\\config.sys"));
+ while ((line = f.readLine()) != null) {
+ System.out.print(f.getLineNumber() + ": ");
+ System.out.println(line);
+ }
+ f.close();
+ } catch (IOException e) {
+ System.out.println("Fehler beim Lesen der Datei");
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1901.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1901.java new file mode 100644 index 0000000..893a540 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1901.java @@ -0,0 +1,23 @@ +/* Listing1901.java */
+
+import java.io.*;
+
+public class Listing1901
+{
+ public static void main(String[] args)
+ {
+ try {
+ FileOutputStream out = new FileOutputStream(
+ args[0],
+ true
+ );
+ for (int i = 0; i < 256; ++i) {
+ out.write(i);
+ }
+ out.close();
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1902.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1902.java new file mode 100644 index 0000000..08d5305 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1902.java @@ -0,0 +1,23 @@ +/* Listing1902.java */
+
+import java.io.*;
+
+public class Listing1902
+{
+ public static void main(String[] args)
+ {
+ try {
+ DataOutputStream out = new DataOutputStream(
+ new BufferedOutputStream(
+ new FileOutputStream("test.txt")));
+ out.writeInt(1);
+ out.writeInt(-1);
+ out.writeDouble(Math.PI);
+ out.writeUTF("häßliches");
+ out.writeUTF("Entlein");
+ out.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1905.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1905.java new file mode 100644 index 0000000..22811df --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1905.java @@ -0,0 +1,23 @@ +/* Listing1905.java */
+
+import java.io.*;
+
+public class Listing1905
+{
+ public static void main(String[] args)
+ {
+ try {
+ DataInputStream in = new DataInputStream(
+ new BufferedInputStream(
+ new FileInputStream("test.txt")));
+ System.out.println(in.readInt());
+ System.out.println(in.readInt());
+ System.out.println(in.readDouble());
+ System.out.println(in.readUTF());
+ System.out.println(in.readUTF());
+ in.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1906.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1906.java new file mode 100644 index 0000000..58bb47b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1906.java @@ -0,0 +1,30 @@ +/* Listing1906.java */
+
+import java.io.*;
+import java.util.zip.*;
+
+public class Listing1906
+{
+ public static void main(String[] args)
+ {
+ if (args.length != 1) {
+ System.out.println("Usage: java Listing1906 file");
+ System.exit(1);
+ }
+ try {
+ CheckedInputStream in = new CheckedInputStream(
+ new FileInputStream(args[0]),
+ new Adler32()
+ );
+ byte[] buf = new byte[4096];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ //nichts
+ }
+ System.out.println(in.getChecksum().getValue());
+ in.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2001.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2001.java new file mode 100644 index 0000000..14ae58a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2001.java @@ -0,0 +1,76 @@ +/* Listing2001.java */
+
+import java.io.*;
+
+class ClassFileReader
+{
+ private RandomAccessFile f;
+
+ public ClassFileReader(String name)
+ throws IOException
+ {
+ if (!name.endsWith(".class")) {
+ name += ".class";
+ }
+ f = new RandomAccessFile(name,"r");
+ }
+
+ public void close()
+ {
+ if (f != null) {
+ try {
+ f.close();
+ } catch (IOException e) {
+ //nichts
+ }
+ }
+ }
+
+ public void printSignature()
+ throws IOException
+ {
+ String ret = "";
+ int b;
+
+ f.seek(0);
+ for (int i=0; i<4; ++i) {
+ b = f.read();
+ ret += (char)(b/16+'A'-10);
+ ret += (char)(b%16+'A'-10);
+ }
+ System.out.println(
+ "Signatur...... "+
+ ret
+ );
+ }
+
+ public void printVersion()
+ throws IOException
+ {
+ int minor, major;
+
+ f.seek(4);
+ minor = f.readShort();
+ major = f.readShort();
+ System.out.println(
+ "Version....... "+
+ major+"."+minor
+ );
+ }
+}
+
+public class Listing2001
+{
+ public static void main(String[] args)
+ {
+ ClassFileReader f;
+
+ try {
+ f = new ClassFileReader("Listing2001");
+ f.printSignature();
+ f.printVersion();
+ } catch (IOException e) {
+ System.out.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2002.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2002.java new file mode 100644 index 0000000..eb6557a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2002.java @@ -0,0 +1,26 @@ +/* Listing2002.java */
+
+import java.io.*;
+
+public class Listing2002
+{
+ public static void main(String[] args)
+ {
+ try {
+ RandomAccessFile f1 = new RandomAccessFile(
+ args[0], "rw"
+ );
+ long len = f1.length();
+ f1.setLength(2 * len);
+ for (long i = 0; i < len; ++i) {
+ f1.seek(i);
+ int c = f1.read();
+ f1.seek(2 * len - i - 1);
+ f1.write(c);
+ }
+ f1.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2101.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2101.java new file mode 100644 index 0000000..1102049 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2101.java @@ -0,0 +1,23 @@ +/* Listing2101.java */
+
+import java.io.*;
+import java.util.*;
+
+public class Listing2101
+{
+ public static void main(String[] args)
+ {
+ File file = new File(args[0]);
+ GregorianCalendar cal = new GregorianCalendar();
+ cal.setTime(new Date(file.lastModified()));
+ System.out.print("Letzte Änderung: ");
+ System.out.println(
+ cal.get(Calendar.DATE) + "." +
+ (cal.get(Calendar.MONTH)+1) + "." +
+ cal.get(Calendar.YEAR) + " " +
+ cal.get(Calendar.HOUR_OF_DAY) + ":" +
+ cal.get(Calendar.MINUTE) + ":" +
+ cal.get(Calendar.SECOND)
+ );
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2105.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2105.java new file mode 100644 index 0000000..fba2e38 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2105.java @@ -0,0 +1,46 @@ +/* Listing2105.java */
+
+import java.io.*;
+
+public class Listing2105
+{
+ static void traverse(File dir, DirectoryVisitor visitor)
+ {
+ if (!dir.isDirectory()) {
+ throw new IllegalArgumentException(
+ "not a directory: " + dir.getName()
+ );
+ }
+ visitor.enterDirectory(dir);
+ File[] entries = dir.listFiles(
+ new FileFilter()
+ {
+ public boolean accept(File pathname)
+ {
+ return true;
+ }
+ }
+ );
+ for (int i = 0; i < entries.length; ++i) {
+ if (entries[i].isDirectory()) {
+ traverse(entries[i], visitor);
+ } else {
+ visitor.visitFile(entries[i]);
+ }
+ }
+ visitor.leaveDirectory(dir);
+ }
+
+ public static void main(String[] args)
+ {
+ File file = new File(args[0]);
+ //Bildschirmausgabe der Struktur
+ traverse(file, new DirectoryPrintVisitor());
+ //Größen ermitteln
+ DirectorySizeVisitor visitor = new DirectorySizeVisitor();
+ traverse(file, visitor);
+ System.out.println("directories: " + visitor.getDirs());
+ System.out.println("files: " + visitor.getFiles());
+ System.out.println("size: " + visitor.getSize());
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2107.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2107.java new file mode 100644 index 0000000..10ccd67 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2107.java @@ -0,0 +1,15 @@ +/* Listing2107.java */
+
+import java.io.*;
+
+public class Listing2107
+{
+ public static void main(String[] args)
+ {
+ try {
+ File tmp = File.createTempFile("xyz", ".tmp", null);
+ } catch (IOException e) {
+ System.out.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2201.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2201.java new file mode 100644 index 0000000..c484589 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2201.java @@ -0,0 +1,22 @@ +/* Listing2201.java */
+
+class MyThread2201
+extends Thread
+{
+ public void run()
+ {
+ int i = 0;
+ while (true) {
+ System.out.println(i++);
+ }
+ }
+}
+
+public class Listing2201
+{
+ public static void main(String[] args)
+ {
+ MyThread2201 t = new MyThread2201();
+ t.start();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2202.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2202.java new file mode 100644 index 0000000..47ff5d0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2202.java @@ -0,0 +1,28 @@ +/* Listing2202.java */
+
+class MyThread2202
+extends Thread
+{
+ public void run()
+ {
+ int i = 0;
+ while (true) {
+ System.out.println(i++);
+ }
+ }
+}
+
+public class Listing2202
+{
+ public static void main(String[] args)
+ {
+ MyThread2202 t = new MyThread2202();
+ t.start();
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ t.stop();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2203.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2203.java new file mode 100644 index 0000000..2d91787 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2203.java @@ -0,0 +1,49 @@ +/* Listing2203.java */
+
+public class Listing2203
+extends Thread
+{
+ int cnt = 0;
+
+ public void run()
+ {
+ while (true) {
+ if (isInterrupted()) {
+ break;
+ }
+ printLine(++cnt);
+ }
+ }
+
+ private void printLine(int cnt)
+ {
+ //Zeile ausgeben
+ System.out.print(cnt + ": ");
+ for (int i = 0; i < 30; ++i) {
+ System.out.print(i == cnt % 30 ? "* " : ". ");
+ }
+ System.out.println();
+ //100 ms. warten
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ interrupt();
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing2203 th = new Listing2203();
+ {
+ //Thread starten
+ th.start();
+ //2 Sekunden warten
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ }
+ //Thread unterbrechen
+ th.interrupt();
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2204.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2204.java new file mode 100644 index 0000000..73189fd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2204.java @@ -0,0 +1,39 @@ +/* Listing2204.java */
+
+class A2204
+{
+ int irgendwas;
+ //...
+}
+
+class B2204
+extends A2204
+implements Runnable
+{
+ public void run()
+ {
+ int i = 0;
+ while (true) {
+ if (Thread.interrupted()) {
+ break;
+ }
+ System.out.println(i++);
+ }
+ }
+}
+
+public class Listing2204
+{
+ public static void main(String[] args)
+ {
+ B2204 b = new B2204();
+ Thread t = new Thread(b);
+ t.start();
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e){
+ //nichts
+ }
+ t.interrupt();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2206.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2206.java new file mode 100644 index 0000000..b96a3fd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2206.java @@ -0,0 +1,29 @@ +/* Listing2206.java */
+
+import java.io.*;
+
+public class Listing2206
+{
+ public static void main(String[] args)
+ {
+ PrimeNumberTools pt = new PrimeNumberTools();
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(
+ new DataInputStream(System.in)));
+ int num;
+
+ try {
+ while (true) {
+ System.out.print("Bitte eine Zahl eingeben: ");
+ System.out.flush();
+ num = (new Integer(in.readLine())).intValue();
+ if (num == -1) {
+ break;
+ }
+ pt.printPrimeFactors(num);
+ }
+ } catch (IOException e) {
+ //nichts
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2208.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2208.java new file mode 100644 index 0000000..03b340b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2208.java @@ -0,0 +1,30 @@ +/* Listing2208.java */
+
+import java.io.*;
+
+public class Listing2208
+{
+ public static void main(String[] args)
+ {
+ ThreadedPrimeNumberTools pt;
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(
+ new DataInputStream(System.in)));
+ int num;
+
+ try {
+ while (true) {
+ System.out.print("Bitte eine Zahl eingeben: ");
+ System.out.flush();
+ num = (new Integer(in.readLine())).intValue();
+ if (num == -1) {
+ break;
+ }
+ pt = new ThreadedPrimeNumberTools();
+ pt.printPrimeFactors(num);
+ }
+ } catch (IOException e) {
+ //nichts
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2209.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2209.java new file mode 100644 index 0000000..f068ed2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2209.java @@ -0,0 +1,22 @@ +/* Listing2209.java */
+
+public class Listing2209
+extends Thread
+{
+ static int cnt = 0;
+
+ public static void main(String[] args)
+ {
+ Thread t1 = new Listing2209();
+ Thread t2 = new Listing2209();
+ t1.start();
+ t2.start();
+ }
+
+ public void run()
+ {
+ while (true) {
+ System.out.println(cnt++);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2210.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2210.java new file mode 100644 index 0000000..e52cfa1 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2210.java @@ -0,0 +1,24 @@ +/* Listing2210.java */
+
+public class Listing2210
+extends Thread
+{
+ static int cnt = 0;
+
+ public static void main(String[] args)
+ {
+ Thread t1 = new Listing2210();
+ Thread t2 = new Listing2210();
+ t1.start();
+ t2.start();
+ }
+
+ public void run()
+ {
+ while (true) {
+ synchronized (getClass()) {
+ System.out.println(cnt++);
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2211.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2211.java new file mode 100644 index 0000000..ce7d764 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2211.java @@ -0,0 +1,59 @@ +/* Listing2211.java */
+
+class Counter2211
+{
+ int cnt;
+
+ public Counter2211(int cnt)
+ {
+ this.cnt = cnt;
+ }
+
+ public int nextNumber()
+ {
+ int ret = cnt;
+ //Hier erfolgen ein paar zeitaufwändige Berechnungen, um
+ //so zu tun, als sei das Errechnen des Nachfolgezählers
+ //eine langwierige Operation, die leicht durch den
+ //Scheduler unterbrochen werden kann.
+ double x = 1.0, y, z;
+ for (int i= 0; i < 1000; ++i) {
+ x = Math.sin((x*i%35)*1.13);
+ y = Math.log(x+10.0);
+ z = Math.sqrt(x+y);
+ }
+ //Jetzt ist der Wert gefunden
+ cnt++;
+ return ret;
+ }
+}
+
+public class Listing2211
+extends Thread
+{
+ private String name;
+ private Counter2211 counter;
+
+ public Listing2211(String name, Counter2211 counter)
+ {
+ this.name = name;
+ this.counter = counter;
+ }
+
+ public static void main(String[] args)
+ {
+ Thread[] t = new Thread[5];
+ Counter2211 cnt = new Counter2211(10);
+ for (int i = 0; i < 5; ++i) {
+ t[i] = new Listing2211("Thread-"+i,cnt);
+ t[i].start();
+ }
+ }
+
+ public void run()
+ {
+ while (true) {
+ System.out.println(counter.nextNumber()+" for "+name);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2213.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2213.java new file mode 100644 index 0000000..ebd0227 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2213.java @@ -0,0 +1,82 @@ +/* Listing2213.java */
+
+import java.util.*;
+
+class Producer2213
+extends Thread
+{
+ private Vector v;
+
+ public Producer2213(Vector v)
+ {
+ this.v = v;
+ }
+
+ public void run()
+ {
+ String s;
+
+ while (true) {
+ synchronized (v) {
+ s = "Wert "+Math.random();
+ v.addElement(s);
+ System.out.println("Produzent erzeugte "+s);
+ v.notify();
+ }
+ try {
+ Thread.sleep((int)(100*Math.random()));
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ }
+ }
+}
+
+class Consumer2213
+extends Thread
+{
+ private Vector v;
+
+ public Consumer2213(Vector v)
+ {
+ this.v = v;
+ }
+
+ public void run()
+ {
+ while (true) {
+ synchronized (v) {
+ if (v.size() < 1) {
+ try {
+ v.wait();
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ }
+ System.out.print(
+ " Konsument fand "+(String)v.elementAt(0)
+ );
+ v.removeElementAt(0);
+ System.out.println(" (verbleiben: "+v.size()+")");
+ }
+ try {
+ Thread.sleep((int)(100*Math.random()));
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ }
+ }
+}
+
+public class Listing2213
+{
+ public static void main(String[] args)
+ {
+ Vector v = new Vector();
+
+ Producer2213 p = new Producer2213(v);
+ Consumer2213 c = new Consumer2213(v);
+ p.start();
+ c.start();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2214.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2214.java new file mode 100644 index 0000000..f75fe58 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2214.java @@ -0,0 +1,74 @@ +/* Listing2214.java */
+
+import java.io.*;
+
+class Producer2214
+extends Thread
+{
+ private PipedOutputStream pipe;
+
+ public Producer2214(PipedOutputStream pipe)
+ {
+ this.pipe = pipe;
+ }
+
+ public void run()
+ {
+ while (true) {
+ byte b = (byte)(Math.random() * 128);
+ try {
+ pipe.write(b);
+ System.out.println("Produzent erzeugte " + b);
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ try {
+ Thread.sleep((int)(100*Math.random()));
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ }
+ }
+}
+
+class Consumer2214
+extends Thread
+{
+ private PipedInputStream pipe;
+
+ public Consumer2214(PipedInputStream pipe)
+ {
+ this.pipe = pipe;
+ }
+
+ public void run()
+ {
+ while (true) {
+ try {
+ byte b = (byte)pipe.read();
+ System.out.println(" Konsument fand " + b);
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ try {
+ Thread.sleep((int)(100*Math.random()));
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ }
+ }
+}
+
+public class Listing2214
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ PipedInputStream inPipe = new PipedInputStream();
+ PipedOutputStream outPipe = new PipedOutputStream(inPipe);
+ Producer2214 p = new Producer2214(outPipe);
+ Consumer2214 c = new Consumer2214(inPipe);
+ p.start();
+ c.start();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2301.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2301.java new file mode 100644 index 0000000..55e0bb8 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2301.java @@ -0,0 +1,14 @@ +/* Listing2301.java */
+
+import java.awt.*;
+
+class Listing2301
+{
+ public static void main(String[] args)
+ {
+ Frame wnd = new Frame("Einfaches Fenster");
+
+ wnd.setSize(400,300);
+ wnd.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2303.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2303.java new file mode 100644 index 0000000..3660f0c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2303.java @@ -0,0 +1,14 @@ +/* Listing2303.java */
+
+import java.awt.*;
+
+class Listing2303
+{
+ public static void main(String[] args)
+ {
+ Frame wnd = new Frame("Fenster schließen");
+ wnd.addWindowListener(new WindowClosingAdapter(true));
+ wnd.setSize(400,300);
+ wnd.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2501.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2501.java new file mode 100644 index 0000000..3d034b7 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2501.java @@ -0,0 +1,56 @@ +/* Listing2501.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2501
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing2501 wnd = new Listing2501();
+ }
+
+ public Listing2501()
+ {
+ super("Der Farbenkreis");
+ addWindowListener(new WindowClosingAdapter(true));
+ setSize(300,200);
+ setVisible(true);
+ }
+
+ public void paint(Graphics g)
+ {
+ int top = getInsets().top;
+ int left = getInsets().left;
+ int maxX = getSize().width-left-getInsets().right;
+ int maxY = getSize().height-top-getInsets().bottom;
+ Color col;
+ int[] arx = {130,160,190};
+ int[] ary = {60,110,60};
+ int[] arr = {50,50,50};
+ int[] arcol = {0,0,0};
+ boolean paintit;
+ int dx, dy;
+
+ for (int y = 0; y < maxY; ++y) {
+ for (int x = 0; x < maxX; ++x) {
+ paintit = false;
+ for (int i = 0; i < arcol.length; ++i) {
+ dx = x - arx[i];
+ dy = y - ary[i];
+ arcol[i] = 0;
+ if ((dx*dx+dy*dy) <= arr[i]*arr[i]) {
+ arcol[i] = 255;
+ paintit = true;
+ }
+ }
+ if (paintit) {
+ col = new Color(arcol[0],arcol[1],arcol[2]);
+ g.setColor(col);
+ g.drawLine(x+left,y+top,x+left+1,y+top+1);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2502.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2502.java new file mode 100644 index 0000000..0e8ba2b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2502.java @@ -0,0 +1,49 @@ +/* Listing2502.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2502
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing2502 wnd = new Listing2502();
+ }
+
+ public Listing2502()
+ {
+ super("Systemfarben");
+ setBackground(SystemColor.desktop);
+ setSize(200,100);
+ setVisible(true);
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void paint(Graphics g)
+ {
+ g.setFont(new Font("Serif",Font.PLAIN,36));
+ FontMetrics fm = g.getFontMetrics();
+ int sheight = fm.getHeight();
+ int curx = 10;
+ int cury = getInsets().top + 10;
+ //"Tag" in normaler Textfarbe
+ int swidth = fm.stringWidth("Tag");
+ g.setColor(SystemColor.text);
+ g.fillRect(curx,cury,swidth,sheight);
+ g.setColor(SystemColor.textText);
+ g.drawString("Tag",curx,cury+fm.getAscent());
+ //"&" in Blau auf normalem Hintergrund
+ curx += swidth + 5;
+ swidth = fm.stringWidth("&");
+ g.setColor(Color.blue);
+ g.drawString("&",curx,cury+fm.getAscent());
+ //"Nacht" in hervorgehobener Textfarbe
+ curx += swidth + 5;
+ swidth = fm.stringWidth("Nacht");
+ g.setColor(SystemColor.textHighlight);
+ g.fillRect(curx,cury,swidth,sheight);
+ g.setColor(SystemColor.textHighlightText);
+ g.drawString("Nacht",curx,cury+fm.getAscent());
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2601.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2601.java new file mode 100644 index 0000000..f0a46db --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2601.java @@ -0,0 +1,94 @@ +/* Listing2601.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2601
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing2601 wnd = new Listing2601();
+ }
+
+ public Listing2601()
+ {
+ super("Drucken");
+ addWindowListener(new WindowClosingAdapter(true));
+ setBackground(Color.lightGray);
+ setSize(400,400);
+ setVisible(true);
+ //Ausdruck in 2 Sekunden starten
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ printTestPage();
+ }
+
+ public void paint(Graphics g)
+ {
+ paintGrayBoxes(g, 40, 50);
+ }
+
+ public void printTestPage()
+ {
+ PrintJob pjob = getToolkit().getPrintJob(
+ this,
+ "Testseite",
+ null
+ );
+ if (pjob != null) {
+ //Metriken
+ int pres = pjob.getPageResolution();
+ int sres = getToolkit().getScreenResolution();
+ Dimension d2 = new Dimension(
+ (int)(((21.0 - 2.0) / 2.54) * sres),
+ (int)(((29.7 - 2.0) / 2.54) * sres)
+ );
+ //Ausdruck beginnt
+ Graphics pg = pjob.getGraphics();
+ if (pg != null) {
+ //Rahmen
+ pg.drawRect(0, 0, d2.width, d2.height);
+ //Text
+ pg.setFont(new Font("TimesRoman",Font.PLAIN,24));
+ pg.drawString("Testseite",40,70);
+ pg.drawString(
+ "Druckerauflösung : " + pres + " dpi",
+ 40,
+ 100
+ );
+ pg.drawString(
+ "Bildschirmauflösung : " + sres + " dpi",
+ 40,
+ 130
+ );
+ pg.drawString(
+ "Seitengröße : " + d2.width + " * " + d2.height,
+ 40,
+ 160
+ );
+ //Graustufenkästchen
+ paintGrayBoxes(pg, 40, 200);
+ //Seite ausgeben
+ pg.dispose();
+ }
+ pjob.end();
+ }
+ }
+
+ private void paintGrayBoxes(Graphics g, int x, int y)
+ {
+ for (int i = 0; i < 16; ++i) {
+ for (int j = 0; j < 16; ++j) {
+ int level = 16 * i + j;
+ g.setColor(Color.black);
+ g.drawRect(x + 20 * j, y + 20 * i, 20, 20);
+ g.setColor(new Color(level, level, level));
+ g.fillRect(x + 1 + 20 * j, y + 1 + 20 * i, 19, 19);
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2604.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2604.java new file mode 100644 index 0000000..0a9568b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2604.java @@ -0,0 +1,50 @@ +/* Listing2604.java */
+
+import java.util.*;
+import java.io.*;
+import javax.comm.*;
+
+public class Listing2604
+{
+ public static void printHello(Writer out)
+ throws IOException
+ {
+ String s = "Hello LPT1 World";
+ s += " " + s + " " + s;
+ for (int i = 1; i <= 50; ++i) {
+ out.write(s.substring(0, i) + "\r\n");
+ }
+ out.write("\f");
+ }
+
+ public static void main(String[] args)
+ {
+ Enumeration en = CommPortIdentifier.getPortIdentifiers();
+ while (en.hasMoreElements()) {
+ CommPortIdentifier cpi = (CommPortIdentifier)en.nextElement();
+ if (cpi.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
+ if (cpi.getName().equals("LPT1")) {
+ try {
+ ParallelPort lpt1 = (ParallelPort)cpi.open(
+ "LPT1Test",
+ 1000
+ );
+ OutputStreamWriter out = new OutputStreamWriter(
+ lpt1.getOutputStream()
+ );
+ printHello(out);
+ out.close();
+ lpt1.close();
+ System.exit(0);
+ } catch (PortInUseException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2701.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2701.java new file mode 100644 index 0000000..379a436 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2701.java @@ -0,0 +1,21 @@ +/* Listing2701.java */
+
+import java.awt.*;
+
+public class Listing2701
+{
+ public static void main(String[] args)
+ {
+ Frame frame = new Frame("Frame entfernen");
+ frame.setSize(300,200);
+ frame.setVisible(true);
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ frame.setVisible(false);
+ frame.dispose();
+ System.exit(0);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2702.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2702.java new file mode 100644 index 0000000..5925695 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2702.java @@ -0,0 +1,45 @@ +/* Listing2702.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2702
+extends Window
+{
+ public static void main(String[] args)
+ {
+ final Listing2702 wnd = new Listing2702();
+ wnd.setLocation(new Point(0,0));
+ wnd.setSize(wnd.getToolkit().getScreenSize());
+ wnd.setVisible(true);
+ wnd.requestFocus();
+ wnd.addKeyListener(
+ new KeyAdapter() {
+ public void keyPressed(KeyEvent event)
+ {
+ wnd.setVisible(false);
+ wnd.dispose();
+ System.exit(0);
+ }
+ }
+ );
+ }
+
+ public Listing2702()
+ {
+ super(new Frame());
+ setBackground(Color.black);
+ }
+
+ public void paint(Graphics g)
+ {
+ g.setColor(Color.red);
+ g.drawString(
+ "Bildschirmgröße ist "+
+ getSize().width+"*"+getSize().height,
+ 10,
+ 20
+ );
+ g.drawString("Bitte eine Taste drücken",10,40);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2703.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2703.java new file mode 100644 index 0000000..62b5360 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2703.java @@ -0,0 +1,33 @@ +/* Listing2703.java */
+
+import java.awt.*;
+
+public class Listing2703
+{
+ public static void main(String[] args)
+ {
+ Frame frame = new Frame("Anzeigezustand");
+ frame.setSize(300,200);
+ frame.setVisible(true);
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ frame.setState(Frame.ICONIFIED);
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ frame.setState(Frame.NORMAL);
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ frame.setVisible(false);
+ frame.dispose();
+ System.exit(0);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2704.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2704.java new file mode 100644 index 0000000..a8ee76a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2704.java @@ -0,0 +1,68 @@ +/* Listing2704.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2704
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing2704 wnd = new Listing2704();
+ wnd.setSize(300,200);
+ wnd.setLocation(50,50);
+ wnd.setVisible(true);
+ }
+
+ public Listing2704()
+ {
+ super("");
+ assignTitle();
+ assignIcon();
+ assignCursor();
+ assignColors();
+ assignFont();
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ private void assignTitle()
+ {
+ setTitle("Veränderte Fensterelemente");
+ }
+
+ private void assignIcon()
+ {
+ Image img = getToolkit().getImage("testicon.gif");
+ MediaTracker mt = new MediaTracker(this);
+
+ mt.addImage(img, 0);
+ try {
+ //Warten, bis das Image vollständig geladen ist,
+ mt.waitForAll();
+ } catch (InterruptedException e) {
+ //nothing
+ }
+ setIconImage(img);
+ }
+
+ private void assignCursor()
+ {
+ setCursor(new Cursor(Cursor.WAIT_CURSOR));
+ }
+
+ private void assignColors()
+ {
+ setForeground(Color.white);
+ setBackground(Color.black);
+ }
+
+ private void assignFont()
+ {
+ setFont(new Font("Serif", Font.PLAIN, 28));
+ }
+
+ public void paint(Graphics g)
+ {
+ g.drawString("Test in Vordergrundfarbe",10,70);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2801.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2801.java new file mode 100644 index 0000000..15fc039 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2801.java @@ -0,0 +1,28 @@ +/* Listing2801.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2801
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing2801 wnd = new Listing2801();
+ }
+
+ public Listing2801()
+ {
+ super("Nachrichtentransfer");
+ setBackground(Color.lightGray);
+ setSize(300,200);
+ setLocation(200,100);
+ setVisible(true);
+ }
+
+ public void paint(Graphics g)
+ {
+ g.setFont(new Font("Serif",Font.PLAIN,18));
+ g.drawString("Zum Beenden bitte ESC drücken...",10,50);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2802.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2802.java new file mode 100644 index 0000000..5e1e186 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2802.java @@ -0,0 +1,47 @@ +/* Listing2802.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2802
+extends Frame
+implements KeyListener
+{
+ public static void main(String[] args)
+ {
+ Listing2802 wnd = new Listing2802();
+ }
+
+ public Listing2802()
+ {
+ super("Nachrichtentransfer");
+ setBackground(Color.lightGray);
+ setSize(300,200);
+ setLocation(200,100);
+ setVisible(true);
+ addKeyListener(this);
+ }
+
+ public void paint(Graphics g)
+ {
+ g.setFont(new Font("Serif",Font.PLAIN,18));
+ g.drawString("Zum Beenden bitte ESC drücken...",10,50);
+ }
+
+ public void keyPressed(KeyEvent event)
+ {
+ if (event.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ }
+ }
+
+ public void keyReleased(KeyEvent event)
+ {
+ }
+
+ public void keyTyped(KeyEvent event)
+ {
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2803.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2803.java new file mode 100644 index 0000000..8d25758 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2803.java @@ -0,0 +1,42 @@ +/* Listing2803.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2803
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing2803 wnd = new Listing2803();
+ }
+
+ public Listing2803()
+ {
+ super("Nachrichtentransfer");
+ setBackground(Color.lightGray);
+ setSize(300,200);
+ setLocation(200,100);
+ setVisible(true);
+ addKeyListener(new MyKeyListener());
+ }
+
+ public void paint(Graphics g)
+ {
+ g.setFont(new Font("Serif",Font.PLAIN,18));
+ g.drawString("Zum Beenden bitte ESC drücken...",10,50);
+ }
+
+ class MyKeyListener
+ extends KeyAdapter
+ {
+ public void keyPressed(KeyEvent event)
+ {
+ if (event.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2804.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2804.java new file mode 100644 index 0000000..5f8305f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2804.java @@ -0,0 +1,40 @@ +/* Listing2804.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2804
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing2804 wnd = new Listing2804();
+ }
+
+ public Listing2804()
+ {
+ super("Nachrichtentransfer");
+ setBackground(Color.lightGray);
+ setSize(300,200);
+ setLocation(200,100);
+ setVisible(true);
+ addKeyListener(
+ new KeyAdapter() {
+ public void keyPressed(KeyEvent event)
+ {
+ if (event.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ }
+ }
+ }
+ );
+ }
+
+ public void paint(Graphics g)
+ {
+ g.setFont(new Font("Serif",Font.PLAIN,18));
+ g.drawString("Zum Beenden bitte ESC drücken...",10,50);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2805.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2805.java new file mode 100644 index 0000000..5f56bf8 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2805.java @@ -0,0 +1,55 @@ +/* Listing2805.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2805
+{
+ public static void main(String[] args)
+ {
+ MainFrameCommand cmd = new MainFrameCommand();
+ MainFrameGUI gui = new MainFrameGUI(cmd);
+ }
+}
+
+class MainFrameGUI
+extends Frame
+{
+ public MainFrameGUI(KeyListener cmd)
+ {
+ super("Nachrichtentransfer");
+ setBackground(Color.lightGray);
+ setSize(300,200);
+ setLocation(200,100);
+ setVisible(true);
+ addKeyListener(cmd);
+ }
+
+ public void paint(Graphics g)
+ {
+ g.setFont(new Font("Serif",Font.PLAIN,18));
+ g.drawString("Zum Beenden bitte ESC drücken...",10,50);
+ }
+}
+
+class MainFrameCommand
+implements KeyListener
+{
+ public void keyPressed(KeyEvent event)
+ {
+ Frame source = (Frame)event.getSource();
+ if (event.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ source.setVisible(false);
+ source.dispose();
+ System.exit(0);
+ }
+ }
+
+ public void keyReleased(KeyEvent event)
+ {
+ }
+
+ public void keyTyped(KeyEvent event)
+ {
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2806.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2806.java new file mode 100644 index 0000000..07633d8 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2806.java @@ -0,0 +1,41 @@ +/* Listing2806.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2806
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing2806 wnd = new Listing2806();
+ }
+
+ public Listing2806()
+ {
+ super("Nachrichtentransfer");
+ setBackground(Color.lightGray);
+ setSize(300,200);
+ setLocation(200,100);
+ setVisible(true);
+ enableEvents(AWTEvent.KEY_EVENT_MASK);
+ }
+
+ public void paint(Graphics g)
+ {
+ g.setFont(new Font("Serif",Font.PLAIN,18));
+ g.drawString("Zum Beenden bitte ESC drücken...",10,50);
+ }
+
+ public void processKeyEvent(KeyEvent event)
+ {
+ if (event.getID() == KeyEvent.KEY_PRESSED) {
+ if (event.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ }
+ }
+ super.processKeyEvent(event);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2901.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2901.java new file mode 100644 index 0000000..5a38e94 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2901.java @@ -0,0 +1,48 @@ +/* Listing2901.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+class CloseableFrame
+extends Frame
+{
+ public CloseableFrame()
+ {
+ this("");
+ }
+
+ public CloseableFrame(String title)
+ {
+ super(title);
+ addWindowListener(
+ new WindowAdapter() {
+ public void windowClosing(WindowEvent event)
+ {
+ setVisible(false);
+ dispose();
+ }
+ }
+ );
+ }
+}
+
+public class Listing2901
+{
+ public static void main(String[] args)
+ {
+ CloseableFrame wnd = new CloseableFrame("CloseableFrame");
+ wnd.setBackground(Color.lightGray);
+ wnd.setSize(300,200);
+ wnd.setLocation(200,100);
+ wnd.setVisible(true);
+ wnd.addWindowListener(
+ new WindowAdapter() {
+ public void windowClosed(WindowEvent event)
+ {
+ System.out.println("terminating program...");
+ System.exit(0);
+ }
+ }
+ );
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2902.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2902.java new file mode 100644 index 0000000..be57239 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2902.java @@ -0,0 +1,69 @@ +/* Listing2902.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+class ComponentRepaintAdapter
+extends ComponentAdapter
+{
+ public void componentMoved(ComponentEvent event)
+ {
+ event.getComponent().repaint();
+ }
+
+ public void componentResized(ComponentEvent event)
+ {
+ event.getComponent().repaint();
+ }
+}
+
+class BirdsEyeFrame
+extends Frame
+{
+ public BirdsEyeFrame()
+ {
+ super("BirdsEyeFrame");
+ addWindowListener(new WindowClosingAdapter(true));
+ addComponentListener(new ComponentRepaintAdapter());
+ setBackground(Color.lightGray);
+ }
+
+ public void paint(Graphics g)
+ {
+ Dimension screensize = getToolkit().getScreenSize();
+ Dimension framesize = getSize();
+ double qx = framesize.width / (double)screensize.width;
+ double qy = framesize.height / (double)screensize.height;
+ g.setColor(Color.white);
+ g.fillRect(
+ (int)(qx * getLocation().x),
+ (int)(qy * getLocation().y),
+ (int)(qx * framesize.width),
+ (int)(qy * framesize.height)
+ );
+ g.setColor(Color.darkGray);
+ g.fillRect(
+ (int)(qx * getLocation().x),
+ (int)(qy * getLocation().y),
+ (int)(qx * framesize.width),
+ (int)(qy * getInsets().top)
+ );
+ g.drawRect(
+ (int)(qx * getLocation().x),
+ (int)(qy * getLocation().y),
+ (int)(qx * framesize.width),
+ (int)(qy * framesize.height)
+ );
+ }
+}
+
+public class Listing2902
+{
+ public static void main(String[] args)
+ {
+ BirdsEyeFrame wnd = new BirdsEyeFrame();
+ wnd.setSize(300,200);
+ wnd.setLocation(200,100);
+ wnd.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2903.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2903.java new file mode 100644 index 0000000..33438fc --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2903.java @@ -0,0 +1,53 @@ +/* Listing2903.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2903
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing2903 wnd = new Listing2903();
+ wnd.setSize(300,200);
+ wnd.setLocation(200,100);
+ wnd.setVisible(true);
+ }
+
+ public Listing2903()
+ {
+ super("Mausklicks");
+ addWindowListener(new WindowClosingAdapter(true));
+ addMouseListener(new MyMouseListener());
+ }
+
+ class MyMouseListener
+ extends MouseAdapter
+ {
+ int cnt = 0;
+
+ public void mousePressed(MouseEvent event)
+ {
+ Graphics g = getGraphics();
+ int x = event.getX();
+ int y = event.getY();
+ if (event.getClickCount() == 1) { //Gesicht
+ ++cnt;
+ //Kopf und Augen
+ g.drawOval(x-10,y-10,20,20);
+ g.fillRect(x-6,y-5,4,5);
+ g.fillRect(x+3,y-5,4,5);
+ //Mund
+ if (event.isMetaDown()) { //grimmig
+ g.drawLine(x-5,y+7,x+5,y+7);
+ } else { //lächeln
+ g.drawArc(x-7,y-7,14,14,225,100);
+ }
+ //Zähler
+ g.drawString(""+cnt,x+10,y-10);
+ } else if (event.getClickCount() == 2) { //Brille
+ g.drawLine(x-9,y-3,x+9,y-3);
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2904.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2904.java new file mode 100644 index 0000000..5bea4ee --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2904.java @@ -0,0 +1,92 @@ +/* Listing2904.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+
+public class Listing2904
+extends Frame
+{
+ private Vector drawlist;
+ private Rectangle actrect;
+
+ public static void main(String[] args)
+ {
+ Listing2904 wnd = new Listing2904();
+ wnd.setLocation(200,200);
+ wnd.setSize(400,300);
+ wnd.setVisible(true);
+ }
+
+ public Listing2904()
+ {
+ super("Rechtecke zeichnen");
+ drawlist = new Vector();
+ actrect = new Rectangle(0,0,0,0);
+ addWindowListener(new MyWindowListener());
+ addMouseListener(new MyMouseListener());
+ addMouseMotionListener(new MyMouseMotionListener());
+ }
+
+ public void paint(Graphics g)
+ {
+ Rectangle r;
+ Enumeration e;
+
+ for (e = drawlist.elements(); e.hasMoreElements(); ) {
+ r = (Rectangle)e.nextElement();
+ g.drawRect(r.x, r.y, r.width, r.height);
+ }
+ if (actrect.x > 0 || actrect.y > 0) {
+ g.drawRect(
+ actrect.x,
+ actrect.y,
+ actrect.width,
+ actrect.height
+ );
+ }
+ }
+
+ class MyMouseListener
+ extends MouseAdapter
+ {
+ public void mousePressed(MouseEvent event)
+ {
+ actrect = new Rectangle(event.getX(),event.getY(),0,0);
+ }
+
+ public void mouseReleased(MouseEvent event)
+ {
+ if (actrect.width > 0 || actrect.height > 0) {
+ drawlist.addElement(actrect);
+ }
+ repaint();
+ }
+ }
+
+ class MyMouseMotionListener
+ extends MouseMotionAdapter
+ {
+ public void mouseDragged(MouseEvent event)
+ {
+ int x = event.getX();
+ int y = event.getY();
+ if (x > actrect.x && y > actrect.y) {
+ actrect.width = x - actrect.x;
+ actrect.height = y - actrect.y;
+ }
+ repaint();
+ }
+ }
+
+ class MyWindowListener
+ extends WindowAdapter
+ {
+ public void windowClosing(WindowEvent event)
+ {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2905.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2905.java new file mode 100644 index 0000000..1a8d40c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2905.java @@ -0,0 +1,52 @@ +/* Listing2905.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2905
+extends Frame
+implements FocusListener
+{
+ boolean havefocus = false;
+
+ public static void main(String[] args)
+ {
+ Listing2905 wnd = new Listing2905();
+ }
+
+ public Listing2905()
+ {
+ super("Focus-Listener");
+ addFocusListener(this);
+ addWindowListener(new WindowClosingAdapter(true));
+ setBackground(Color.lightGray);
+ setSize(300,200);
+ setLocation(200,100);
+ setVisible(true);
+ }
+
+ public void paint(Graphics g)
+ {
+ if (havefocus) {
+ g.setColor(Color.black);
+ g.drawString("Fokus erhalten",10,50);
+ } else {
+ g.setColor(Color.darkGray);
+ g.drawString("Kein Fokus",10,50);
+ }
+ }
+
+ public void focusGained(FocusEvent event)
+ {
+ havefocus = true;
+ setBackground(Color.yellow);
+ repaint();
+ }
+
+ public void focusLost(FocusEvent event)
+ {
+ havefocus = false;
+ setBackground(Color.lightGray);
+ repaint();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2906.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2906.java new file mode 100644 index 0000000..77375f9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2906.java @@ -0,0 +1,109 @@ +/* Listing2906.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing2906
+extends Frame
+implements KeyListener
+{
+ String msg1 = "";
+ String msg2 = "";
+
+ public static void main(String[] args)
+ {
+ Listing2906 wnd = new Listing2906();
+ }
+
+ public Listing2906()
+ {
+ super("Tastaturereignisse");
+ addKeyListener(this);
+ addWindowListener(new WindowClosingAdapter(true));
+ setBackground(Color.lightGray);
+ setSize(300,200);
+ setLocation(200,100);
+ setVisible(true);
+ }
+
+ public void paint(Graphics g)
+ {
+ if (msg1.length() > 0) {
+ draw3DRect(g,20,50,250,30);
+ g.setColor(Color.black);
+ g.drawString(msg1,30,70);
+ }
+ if (msg2.length() > 0) {
+ draw3DRect(g,20,100,250,30);
+ g.setColor(Color.black);
+ g.drawString(msg2,30,120);
+ }
+ }
+
+ void draw3DRect(Graphics g,int x,int y,int width,int height)
+ {
+ g.setColor(Color.darkGray);
+ g.drawLine(x,y,x,y+height);
+ g.drawLine(x,y,x+width,y);
+ g.setColor(Color.white);
+ g.drawLine(x+width,y+height,x,y+height);
+ g.drawLine(x+width,y+height,x+width,y);
+ }
+
+ public void keyPressed(KeyEvent event)
+ {
+ msg1 = "";
+ System.out.println(
+ "key pressed: " +
+ "key char = " + event.getKeyChar() + " " +
+ "key code = " + event.getKeyCode()
+ );
+ if (event.getKeyChar() == KeyEvent.CHAR_UNDEFINED) {
+ int key = event.getKeyCode();
+ //Funktionstaste abfragen
+ if (key == KeyEvent.VK_F1) {
+ msg1 = "F1";
+ } else if (key == KeyEvent.VK_F2) {
+ msg1 = "F2";
+ } else if (key == KeyEvent.VK_F3) {
+ msg1 = "F3";
+ }
+ //Modifier abfragen
+ if (msg1.length() > 0) {
+ if (event.isAltDown()) {
+ msg1 = "ALT + " + msg1;
+ }
+ if (event.isControlDown()) {
+ msg1 = "STRG + " + msg1;
+ }
+ if (event.isShiftDown()) {
+ msg1 = "UMSCHALT + " + msg1;
+ }
+ }
+ }
+ repaint();
+ }
+
+ public void keyReleased(KeyEvent event)
+ {
+ System.out.println("key released");
+ msg1 = "";
+ repaint();
+ }
+
+ public void keyTyped(KeyEvent event)
+ {
+ char key = event.getKeyChar();
+ System.out.println("key typed: " + key);
+ if (key == KeyEvent.VK_BACK_SPACE) {
+ if (msg2.length() > 0) {
+ msg2 = msg2.substring(0,msg2.length() - 1);
+ }
+ } else if (key >= KeyEvent.VK_SPACE) {
+ if (msg2.length() < 40) {
+ msg2 += event.getKeyChar();
+ }
+ }
+ repaint();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3001.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3001.java new file mode 100644 index 0000000..ccb784a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3001.java @@ -0,0 +1,76 @@ +/* Listing3001.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+class MainMenu1
+extends MenuBar
+{
+ private MenuItem miRueck;
+ private CheckboxMenuItem miFarbe;
+
+ public MainMenu1()
+ {
+ Menu m;
+
+ //Datei
+ m = new Menu("Datei");
+ m.add(new MenuItem("Neu"));
+ m.add(new MenuItem("Laden"));
+ m.add(new MenuItem("Speichern"));
+ m.addSeparator();
+ m.add(new MenuItem("Beenden"));
+ add(m);
+ //Bearbeiten
+ m = new Menu("Bearbeiten");
+ m.add((miRueck = new MenuItem("Rueckgaengig")));
+ m.addSeparator();
+ m.add(new MenuItem("Ausschneiden"));
+ m.add(new MenuItem("Kopieren"));
+ m.add(new MenuItem("Einfuegen"));
+ m.add(new MenuItem("Loeschen"));
+ add(m);
+ //Optionen
+ m = new Menu("Optionen");
+ m.add(new MenuItem("Einstellungen"));
+ m.add((miFarbe = new CheckboxMenuItem("Farbe")));
+ add(m);
+ //Rueckgaengig deaktivieren
+ enableRueckgaengig(false);
+ //Farbe anschalten
+ setFarbe(true);
+ }
+
+ public void enableRueckgaengig(boolean ena)
+ {
+ if (ena) {
+ miRueck.setEnabled(true);
+ } else {
+ miRueck.setEnabled(false);
+ }
+ }
+
+ public void setFarbe(boolean on)
+ {
+ miFarbe.setState(on);
+ }
+}
+
+public class Listing3001
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing3001 wnd = new Listing3001();
+ }
+
+ public Listing3001()
+ {
+ super("Menüs");
+ setLocation(100,100);
+ setSize(400,300);
+ setMenuBar(new MainMenu1());
+ setVisible(true);
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3005.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3005.java new file mode 100644 index 0000000..4b6ae83 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3005.java @@ -0,0 +1,118 @@ +/* Listing3005.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+class MainMenu4
+extends MenuBar
+{
+ private MenuItem miRueck;
+ private CheckboxMenuItem miFarbe;
+
+ private static void
+ addNewMenuItem(Menu menu, String name, ActionListener listener)
+ {
+ int pos = name.indexOf('&');
+ MenuShortcut shortcut = null;
+ MenuItem mi;
+ if (pos != -1) {
+ if (pos < name.length() - 1) {
+ char c = name.charAt(pos + 1);
+ shortcut=new MenuShortcut(Character.toLowerCase(c));
+ name=name.substring(0,pos)+name.substring(pos + 1);
+ }
+ }
+ if (shortcut != null) {
+ mi = new MenuItem(name, shortcut);
+ } else {
+ mi = new MenuItem(name);
+ }
+ mi.setActionCommand(name);
+ mi.addActionListener(listener);
+ menu.add(mi);
+ }
+
+ public MainMenu4(ActionListener listener)
+ {
+ Menu m;
+
+ //Menü "Größe"
+ m = new Menu("Größe");
+ addNewMenuItem(m, "&Größer", listener);
+ addNewMenuItem(m, "&Kleiner", listener);
+ m.addSeparator();
+ addNewMenuItem(m, "B&eenden", listener);
+ add(m);
+
+ //Menü "Position"
+ m = new Menu("Position");
+ addNewMenuItem(m, "&Links", listener);
+ addNewMenuItem(m, "&Rechts", listener);
+ addNewMenuItem(m, "&Oben", listener);
+ addNewMenuItem(m, "&Unten", listener);
+ add(m);
+ }
+}
+
+public class Listing3005
+extends Frame
+implements ActionListener
+{
+ public static void main(String[] args)
+ {
+ Listing3005 wnd = new Listing3005();
+ }
+
+ public Listing3005()
+ {
+ super("Menü-ActionEvents");
+ setLocation(100,100);
+ setSize(300,200);
+ setMenuBar(new MainMenu4(this));
+ setVisible(true);
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void paint(Graphics g)
+ {
+ Insets in = getInsets();
+ Dimension d = getSize();
+ g.setColor(Color.red);
+ g.drawLine(
+ in.left, in.top,
+ d.width - in.right, d.height - in.bottom
+ );
+ g.drawLine(
+ in.left, d.height - in.bottom,
+ d.width - in.right, in.top
+ );
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("Größer")) {
+ Dimension d = getSize();
+ d.height *= 1.05;
+ d.width *= 1.05;
+ setSize(d);
+ } else if (cmd.equals("Kleiner")) {
+ Dimension d = getSize();
+ d.height *= 0.95;
+ d.width *= 0.95;
+ setSize(d);
+ } else if (cmd.equals("Beenden")) {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ } else if (cmd.equals("Links")) {
+ setLocation(getLocation().x-10, getLocation().y);
+ } else if (cmd.equals("Rechts")) {
+ setLocation(getLocation().x+10, getLocation().y);
+ } else if (cmd.equals("Oben")) {
+ setLocation(getLocation().x, getLocation().y-10);
+ } else if (cmd.equals("Unten")) {
+ setLocation(getLocation().x, getLocation().y+10);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3006.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3006.java new file mode 100644 index 0000000..636c826 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3006.java @@ -0,0 +1,73 @@ +/* Listing3006.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+class MyPopupMenu
+extends PopupMenu
+{
+ public MyPopupMenu(ActionListener listener)
+ {
+ MenuItem mi;
+
+ mi = new MenuItem("Rueckgaengig");
+ mi.addActionListener(listener);
+ add(mi);
+
+ addSeparator();
+
+ mi = new MenuItem("Ausschneiden");
+ mi.addActionListener(listener);
+ add(mi);
+
+ mi = new MenuItem("Kopieren");
+ mi.addActionListener(listener);
+ add(mi);
+
+ mi = new MenuItem("Einfuegen");
+ mi.addActionListener(listener);
+ add(mi);
+ }
+}
+
+public class Listing3006
+extends Frame
+implements ActionListener
+{
+ MyPopupMenu popup;
+
+ public static void main(String[] args)
+ {
+ Listing3006 wnd = new Listing3006();
+ }
+
+ public Listing3006()
+ {
+ super("Kontextmenü");
+ setLocation(100,100);
+ setSize(300,200);
+ setVisible(true);
+ addWindowListener(new WindowClosingAdapter(true));
+ //Kontextmenü erzeugen und aktivieren
+ popup = new MyPopupMenu(this);
+ add(popup);
+ enableEvents(AWTEvent.MOUSE_EVENT_MASK);
+ }
+
+ public void processMouseEvent(MouseEvent event)
+ {
+ if (event.isPopupTrigger()) {
+ popup.show(
+ event.getComponent(),
+ event.getX(),
+ event.getY()
+ );
+ }
+ super.processMouseEvent(event);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ System.out.println(event.getActionCommand());
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3101.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3101.java new file mode 100644 index 0000000..374f70c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3101.java @@ -0,0 +1,24 @@ +/* Listing3101.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3101
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing3101 wnd = new Listing3101();
+ wnd.setVisible(true);
+ }
+
+ public Listing3101()
+ {
+ super("Dialogtest");
+ addWindowListener(new WindowClosingAdapter(true));
+ setLayout(new FlowLayout());
+ add(new Button("Abbruch"));
+ add(new Button("OK"));
+ pack();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3102.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3102.java new file mode 100644 index 0000000..4d5fc48 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3102.java @@ -0,0 +1,28 @@ +/* Listing3102.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3102
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing3102 wnd = new Listing3102();
+ wnd.setVisible(true);
+ }
+
+ public Listing3102()
+ {
+ super("Test FlowLayout");
+ addWindowListener(new WindowClosingAdapter(true));
+ //Layout setzen und Komponenten hinzufügen
+ setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
+ add(new Button("Button 1"));
+ add(new Button("Button 2"));
+ add(new Button("Button 3"));
+ add(new Button("Button 4"));
+ add(new Button("Button 5"));
+ pack();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3103.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3103.java new file mode 100644 index 0000000..0e6d684 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3103.java @@ -0,0 +1,30 @@ +/* Listing3103.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3103
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing3103 wnd = new Listing3103();
+ wnd.setVisible(true);
+ }
+
+ public Listing3103()
+ {
+ super("Test GridLayout");
+ addWindowListener(new WindowClosingAdapter(true));
+ //Layout setzen und Komponenten hinzufügen
+ setLayout(new GridLayout(4,2));
+ add(new Button("Button 1"));
+ add(new Button("Button 2"));
+ add(new Button("Button 3"));
+ add(new Button("Button 4"));
+ add(new Button("Button 5"));
+ add(new Button("Button 6"));
+ add(new Button("Button 7"));
+ pack();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3104.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3104.java new file mode 100644 index 0000000..9ad4f12 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3104.java @@ -0,0 +1,28 @@ +/* Listing3104.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3104
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing3104 wnd = new Listing3104();
+ wnd.setVisible(true);
+ }
+
+ public Listing3104()
+ {
+ super("Test BorderLayout");
+ addWindowListener(new WindowClosingAdapter(true));
+ //Layout setzen und Komponenten hinzufügen
+ setSize(300,200);
+ setLayout(new BorderLayout());
+ add(new Button("Button 1"), BorderLayout.NORTH);
+ add(new Button("Button 2"), BorderLayout.SOUTH);
+ add(new Button("Button 3"), BorderLayout.WEST);
+ add(new Button("Button 4"), BorderLayout.EAST);
+ add(new Button("Button 5"), BorderLayout.CENTER);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3106.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3106.java new file mode 100644 index 0000000..49a0237 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3106.java @@ -0,0 +1,74 @@ +/* Listing3106.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3106
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing3106 wnd = new Listing3106();
+ wnd.setVisible(true);
+ }
+
+ public Listing3106()
+ {
+ super("Test GridBagLayout");
+ setBackground(Color.lightGray);
+ addWindowListener(new WindowClosingAdapter(true));
+ //Layout setzen und Komponenten hinzufügen
+ GridBagLayout gbl = new GridBagLayout();
+ GridBagConstraints gbc;
+ setLayout(gbl);
+
+ //List hinzufügen
+ List list = new List();
+ for (int i = 0; i < 20; ++i) {
+ list.add("This is item " + i);
+ }
+ gbc = makegbc(0, 0, 1, 3);
+ gbc.weightx = 100;
+ gbc.weighty = 100;
+ gbc.fill = GridBagConstraints.BOTH;
+ gbl.setConstraints(list, gbc);
+ add(list);
+ //Zwei Labels und zwei Textfelder
+ for (int i = 0; i < 2; ++i) {
+ //Label
+ gbc = makegbc(1, i, 1, 1);
+ gbc.fill = GridBagConstraints.NONE;
+ Label label = new Label("Label " + (i + 1));
+ gbl.setConstraints(label, gbc);
+ add(label);
+ //Textfeld
+ gbc = makegbc(2, i, 1, 1);
+ gbc.weightx = 100;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ TextField field = new TextField("TextField " + (i +1));
+ gbl.setConstraints(field, gbc);
+ add(field);
+ }
+ //Ende-Button
+ Button button = new Button("Ende");
+ gbc = makegbc(2, 2, 0, 0);
+ gbc.fill = GridBagConstraints.NONE;
+ gbc.anchor = GridBagConstraints.SOUTHEAST;
+ gbl.setConstraints(button, gbc);
+ add(button);
+ //Dialogelemente layouten
+ pack();
+ }
+
+ private GridBagConstraints makegbc(
+ int x, int y, int width, int height)
+ {
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.gridx = x;
+ gbc.gridy = y;
+ gbc.gridwidth = width;
+ gbc.gridheight = height;
+ gbc.insets = new Insets(1, 1, 1, 1);
+ return gbc;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3107.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3107.java new file mode 100644 index 0000000..f40b445 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3107.java @@ -0,0 +1,28 @@ +/* Listing3107.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3107
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing3107 wnd = new Listing3107();
+ wnd.setVisible(true);
+ }
+
+ public Listing3107()
+ {
+ super("Dialogelemente ohne Layoutmanager");
+ addWindowListener(new WindowClosingAdapter(true));
+ //Layout setzen und Komponenten hinzufügen
+ setSize(300,250);
+ setLayout(null);
+ for (int i = 0; i < 5; ++i) {
+ Button button = new Button("Button"+(i+1));
+ button.setBounds(10+i*35,40+i*35,100,30);
+ add(button);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3108.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3108.java new file mode 100644 index 0000000..0e0b5b8 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3108.java @@ -0,0 +1,40 @@ +/* Listing3108.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3108
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing3108 wnd = new Listing3108();
+ wnd.setVisible(true);
+ }
+
+ public Listing3108()
+ {
+ super("Geschachtelte Layoutmanager");
+ addWindowListener(new WindowClosingAdapter(true));
+ //Layout setzen und Komponenten hinzufügen
+ //Panel 1
+ Panel panel1 = new Panel();
+ panel1.setLayout(new GridLayout(3,1));
+ panel1.add(new Button("Button1"));
+ panel1.add(new Button("Button2"));
+ panel1.add(new Button("Button3"));
+ //Panel 2
+ Panel panel2 = new Panel();
+ panel2.setLayout(new BorderLayout());
+ panel2.add(new Button("Button4"), BorderLayout.NORTH);
+ panel2.add(new Button("Button5"), BorderLayout.SOUTH);
+ panel2.add(new Button("Button6"), BorderLayout.WEST);
+ panel2.add(new Button("Button7"), BorderLayout.EAST);
+ panel2.add(new Button("Button8"), BorderLayout.CENTER);
+ //Hauptfenster
+ setLayout(new GridLayout(1,2));
+ add(panel1);
+ add(panel2);
+ pack();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3109.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3109.java new file mode 100644 index 0000000..a90bce0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3109.java @@ -0,0 +1,40 @@ +/* Listing3109.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3109
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing3109 wnd = new Listing3109();
+ wnd.setVisible(true);
+ }
+
+ public Listing3109()
+ {
+ super("Geschachtelte Layoutmanager, Teil II");
+ addWindowListener(new WindowClosingAdapter(true));
+ //Layout setzen und Komponenten hinzufügen
+ setSize(300,200);
+ //Panel 1
+ Panel panel1 = new Panel();
+ panel1.setLayout(new GridLayout(3,2));
+ panel1.add(new Button("Button1"));
+ panel1.add(new Button("Button2"));
+ panel1.add(new Button("Button3"));
+ panel1.add(new Button("Button4"));
+ panel1.add(new Button("Button5"));
+ panel1.add(new Button("Button6"));
+ //Panel 2
+ Panel panel2 = new Panel();
+ panel2.setLayout(new FlowLayout(FlowLayout.RIGHT));
+ panel2.add(new Button("Abbruch"));
+ panel2.add(new Button("OK"));
+ //Hauptfenster
+ setLayout(new BorderLayout());
+ add(panel1, BorderLayout.CENTER);
+ add(panel2, BorderLayout.SOUTH);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java new file mode 100644 index 0000000..c785bb7 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java @@ -0,0 +1,90 @@ +/* Listing3110.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+class YesNoDialog
+extends Dialog
+implements ActionListener
+{
+ boolean result;
+
+ public YesNoDialog(Frame owner, String msg)
+ {
+ super(owner, "Ja-/Nein-Auswahl", true);
+ //Fenster
+ setBackground(Color.lightGray);
+ setLayout(new BorderLayout());
+ setResizable(false); //Hinweis im Text beachten
+ Point parloc = owner.getLocation();
+ setLocation(parloc.x + 30, parloc.y + 30);
+ //Message
+ add(new Label(msg), BorderLayout.CENTER);
+ //Buttons
+ Panel panel = new Panel();
+ panel.setLayout(new FlowLayout(FlowLayout.CENTER));
+ Button button = new Button("Ja");
+ button.addActionListener(this);
+ panel.add(button);
+ button = new Button("Nein");
+ button.addActionListener(this);
+ panel.add(button);
+ add(panel, BorderLayout.SOUTH);
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ result = event.getActionCommand().equals("Ja");
+ setVisible(false);
+ dispose();
+ }
+
+ public boolean getResult()
+ {
+ return result;
+ }
+}
+
+public class Listing3110
+extends Frame
+implements ActionListener
+{
+ public static void main(String[] args)
+ {
+ Listing3110 wnd = new Listing3110();
+ wnd.setVisible(true);
+ }
+
+ public Listing3110()
+ {
+ super("Modale Dialoge");
+ setLayout(new FlowLayout());
+ setBackground(Color.lightGray);
+ Button button = new Button("Ende");
+ button.addActionListener(this);
+ add(button);
+ setLocation(100,100);
+ setSize(300,200);
+ setVisible(true);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("Ende")) {
+ YesNoDialog dlg;
+ dlg = new YesNoDialog(
+ this,
+ "Wollen Sie das Programm wirklich beenden?"
+ );
+ dlg.setVisible(true);
+ //Auf das Schließen des Dialogs warten...
+ if (dlg.getResult()) {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3111.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3111.java new file mode 100644 index 0000000..22c3b5e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3111.java @@ -0,0 +1,129 @@ +/* Listing3111.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+
+class ModalDialog
+extends Dialog
+implements ActionListener
+{
+ String result;
+
+ public static String OKDialog(Frame owner, String msg)
+ {
+ ModalDialog dlg;
+ dlg = new ModalDialog(owner,"Nachricht",msg,"OK");
+ dlg.setVisible(true);
+ return dlg.getResult();
+ }
+
+ public static String YesNoDialog(Frame owner, String msg)
+ {
+ ModalDialog dlg;
+ dlg = new ModalDialog(owner,"Frage",msg,"Ja,Nein");
+ dlg.setVisible(true);
+ return dlg.getResult();
+ }
+
+ public static String YesNoCancelDialog(Frame owner,String msg)
+ {
+ ModalDialog dlg;
+ dlg = new ModalDialog(owner,"Frage",msg,"Ja,Nein,Abbruch");
+ dlg.setVisible(true);
+ return dlg.getResult();
+ }
+
+ public ModalDialog(
+ Frame owner,
+ String title,
+ String msg,
+ String buttons
+ )
+ {
+ super(owner, title, true);
+ //Fenster
+ setBackground(Color.lightGray);
+ setLayout(new BorderLayout());
+ setResizable(false);
+ Point parloc = owner.getLocation();
+ setLocation(parloc.x + 30, parloc.y + 30);
+ //Message
+ add(new Label(msg), BorderLayout.CENTER);
+ //Buttons
+ Panel panel = new Panel();
+ panel.setLayout(new FlowLayout(FlowLayout.CENTER));
+ StringTokenizer strtok = new StringTokenizer(buttons,",");
+ while (strtok.hasMoreTokens()) {
+ Button button = new Button(strtok.nextToken());
+ button.addActionListener(this);
+ panel.add(button);
+ }
+ add(panel, BorderLayout.SOUTH);
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ result = event.getActionCommand();
+ setVisible(false);
+ dispose();
+ }
+
+ public String getResult()
+ {
+ return result;
+ }
+}
+
+public class Listing3111
+extends Frame
+implements ActionListener
+{
+ public static void main(String[] args)
+ {
+ Listing3111 wnd = new Listing3111();
+ wnd.setVisible(true);
+ }
+
+ public Listing3111()
+ {
+ super("Drei modale Standarddialoge");
+ setLayout(new FlowLayout());
+ setBackground(Color.lightGray);
+ Button button = new Button("OKDialog");
+ button.addActionListener(this);
+ add(button);
+ button = new Button("YesNoDialog");
+ button.addActionListener(this);
+ add(button);
+ button = new Button("YesNoCancelDialog");
+ button.addActionListener(this);
+ add(button);
+ setLocation(100,100);
+ setSize(400,200);
+ setVisible(true);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("OKDialog")) {
+ ModalDialog.OKDialog(this,"Dream, dream, dream, ...");
+ } else if (cmd.equals("YesNoDialog")) {
+ String ret = ModalDialog.YesNoDialog(
+ this,
+ "Programm beenden?"
+ );
+ if (ret.equals("Ja")) {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ }
+ } else if (cmd.equals("YesNoCancelDialog")) {
+ String msg = "Verzeichnis erstellen?";
+ String ret = ModalDialog.YesNoCancelDialog(this,msg);
+ ModalDialog.OKDialog(this,"Rückgabe: " + ret);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3216.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3216.java new file mode 100644 index 0000000..b3c6a51 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3216.java @@ -0,0 +1,144 @@ +/* Listing3216.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+class NamedSystemColors
+{
+ String[] names;
+ SystemColor[] colors;
+
+ public NamedSystemColors()
+ {
+ names = new String[SystemColor.NUM_COLORS];
+ colors = new SystemColor[SystemColor.NUM_COLORS];
+ names [ 0] = "desktop";
+ colors[ 0] = SystemColor.desktop;
+ names [ 1]= "activeCaption";
+ colors[ 1] = SystemColor.activeCaption;
+ names [ 2] = "activeCaptionText";
+ colors[ 2] = SystemColor.activeCaptionText;
+ names [ 3] = "activeCaptionBorder";
+ colors[ 3] = SystemColor.activeCaptionBorder;
+ names [ 4] = "inactiveCaption";
+ colors[ 4] = SystemColor.inactiveCaption;
+ names [ 5] = "inactiveCaptionText";
+ colors[ 5] = SystemColor.inactiveCaptionText;
+ names [ 6] = "inactiveCaptionBorder";
+ colors[ 6] = SystemColor.inactiveCaptionBorder;
+ names [ 7] = "window";
+ colors[ 7] = SystemColor.window;
+ names [ 8] = "windowBorder";
+ colors[ 8] = SystemColor.windowBorder;
+ names [ 9] = "windowText";
+ colors[ 9] = SystemColor.windowText;
+ names [10] = "menu";
+ colors[10] = SystemColor.menu;
+ names [11] = "menuText";
+ colors[11] = SystemColor.menuText;
+ names [12] = "text";
+ colors[12] = SystemColor.text;
+ names [13] = "textText";
+ colors[13] = SystemColor.textText;
+ names [14] = "textHighlight";
+ colors[14] = SystemColor.textHighlight;
+ names [15] = "textHighlightText";
+ colors[15] = SystemColor.textHighlightText;
+ names [16] = "textInactiveText";
+ colors[16] = SystemColor.textInactiveText;
+ names [17] = "control";
+ colors[17] = SystemColor.control;
+ names [18] = "controlText";
+ colors[18] = SystemColor.controlText;
+ names [19] = "controlHighlight";
+ colors[19] = SystemColor.controlHighlight;
+ names [20] = "controlLtHighlight";
+ colors[20] = SystemColor.controlLtHighlight;
+ names [21] = "controlShadow";
+ colors[21] = SystemColor.controlShadow;
+ names [22] = "controlDkShadow";
+ colors[22] = SystemColor.controlDkShadow;
+ names [23] = "scrollbar";
+ colors[23] = SystemColor.scrollbar;
+ names [24] = "info";
+ colors[24] = SystemColor.info;
+ names [25] = "infoText";
+ colors[25] = SystemColor.infoText;
+ }
+
+ public int getSize()
+ {
+ return SystemColor.NUM_COLORS;
+ }
+
+ public String getName(int i)
+ {
+ return names[i];
+ }
+
+ public SystemColor getColor(int i)
+ {
+ return colors[i];
+ }
+}
+
+class SystemColorViewer
+extends Canvas
+{
+ NamedSystemColors colors;
+
+ public SystemColorViewer()
+ {
+ colors = new NamedSystemColors();
+ }
+
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(150,16 + colors.getSize() * 20);
+ }
+
+ public void paint(Graphics g)
+ {
+ for (int i = 0; i < colors.getSize(); ++i) {
+ //Rahmen für Farbbox
+ g.setColor(Color.black);
+ g.drawRect(10,16+20*i,16,16);
+ //Farbbox
+ g.setColor(colors.getColor(i));
+ g.fillRect(11,17+20*i,15,15);
+ //Bezeichnung
+ g.setColor(Color.black);
+ g.drawString(colors.getName(i),30,30+20*i);
+ }
+ }
+}
+
+public class Listing3216
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing3216 wnd = new Listing3216();
+ wnd.setLocation(200,100);
+ wnd.setVisible(true);
+ }
+
+ public Listing3216()
+ {
+ super("ScrollPane");
+ setBackground(Color.lightGray);
+ //ScrollPane
+ ScrollPane sc = new ScrollPane(
+ ScrollPane.SCROLLBARS_AS_NEEDED
+ );
+ sc.add(new SystemColorViewer());
+ sc.getVAdjustable().setUnitIncrement(1);
+ sc.getHAdjustable().setUnitIncrement(1);
+ sc.setSize(200,200);
+ add(sc);
+ //Window-Listener
+ addWindowListener(new WindowClosingAdapter(true));
+ //Dialogelement anordnen
+ pack();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3302.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3302.java new file mode 100644 index 0000000..122da09 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3302.java @@ -0,0 +1,107 @@ +/* Listing3302.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+class MyDialog3302
+extends Dialog
+implements ActionListener
+{
+ public MyDialog3302(Frame parent)
+ {
+ super(parent,"MyDialog3302",true);
+ setBounds(100,100,400,300);
+ setBackground(Color.lightGray);
+ setLayout(new BorderLayout());
+ Panel panel = new Panel();
+ customizeLayout(panel);
+ add(panel, BorderLayout.CENTER);
+ //Ende-Button
+ Button button = new Button("Ende");
+ button.addActionListener(this);
+ add(button, BorderLayout.SOUTH);
+ pack();
+ //Window-Ereignisse
+ addWindowListener(
+ new WindowAdapter() {
+ public void windowClosing(WindowEvent event)
+ {
+ endDialog();
+ }
+ }
+ );
+ }
+
+ private void customizeLayout(Panel panel)
+ {
+ panel.setLayout(new FlowLayout());
+ panel.add(new Segment7(0));
+ panel.add(new Segment7(1));
+ panel.add(new Segment7(2));
+ panel.add(new Segment7(3));
+ panel.add(new Segment7(4));
+ panel.add(new Segment7(5));
+ panel.add(new Segment7(6));
+ panel.add(new Segment7(7));
+ panel.add(new Segment7(8));
+ panel.add(new Segment7(9));
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("Ende")) {
+ endDialog();
+ }
+ }
+
+ void endDialog()
+ {
+ setVisible(false);
+ dispose();
+ ((Window)getParent()).toFront();
+ getParent().requestFocus();
+ }
+}
+
+public class Listing3302
+extends Frame
+implements ActionListener
+{
+ public static void main(String[] args)
+ {
+ Listing3302 wnd = new Listing3302();
+ wnd.setSize(300,200);
+ wnd.setVisible(true);
+ }
+
+ public Listing3302()
+ {
+ super("7-Segment-Anzeige");
+ setBackground(Color.lightGray);
+ setLayout(new FlowLayout());
+ //Dialog-Button
+ Button button = new Button("Dialog");
+ button.addActionListener(this);
+ add(button);
+ //Ende-Button
+ button = new Button("Ende");
+ button.addActionListener(this);
+ add(button);
+ //Window-Ereignisse
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("Dialog")) {
+ MyDialog3302 dlg = new MyDialog3302(this);
+ dlg.setVisible(true);
+ } else if (cmd.equals("Ende")) {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3403.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3403.java new file mode 100644 index 0000000..82460eb --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3403.java @@ -0,0 +1,43 @@ +/* Listing3403.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3403
+extends Frame
+{
+ private Image img;
+
+ public static void main(String[] args)
+ {
+ Listing3403 wnd = new Listing3403();
+ }
+
+ public Listing3403()
+ {
+ super("Bitmap");
+ setBackground(Color.lightGray);
+ setSize(250,150);
+ setVisible(true);
+ //WindowListener
+ addWindowListener(new WindowClosingAdapter(true));
+ //Bild laden
+ img = getToolkit().getImage("duke.gif");
+ MediaTracker mt = new MediaTracker(this);
+ mt.addImage(img, 0);
+ try {
+ //Warten, bis das Image vollständig geladen ist,
+ mt.waitForAll();
+ } catch (InterruptedException e) {
+ //nothing
+ }
+ repaint();
+ }
+
+ public void paint(Graphics g)
+ {
+ if (img != null) {
+ g.drawImage(img,40,40,this);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3405.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3405.java new file mode 100644 index 0000000..fa6b6e2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3405.java @@ -0,0 +1,30 @@ +/* Listing3405.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3405
+extends Frame
+{
+ public static void main(String[] args)
+ {
+ Listing3405 wnd = new Listing3405();
+ }
+
+ public Listing3405()
+ {
+ super("Bitmap-Komponente");
+ setBackground(Color.lightGray);
+ setSize(250,150);
+ setVisible(true);
+ //Hinzufügen der Komponenten
+ setLayout(new GridLayout(2,2));
+ add(new BitmapComponent("duke.gif"));
+ add(new BitmapComponent("duke.gif"));
+ add(new BitmapComponent("duke.gif"));
+ add(new BitmapComponent("duke.gif"));
+ pack();
+ //WindowListener
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3406.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3406.java new file mode 100644 index 0000000..2790de8 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3406.java @@ -0,0 +1,42 @@ +/* Listing3406.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3406
+extends Frame
+{
+ int cnt = 0;
+
+ public static void main(String[] args)
+ {
+ Listing3406 wnd = new Listing3406();
+ wnd.setSize(250,150);
+ wnd.setVisible(true);
+ wnd.startAnimation();
+ }
+
+ public Listing3406()
+ {
+ super("Animierter Zähler");
+ setBackground(Color.lightGray);
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void startAnimation()
+ {
+ while (true) {
+ repaint();
+ }
+ }
+
+ public void paint(Graphics g)
+ {
+ ++cnt;
+ g.drawString("Counter = "+cnt,10,50);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3407.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3407.java new file mode 100644 index 0000000..36095ff --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3407.java @@ -0,0 +1,50 @@ +/* Listing3407.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3407
+extends Frame
+implements Runnable
+{
+ int cnt = 0;
+
+ public static void main(String[] args)
+ {
+ Listing3407 wnd = new Listing3407();
+ wnd.setSize(250,150);
+ wnd.setVisible(true);
+ wnd.startAnimation();
+ }
+
+ public Listing3407()
+ {
+ super("Animations-Threads");
+ setBackground(Color.lightGray);
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void startAnimation()
+ {
+ Thread th = new Thread(this);
+ th.start();
+ }
+
+ public void run()
+ {
+ while (true) {
+ repaint();
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ }
+ }
+
+ public void paint(Graphics g)
+ {
+ ++cnt;
+ g.drawString("Counter = "+cnt,10,50);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3408.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3408.java new file mode 100644 index 0000000..42c8f4f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3408.java @@ -0,0 +1,73 @@ +/* Listing3408.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3408
+extends Frame
+implements Runnable
+{
+ Thread th;
+ Image[] arImg;
+ int actimage;
+
+ public static void main(String[] args)
+ {
+ Listing3408 wnd = new Listing3408();
+ wnd.setSize(200,150);
+ wnd.setVisible(true);
+ wnd.startAnimation();
+ }
+
+ public Listing3408()
+ {
+ super("Bitmap-Folge");
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void startAnimation()
+ {
+ th = new Thread(this);
+ actimage = -1;
+ th.start();
+ }
+
+ public void run()
+ {
+ //Bilder laden
+ arImg = new Image[30];
+ MediaTracker mt = new MediaTracker(this);
+ Toolkit tk = getToolkit();
+ for (int i = 1; i <= 30; ++i) {
+ arImg[i-1] = tk.getImage("images/jana"+i+".gif");
+ mt.addImage(arImg[i-1], 0);
+ actimage = -i;
+ repaint();
+ try {
+ mt.waitForAll();
+ } catch (InterruptedException e) {
+ //nothing
+ }
+ }
+ //Animation beginnen
+ actimage = 0;
+ while (true) {
+ repaint();
+ actimage = (actimage + 1) % 30;
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ }
+ }
+
+ public void paint(Graphics g)
+ {
+ if (actimage < 0) {
+ g.drawString("Lade Bitmap "+(-actimage),10,50);
+ } else {
+ g.drawImage(arImg[actimage],10,30,this);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3409.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3409.java new file mode 100644 index 0000000..58f20bc --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3409.java @@ -0,0 +1,176 @@ +/* Listing3409.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+
+class ColorRectangle
+extends Rectangle
+{
+ public Color color;
+}
+
+public class Listing3409
+extends Frame
+implements Runnable
+{
+ //Konstanten
+ private static final int SIZERECT = 7;
+ private static final int SLEEP = 40;
+ private static final int NUMELEMENTS = 20;
+ private static final Color BGCOLOR = Color.lightGray;
+
+ //Instanzvariablen
+ private Thread th;
+ private Vector snake;
+ private int dx;
+ private int dy;
+
+ public static void main(String[] args)
+ {
+ Listing3409 frame = new Listing3409();
+ frame.setSize(200,150);
+ frame.setVisible(true);
+ frame.startAnimation();
+ }
+
+ public Listing3409()
+ {
+ super("Animierte Schlange");
+ setBackground(BGCOLOR);
+ addWindowListener(new WindowClosingAdapter(true));
+ snake = new Vector();
+ }
+
+ public void startAnimation()
+ {
+ th = new Thread(this);
+ th.start();
+ }
+
+ public void run()
+ {
+ //Schlange konstruieren
+ ColorRectangle cr;
+ int x = 100;
+ int y = 100;
+ for (int i=0; i < NUMELEMENTS; ++i) {
+ cr = new ColorRectangle();
+ cr.x = x;
+ cr.y = y;
+ cr.width = SIZERECT;
+ cr.height = SIZERECT;
+ x += SIZERECT;
+ cr.color = new Color(
+ i*(256/NUMELEMENTS),
+ 0,
+ 240-i*(256/NUMELEMENTS)
+ );
+ snake.addElement(cr);
+ }
+
+ //Vorzugsrichtung festlegen
+ dx = -1;
+ dy = -1;
+
+ //Schlange laufen lassen
+ while (true) {
+ repaint();
+ try {
+ Thread.sleep(SLEEP);
+ } catch (InterruptedException e){
+ //nichts
+ }
+ moveSnake();
+ }
+ }
+
+ public void moveSnake()
+ {
+ Dimension size = getSize();
+ int sizex = size.width-getInsets().left-getInsets().right;
+ int sizey = size.height-getInsets().top-getInsets().bottom;
+ ColorRectangle cr = (ColorRectangle)snake.firstElement();
+ boolean lBorder = false;
+ int xalt, yalt;
+ int xtmp, ytmp;
+
+ //Kopf der Schlange neu berechnen
+ if (cr.x <= 1) {
+ dx = 1;
+ lBorder = true;
+ }
+ if (cr.x + cr.width >= sizex) {
+ dx = -1;
+ lBorder = true;
+ }
+ if (cr.y <= 1) {
+ dy = 1;
+ lBorder = true;
+ }
+ if (cr.y + cr.height >= sizey) {
+ dy = -1;
+ lBorder = true;
+ }
+ if (! lBorder) {
+ if (rand(10) == 0) {
+ if (rand(2) == 0) {
+ switch (rand(5)) {
+ case 0: case 1:
+ dx = -1;
+ break;
+ case 2:
+ dx = 0;
+ break;
+ case 3: case 4:
+ dx = 1;
+ break;
+ }
+ } else {
+ switch (rand(5)) {
+ case 0: case 1:
+ dy = -1;
+ break;
+ case 2:
+ dy = 0;
+ break;
+ case 3: case 4:
+ dy = 1;
+ break;
+ }
+ }
+ }
+ }
+ xalt = cr.x + SIZERECT * dx;
+ yalt = cr.y + SIZERECT * dy;
+ //Rest der Schlange hinterherziehen
+ Enumeration e = snake.elements();
+ while (e.hasMoreElements()) {
+ cr = (ColorRectangle)e.nextElement();
+ xtmp = cr.x;
+ ytmp = cr.y;
+ cr.x = xalt;
+ cr.y = yalt;
+ xalt = xtmp;
+ yalt = ytmp;
+ }
+ }
+
+ public void paint(Graphics g)
+ {
+ ColorRectangle cr;
+ Enumeration e = snake.elements();
+ int inleft = getInsets().left;
+ int intop = getInsets().top;
+ while (e.hasMoreElements()) {
+ cr = (ColorRectangle)e.nextElement();
+ g.setColor(cr.color);
+ g.fillRect(cr.x+inleft,cr.y+intop,cr.width,cr.height);
+ }
+ }
+
+ private int rand(int limit)
+ {
+ return (int)(Math.random() * limit);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3410.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3410.java new file mode 100644 index 0000000..c65b520 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3410.java @@ -0,0 +1,69 @@ +/* Listing3410.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3410
+extends Frame
+implements Runnable
+{
+ //Konstanten
+ private static final int NUMLEDS = 20;
+ private static final int SLEEP = 60;
+ private static final int LEDSIZE = 10;
+ private static final Color ONCOLOR = new Color(255,0,0);
+ private static final Color OFFCOLOR = new Color(100,0,0);
+
+ //Instanzvariablen
+ private Thread th;
+ private int switched;
+ private int dx;
+
+ public static void main(String[] args)
+ {
+ Listing3410 frame = new Listing3410();
+ frame.setSize(270,150);
+ frame.setVisible(true);
+ frame.startAnimation();
+ }
+
+ public Listing3410()
+ {
+ super("Leuchtdiodenkette");
+ setBackground(Color.lightGray);
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void startAnimation()
+ {
+ th = new Thread(this);
+ th.start();
+ }
+
+ public void run()
+ {
+ switched = -1;
+ dx = 1;
+ while (true) {
+ repaint();
+ try {
+ Thread.sleep(SLEEP);
+ } catch (InterruptedException e){
+ //nichts
+ }
+ switched += dx;
+ if (switched < 0 || switched > NUMLEDS - 1) {
+ dx = -dx;
+ switched += 2*dx;
+ }
+ }
+ }
+
+ public void paint(Graphics g)
+ {
+ for (int i = 0; i < NUMLEDS; ++i) {
+ g.setColor(i == switched ? ONCOLOR : OFFCOLOR);
+ g.fillOval(10+i*(LEDSIZE+2),80,LEDSIZE,LEDSIZE);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3415.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3415.java new file mode 100644 index 0000000..6b6bfac --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3415.java @@ -0,0 +1,99 @@ +/* Listing3415.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3415
+extends Frame
+implements Runnable
+{
+ private Thread th;
+ private int actx;
+ private int dx;
+ private int actarc1;
+ private int actarc2;
+ private Image dbImage;
+ private Graphics dbGraphics;
+
+ public static void main(String[] args)
+ {
+ Listing3415 frame = new Listing3415();
+ frame.setSize(210,170);
+ frame.setVisible(true);
+ frame.startAnimation();
+ }
+
+ public Listing3415()
+ {
+ super("Ameisenanimation");
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void startAnimation()
+ {
+ Thread th = new Thread(this);
+ th.start();
+ }
+
+ public void run()
+ {
+ actx = 0;
+ dx = 1;
+ actarc1 = 0;
+ actarc2 = 0;
+ while (true) {
+ repaint();
+ actx += dx;
+ if (actx < 0 || actx > 100) {
+ dx = -dx;
+ actx += 2*dx;
+ }
+ actarc1 = (actarc1 + 1) % 360;
+ actarc2 = (actarc2 + 2) % 360;
+ try {
+ Thread.sleep(40);
+ } catch (InterruptedException e) {
+ //nichts
+ }
+ }
+ }
+
+ public void update(Graphics g)
+ {
+ //Double-Buffer initialisieren
+ if (dbImage == null) {
+ dbImage = createImage(
+ this.getSize().width,
+ this.getSize().height
+ );
+ dbGraphics = dbImage.getGraphics();
+ }
+ //Hintergrund löschen
+ dbGraphics.setColor(getBackground());
+ dbGraphics.fillRect(
+ 0,
+ 0,
+ this.getSize().width,
+ this.getSize().height
+ );
+ //Vordergrund zeichnen
+ dbGraphics.setColor(getForeground());
+ paint(dbGraphics);
+ //Offscreen anzeigen
+ g.drawImage(dbImage,0,0,this);
+ }
+
+ public void paint(Graphics g)
+ {
+ int xoffs = getInsets().left;
+ int yoffs = getInsets().top;
+ g.setColor(Color.lightGray);
+ g.fillOval(xoffs+actx,yoffs+20,100,100);
+ g.setColor(Color.red);
+ g.drawArc(xoffs+actx,yoffs+20,100,100,actarc1,10);
+ g.drawArc(xoffs+actx-1,yoffs+19,102,102,actarc1,10);
+ g.setColor(Color.blue);
+ g.drawArc(xoffs+actx,yoffs+20,100,100,360-actarc2,10);
+ g.drawArc(xoffs+actx-1,yoffs+19,102,102,360-actarc2,10);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3501.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3501.java new file mode 100644 index 0000000..55ecd38 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3501.java @@ -0,0 +1,91 @@ +/* Listing3501.java */
+
+import java.awt.event.*;
+import java.awt.*;
+import javax.swing.*;
+
+public class Listing3501
+extends JFrame
+implements ActionListener
+{
+ private static final String[] MONTHS = {
+ "Januar", "Februar", "März", "April",
+ "Mai", "Juni", "Juli", "August",
+ "September", "Oktober", "November", "Dezember"
+ };
+
+ public Listing3501()
+ {
+ super("Mein erstes Swing-Programm");
+ //Panel zur Namenseingabe hinzufügen
+ JPanel namePanel = new JPanel();
+ JLabel label = new JLabel(
+ "Name:",
+ new ImageIcon("triblue.gif"),
+ SwingConstants.LEFT
+ );
+ namePanel.add(label);
+ JTextField tf = new JTextField(30);
+ tf.setToolTipText("Geben Sie ihren Namen ein");
+ namePanel.add(tf);
+ namePanel.setBorder(BorderFactory.createEtchedBorder());
+ getContentPane().add(namePanel, BorderLayout.NORTH);
+ //Monatsliste hinzufügen
+ JList list = new JList(MONTHS);
+ list.setToolTipText("Wählen Sie ihren Geburtsmonat aus");
+ getContentPane().add(new JScrollPane(list), BorderLayout.CENTER);
+ //Panel mit den Buttons hinzufügen
+ JPanel buttonPanel = new JPanel();
+ JButton button1 = new JButton("Metal");
+ button1.addActionListener(this);
+ button1.setToolTipText("Metal-Look-and-Feel aktivieren");
+ buttonPanel.add(button1);
+ JButton button2 = new JButton("Motif");
+ button2.addActionListener(this);
+ button2.setToolTipText("Motif-Look-and-Feel aktivieren");
+ buttonPanel.add(button2);
+ JButton button3 = new JButton("Windows");
+ button3.addActionListener(this);
+ button3.setToolTipText("Windows-Look-and-Feel aktivieren");
+ buttonPanel.add(button3);
+ buttonPanel.setBorder(BorderFactory.createEtchedBorder());
+ getContentPane().add(buttonPanel, BorderLayout.SOUTH);
+ //Windows-Listener
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ try {
+ //PLAF-Klasse auswählen
+ String plaf = "unknown";
+ if (cmd.equals("Metal")) {
+ plaf = "javax.swing.plaf.metal.MetalLookAndFeel";
+ } else if (cmd.equals("Motif")) {
+ plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
+ } else if (cmd.equals("Windows")) {
+ plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
+ }
+ //LAF umschalten
+ UIManager.setLookAndFeel(plaf);
+ SwingUtilities.updateComponentTreeUI(this);
+ } catch (UnsupportedLookAndFeelException e) {
+ System.err.println(e.toString());
+ } catch (ClassNotFoundException e) {
+ System.err.println(e.toString());
+ } catch (InstantiationException e) {
+ System.err.println(e.toString());
+ } catch (IllegalAccessException e) {
+ System.err.println(e.toString());
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3501 frame = new Listing3501();
+ frame.setLocation(100, 100);
+ frame.pack();
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3601.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3601.java new file mode 100644 index 0000000..d6c0965 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3601.java @@ -0,0 +1,22 @@ +/* Listing3601.java */
+
+import javax.swing.*;
+import java.awt.event.*;
+
+public class Listing3601
+extends JFrame
+{
+ public Listing3601()
+ {
+ super("Ein einfacher JFrame");
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3601 wnd = new Listing3601();
+ wnd.setLocation(100, 100);
+ wnd.setSize(300, 200);
+ wnd.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3602.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3602.java new file mode 100644 index 0000000..dc020e2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3602.java @@ -0,0 +1,30 @@ +/* Listing3602.java */
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3602
+extends JFrame
+{
+ public Listing3602()
+ {
+ super("Ein einfacher JFrame");
+ //WindowListener hinzufügen
+ addWindowListener(new WindowClosingAdapter(true));
+ //Layout setzen und Buttons hinzufügen
+ Container contentPane = getContentPane();
+ contentPane.setLayout(new GridLayout(3, 1));
+ contentPane.add(new JButton("Button 1"));
+ contentPane.add(new JButton("Button 2"));
+ contentPane.add(new JButton("Button 3"));
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3602 wnd = new Listing3602();
+ wnd.setLocation(100, 100);
+ wnd.setSize(300, 200);
+ wnd.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3604.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3604.java new file mode 100644 index 0000000..e9c496a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3604.java @@ -0,0 +1,37 @@ +/* Listing3604.java */
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3604
+extends JFrame
+{
+ private static final String[] QUARTALE = {
+ "1. Quartal", "2. Quartal", "3. Quartal", "4. Quartal"
+ };
+
+ public Listing3604()
+ {
+ super("Test von JOptionPane");
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3604 wnd = new Listing3604();
+ wnd.setLocation(100, 100);
+ wnd.setSize(300, 200);
+ wnd.setVisible(true);
+ String ret = (String)JOptionPane.showInputDialog(
+ wnd,
+ "Wählen Sie das Quartal aus",
+ "JOptionPane.showInputDialog",
+ JOptionPane.QUESTION_MESSAGE,
+ null,
+ QUARTALE,
+ QUARTALE[2]
+ );
+ System.out.println("Ausgewählt wurde " + ret);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3607.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3607.java new file mode 100644 index 0000000..75d88e5 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3607.java @@ -0,0 +1,58 @@ +/* Listing3607.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+class DesktopFrame
+extends JFrame
+{
+ private JDesktopPane desk;
+
+ public DesktopFrame()
+ {
+ super("DesktopFrame");
+ this.desk = new JDesktopPane();
+ desk.setDesktopManager(new DefaultDesktopManager());
+ setContentPane(desk);
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void addChild(JInternalFrame child, int x, int y)
+ {
+ child.setLocation(x, y);
+ child.setSize(200, 150);
+ child.setDefaultCloseOperation(
+ JInternalFrame.DISPOSE_ON_CLOSE
+ );
+ desk.add(child);
+ child.setVisible(true);
+ }
+}
+
+class ChildFrame
+extends JInternalFrame
+{
+ public ChildFrame(String title)
+ {
+ super("Child " + title, true, true);
+ setIconifiable(true);
+ setMaximizable(true);
+ setBackground(Color.lightGray);
+ }
+}
+
+public class Listing3607
+{
+ public static void main(String[] args)
+ {
+ //Desktop erzeugen
+ DesktopFrame desktop = new DesktopFrame();
+ desktop.setLocation(100, 100);
+ desktop.setSize(400, 300);
+ desktop.setVisible(true);
+ //Zwei ChildFrames hinzufügen
+ desktop.addChild(new ChildFrame("1"), 10, 10);
+ desktop.addChild(new ChildFrame("2"), 20, 20);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3608.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3608.java new file mode 100644 index 0000000..b7939dd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3608.java @@ -0,0 +1,65 @@ +/* Listing3608.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3608
+extends JFrame
+implements ActionListener
+{
+ public Listing3608()
+ {
+ super("Swing-Menütest");
+ addWindowListener(new WindowClosingAdapter(true));
+ JMenuBar menubar = new JMenuBar();
+ menubar.add(createFileMenu());
+ setJMenuBar(menubar);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ System.out.println(event.getActionCommand());
+ }
+
+ //---Private Methoden---------------
+ private JMenu createFileMenu()
+ {
+ JMenu ret = new JMenu("Datei");
+ ret.setMnemonic('D');
+ JMenuItem mi;
+ //Öffnen
+ mi = new JMenuItem("Öffnen", 'f');
+ setCtrlAccelerator(mi, 'O');
+ mi.addActionListener(this);
+ ret.add(mi);
+ //Speichern
+ mi = new JMenuItem("Speichern", 'p');
+ setCtrlAccelerator(mi, 'S');
+ mi.addActionListener(this);
+ ret.add(mi);
+ //Separator
+ ret.addSeparator();
+ //Beenden
+ mi = new JMenuItem("Beenden", 'e');
+ mi.addActionListener(this);
+ ret.add(mi);
+ return ret;
+ }
+
+ private void setCtrlAccelerator(JMenuItem mi, char acc)
+ {
+ KeyStroke ks = KeyStroke.getKeyStroke(
+ acc, Event.CTRL_MASK
+ );
+ mi.setAccelerator(ks);
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3608 frame = new Listing3608();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3609.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3609.java new file mode 100644 index 0000000..401795c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3609.java @@ -0,0 +1,86 @@ +/* Listing3609.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3609
+extends JFrame
+{
+ public Listing3609()
+ {
+ super("Swing-Menütest II");
+ addWindowListener(new WindowClosingAdapter(true));
+ JMenuBar menubar = new JMenuBar();
+ menubar.add(createExtrasMenu());
+ setJMenuBar(menubar);
+ }
+
+ //---Private Methoden---------------
+ private JMenu createExtrasMenu()
+ {
+ JMenu ret = new JMenu("Extras");
+ ret.setMnemonic('X');
+ JMenuItem mi;
+ //Tools-Untermenü
+ ret.add(createToolsSubMenu());
+ //Separator
+ ret.addSeparator();
+ //Statuszeile und Buttonleiste
+ mi = new JCheckBoxMenuItem("Statuszeile");
+ mi.setMnemonic('z');
+ ((JCheckBoxMenuItem)mi).setState(true);
+ ret.add(mi);
+ mi = new JCheckBoxMenuItem("Buttonleiste");
+ mi.setMnemonic('B');
+ ret.add(mi);
+ //Separator
+ ret.addSeparator();
+ //Offline, Verbinden, Anmelden
+ ButtonGroup bg = new ButtonGroup();
+ mi = new JRadioButtonMenuItem("Offline", true);
+ mi.setMnemonic('O');
+ ret.add(mi);
+ bg.add(mi);
+ mi = new JRadioButtonMenuItem("Verbinden");
+ mi.setMnemonic('V');
+ ret.add(mi);
+ bg.add(mi);
+ mi = new JRadioButtonMenuItem("Anmelden");
+ mi.setMnemonic('A');
+ ret.add(mi);
+ bg.add(mi);
+ //Separator
+ ret.addSeparator();
+ //Sicherheit
+ mi = new JMenuItem(
+ "Sicherheit",
+ new ImageIcon("lock.gif")
+ );
+ mi.setMnemonic('S');
+ mi.setHorizontalTextPosition(JMenuItem.LEFT);
+ ret.add(mi);
+ return ret;
+ }
+
+ private JMenu createToolsSubMenu()
+ {
+ JMenu ret = new JMenu("Tools");
+ ret.setMnemonic('T');
+ ret.add(new JMenuItem("Rechner", 'R'));
+ ret.add(new JMenuItem("Editor", 'E'));
+ ret.add(new JMenuItem("Browser", 'B'));
+ ret.add(new JMenuItem("Zipper", 'Z'));
+ ret.add(new JMenuItem("Snapper", 'S'));
+ ret.add(new JMenuItem("Viewer", 'V'));
+ return ret;
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3609 frame = new Listing3609();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3610.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3610.java new file mode 100644 index 0000000..ec07a0f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3610.java @@ -0,0 +1,85 @@ +/* Listing3610.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.border.*;
+
+public class Listing3610
+extends JFrame
+implements MouseListener, ActionListener
+{
+ public Listing3610()
+ {
+ super("Kontextmenüs");
+ addWindowListener(new WindowClosingAdapter(true));
+ addMouseListener(this);
+ }
+
+ //MouseListener
+ public void mouseClicked(MouseEvent event)
+ {
+ checkPopupMenu(event);
+ }
+
+ public void mouseEntered(MouseEvent event)
+ {
+ }
+
+ public void mouseExited(MouseEvent event)
+ {
+ }
+
+ public void mousePressed(MouseEvent event)
+ {
+ checkPopupMenu(event);
+ }
+
+ public void mouseReleased(MouseEvent event)
+ {
+ checkPopupMenu(event);
+ }
+
+ private void checkPopupMenu(MouseEvent event)
+ {
+ if (event.isPopupTrigger()) {
+ JPopupMenu popup = new JPopupMenu();
+ //Rückgängig hinzufügen
+ JMenuItem mi = new JMenuItem("Rueckgaengig");
+ mi.addActionListener(this);
+ popup.add(mi);
+ //Separator hinzufügen
+ popup.addSeparator();
+ //Ausschneiden, Kopieren, Einfügen hinzufügen
+ mi = new JMenuItem("Ausschneiden");
+ mi.addActionListener(this);
+ popup.add(mi);
+ mi = new JMenuItem("Kopieren");
+ mi.addActionListener(this);
+ popup.add(mi);
+ mi = new JMenuItem("Einfuegen");
+ mi.addActionListener(this);
+ popup.add(mi);
+ //Menü anzeigen
+ popup.show(
+ event.getComponent(),
+ event.getX(),
+ event.getY()
+ );
+ }
+ }
+
+ //ActionListener
+ public void actionPerformed(ActionEvent event)
+ {
+ System.out.println(event.getActionCommand());
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3610 frame = new Listing3610();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3611.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3611.java new file mode 100644 index 0000000..724a07d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3611.java @@ -0,0 +1,30 @@ +/* Listing3611.java */
+
+import java.awt.*;
+import javax.swing.*;
+
+public class Listing3611
+extends JFrame
+{
+ public Listing3611()
+ {
+ super("Debug-Grafik");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ DebugGraphics.setFlashTime(100);
+ DebugGraphics.setFlashCount(3);
+ JButton button = new JButton("DEBUG-Button");
+ RepaintManager repaintManager = RepaintManager.currentManager(button);
+ repaintManager.setDoubleBufferingEnabled(false);
+ button.setDebugGraphicsOptions(DebugGraphics.FLASH_OPTION);
+ cp.add(button);
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3611 frame = new Listing3611();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3612.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3612.java new file mode 100644 index 0000000..ba756fd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3612.java @@ -0,0 +1,59 @@ +/* Listing3612.java */
+
+import java.awt.*;
+import javax.swing.*;
+
+public class Listing3612
+extends JFrame
+{
+ public Listing3612()
+ {
+ super("Transparenz");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ //SimpleGridComponent erzeugen
+ SimpleGridComponent grid = new SimpleGridComponent();
+ grid.setLayout(new FlowLayout(FlowLayout.CENTER));
+ //Transparenten Button hinzufügen
+ JButton button = new JButton("Transparent");
+ button.setOpaque(false);
+ grid.add(button);
+ //Undurchsichtigen Button hinzufügen
+ button = new JButton("Opaque");
+ grid.add(button);
+ //SimpleGridComponent hinzufügen
+ cp.add(grid, BorderLayout.CENTER);
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ String plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
+ UIManager.setLookAndFeel(plaf);
+ Listing3612 frame = new Listing3612();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 100);
+ frame.setVisible(true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+}
+
+class SimpleGridComponent
+extends JComponent
+{
+ protected void paintComponent(Graphics g)
+ {
+ int width = getSize().width;
+ int height = getSize().height;
+ g.setColor(Color.gray);
+ for (int i = 0; i < width; i += 10) {
+ g.drawLine(i, 0, i, height);
+ }
+ for (int i = 0; i < height; i += 10) {
+ g.drawLine(0, i, width, i);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3613.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3613.java new file mode 100644 index 0000000..23a7384 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3613.java @@ -0,0 +1,71 @@ +/* Listing3613.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.border.*;
+
+public class Listing3613
+extends JFrame
+implements ActionListener
+{
+ public Listing3613()
+ {
+ super("Invalidierung");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ ((JComponent)cp).setBorder(new EmptyBorder(5, 5, 5, 5));
+ cp.setLayout(new FlowLayout());
+ //Textfelder erzeugen
+ JTextField tf1 = new JTextField("Zeile1", 20);
+ JTextField tf2 = new JTextField("Zeile2", 20);
+ JTextField tf3 = new JTextField("Zeile3", 20);
+ //STRG+UMSCHALT+F6 auf Frame registrieren
+ ((JComponent)cp).registerKeyboardAction(
+ this,
+ "dialog",
+ ctrlShift(KeyEvent.VK_F6),
+ JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
+ );
+ //STRG+UMSCHALT+F7 auf tf1 registrieren
+ tf1.registerKeyboardAction(
+ this,
+ "tf1",
+ ctrlShift(KeyEvent.VK_F7),
+ JComponent.WHEN_IN_FOCUSED_WINDOW
+ );
+ //STRG+UMSCHALT+F8 auf tf2 registrieren
+ tf2.registerKeyboardAction(
+ this,
+ "tf2",
+ ctrlShift(KeyEvent.VK_F8),
+ JComponent.WHEN_FOCUSED
+ );
+ //Textfelder hinzufügen
+ cp.add(tf1);
+ cp.add(tf2);
+ cp.add(tf3);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ System.out.println(cmd);
+ }
+
+ private KeyStroke ctrlShift(int vkey)
+ {
+ return KeyStroke.getKeyStroke(
+ vkey,
+ Event.SHIFT_MASK + Event.CTRL_MASK
+ );
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3613 frame = new Listing3613();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3701.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3701.java new file mode 100644 index 0000000..58c57d9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3701.java @@ -0,0 +1,51 @@ +/* Listing3701.java */
+
+import java.awt.*;
+import javax.swing.*;
+
+public class Listing3701
+extends JFrame
+{
+ public Listing3701()
+ {
+ super("JLabel");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ cp.setLayout(new GridLayout(5, 1));
+ JLabel label;
+ //Standardlabel
+ label = new JLabel("Standard-Label");
+ cp.add(label);
+ //Label mit Icon
+ label = new JLabel(
+ "Label mit Icon",
+ new ImageIcon("lock.gif"),
+ JLabel.CENTER
+ );
+ cp.add(label);
+ //Nur-Icon
+ label = new JLabel(new ImageIcon("lock.gif"));
+ cp.add(label);
+ //Icon auf der rechten Seite
+ label = new JLabel(
+ "Label mit Icon rechts",
+ new ImageIcon("lock.gif"),
+ JLabel.CENTER
+ );
+ label.setHorizontalTextPosition(JLabel.LEFT);
+ cp.add(label);
+ //Label rechts unten
+ label = new JLabel("Label rechts unten");
+ label.setHorizontalAlignment(JLabel.RIGHT);
+ label.setVerticalAlignment(JLabel.BOTTOM);
+ cp.add(label);
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3701 frame = new Listing3701();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java new file mode 100644 index 0000000..22dc3c6 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java @@ -0,0 +1,57 @@ +/* Listing3702.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.event.*;
+
+public class Listing3702
+extends JFrame
+implements ActionListener, CaretListener
+{
+ public Listing3702()
+ {
+ super("JTextField");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ cp.setLayout(new FlowLayout());
+ JTextField tf;
+ //Linksbündiges Textfeld mit "Hello, world"
+ tf = new JTextField("Hello, world");
+ cp.add(tf);
+ //Leeres Textfeld mit 20 Spalten
+ tf = new JTextField(20);
+ cp.add(tf);
+ //Textfeld mit "Hello, world" und 20 Spalten
+ tf = new JTextField("Hello, world", 20);
+ tf.addActionListener(this);
+ tf.addCaretListener(this);
+ cp.add(tf);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ JTextField tf = (JTextField)event.getSource();
+ System.out.println("---ActionEvent---");
+ System.out.println(tf.getText());
+ System.out.println(tf.getSelectedText());
+ System.out.println(tf.getSelectionStart());
+ System.out.println(tf.getSelectionEnd());
+ System.out.println(tf.getCaretPosition());
+ }
+
+ public void caretUpdate(CaretEvent event)
+ {
+ System.out.println("---CaretEvent---");
+ System.out.println(event.getDot());
+ System.out.println(event.getMark());
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3702 frame = new Listing3702();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 150);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3703.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3703.java new file mode 100644 index 0000000..f9c616c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3703.java @@ -0,0 +1,28 @@ +/* Listing3703.java */
+
+import java.awt.*;
+import javax.swing.*;
+
+public class Listing3703
+extends JFrame
+{
+ public Listing3703()
+ {
+ super("JTextArea");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ JTextArea ta = new JTextArea("Hello, world", 20, 30);
+ ta.setTabSize(4);
+ ta.setLineWrap(true);
+ ta.setWrapStyleWord(true);
+ cp.add(new JScrollPane(ta));
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3703 frame = new Listing3703();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3704.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3704.java new file mode 100644 index 0000000..97c44b1 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3704.java @@ -0,0 +1,43 @@ +/* Listing3704.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.event.*;
+
+public class Listing3704
+extends JFrame
+{
+ private static final String[] WDAYS = {
+ "Montag", "Dienstag", "Mittwoch", "Donnerstag",
+ "Freitag", "Samstag", "Sonntag"
+ };
+
+ public Listing3704()
+ {
+ super("JSpinner");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ cp.setLayout(new FlowLayout());
+ //Default-Spinner für Ganzzahlen
+ JSpinner spinner = new JSpinner();
+ cp.add(spinner);
+ //Spinner für einige Vielfache von 7
+ spinner = new JSpinner(new SpinnerNumberModel(91, 49, 126, 7));
+ cp.add(spinner);
+ //Spinner für Datum/Uhrzeit
+ spinner = new JSpinner(new SpinnerDateModel());
+ cp.add(spinner);
+ //Spinner für Wochentage
+ spinner = new JSpinner(new SpinnerListModel(WDAYS));
+ cp.add(spinner);
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3704 frame = new Listing3704();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 150);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3707.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3707.java new file mode 100644 index 0000000..4ce3668 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3707.java @@ -0,0 +1,47 @@ +/* Listing3707.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3707
+extends JFrame
+implements ActionListener
+{
+ public Listing3707()
+ {
+ super("JButton");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ cp.setLayout(new FlowLayout());
+ JPanel panel = new JPanel();
+ //OK-Button
+ JButton okButton = new DefaultButton("OK", getRootPane());
+ okButton.addActionListener(this);
+ panel.add(okButton);
+ //Abbrechen-Button
+ JButton cancelButton = new CancelButton("Abbrechen");
+ cancelButton.addActionListener(this);
+ panel.add(cancelButton);
+ //Hilfe-Button
+ JButton helpButton = new JButton("Hilfe");
+ helpButton.setMnemonic('H');
+ helpButton.addActionListener(this);
+ panel.add(helpButton);
+ //Panel hinzufügen
+ cp.add(panel);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ System.out.println(event.getActionCommand());
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3707 frame = new Listing3707();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 100);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3708.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3708.java new file mode 100644 index 0000000..3151b3d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3708.java @@ -0,0 +1,44 @@ +/* Listing3708.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.event.*;
+
+public class Listing3708
+extends JFrame
+implements ItemListener
+{
+ public Listing3708()
+ {
+ super("JCheckBox");
+ addWindowListener(new WindowClosingAdapter(true));
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(3, 1));
+ for (int i = 1; i <= 3; ++i) {
+ JCheckBox cb = new JCheckBox("Checkbox" + i, i == 2);
+ cb.addItemListener(this);
+ panel.add(cb);
+ }
+ getContentPane().add(panel, BorderLayout.CENTER);
+ }
+
+ public void itemStateChanged(ItemEvent e)
+ {
+ JCheckBox cb = (JCheckBox)e.getSource();
+ int change = e.getStateChange();
+ if (change == ItemEvent.SELECTED) {
+ System.out.println(cb.getText() + ": SELECTED");
+ } else if (change == ItemEvent.DESELECTED) {
+ System.out.println(cb.getText() + ": DESELECTED");
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3708 frame = new Listing3708();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 100);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3709.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3709.java new file mode 100644 index 0000000..76f17f4 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3709.java @@ -0,0 +1,52 @@ +/* Listing3709.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3709
+extends JFrame
+implements ActionListener
+{
+ private ButtonGroup group = new ButtonGroup();
+
+ public Listing3709()
+ {
+ super("JRadioButton");
+ addWindowListener(new WindowClosingAdapter(true));
+ //RadioButton-Panel
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(3, 1));
+ for (int i = 1; i <= 3; ++i) {
+ JRadioButton rb = new JRadioButton("RadioButton" + i, i == 2);
+ rb.setActionCommand(rb.getText());
+ panel.add(rb);
+ group.add(rb);
+ }
+ getContentPane().add(panel, BorderLayout.CENTER);
+ //Selektion-Button
+ JButton button = new JButton("Selektion");
+ button.addActionListener(this);
+ getContentPane().add(button, BorderLayout.SOUTH);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("Selektion")) {
+ ButtonModel selected = group.getSelection();
+ System.out.print("Selektiert: ");
+ if (selected != null) {
+ System.out.println(selected.getActionCommand());
+ }
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3709 frame = new Listing3709();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 120);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3710.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3710.java new file mode 100644 index 0000000..b271396 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3710.java @@ -0,0 +1,58 @@ +/* Listing3710.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3710
+extends JFrame
+implements ActionListener
+{
+ static final String[] DATA = {
+ "Hund", "Katze", "Meerschweinchen", "Tiger", "Maus",
+ "Fisch", "Leopard", "Schimpanse", "Kuh", "Pferd",
+ "Reh", "Huhn", "Marder", "Adler", "Nilpferd"
+ };
+
+ private JList list;
+
+ public Listing3710()
+ {
+ super("JList");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ //Liste
+ list = new JList(DATA);
+ list.setSelectionMode(
+ ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
+ );
+ list.setSelectedIndex(2);
+ cp.add(new JScrollPane(list), BorderLayout.CENTER);
+ //Ausgabe-Button
+ JButton button = new JButton("Ausgabe");
+ button.addActionListener(this);
+ cp.add(button, BorderLayout.SOUTH);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("Ausgabe")) {
+ System.out.println("---");
+ ListModel lm = list.getModel();
+ int[] sel = list.getSelectedIndices();
+ for (int i = 0; i < sel.length; ++i) {
+ String value = (String)lm.getElementAt(sel[i]);
+ System.out.println(" " + value);
+ }
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3710 frame = new Listing3710();
+ frame.setLocation(100, 100);
+ frame.setSize(200, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3711.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3711.java new file mode 100644 index 0000000..4ce818a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3711.java @@ -0,0 +1,37 @@ +/* Listing3711.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3711
+extends JFrame
+{
+ private static final String[] COLORS = {
+ "rot", "grün", "blau", "gelb"
+ };
+
+ public Listing3711()
+ {
+ super("JComboBox");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ for (int i = 1; i <= 2; ++i) {
+ JPanel panel = new JPanel();
+ panel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 2));
+ panel.add(new JLabel("Farbe " + i + ":"));
+ JComboBox combo = new JComboBox(COLORS);
+ combo.setEditable(i == 1);
+ panel.add(combo);
+ cp.add(panel, i == 1 ? BorderLayout.NORTH : BorderLayout.CENTER);
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3711 frame = new Listing3711();
+ frame.setLocation(100, 100);
+ frame.setSize(200, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3712.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3712.java new file mode 100644 index 0000000..5b9dd29 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3712.java @@ -0,0 +1,57 @@ +/* Listing3712.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3712
+extends JFrame
+implements AdjustmentListener
+{
+ private JPanel coloredPanel;
+ private JScrollBar sbEast;
+ private JScrollBar sbSouth;
+ private int blue = 0;
+ private int red = 0;
+
+ public Listing3712()
+ {
+ super("JScrollBar");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ //Vertikaler Schieberegler
+ sbEast = new JScrollBar(JScrollBar.VERTICAL, 0, 10, 0, 255);
+ sbEast.addAdjustmentListener(this);
+ cp.add(sbEast, BorderLayout.EAST);
+ //Horizontaler Schieberegler
+ sbSouth = new JScrollBar(JScrollBar.HORIZONTAL, 0, 10, 0, 255);
+ sbSouth.addAdjustmentListener(this);
+ cp.add(sbSouth, BorderLayout.SOUTH);
+ //Farbiges Panel
+ coloredPanel = new JPanel();
+ coloredPanel.setBackground(new Color(red, 0, blue));
+ cp.add(coloredPanel, BorderLayout.CENTER);
+ }
+
+ public void adjustmentValueChanged(AdjustmentEvent event)
+ {
+ JScrollBar sb = (JScrollBar)event.getSource();
+ if (sb == sbEast) {
+ blue = event.getValue();
+ } else {
+ red = event.getValue();
+ }
+ coloredPanel.setBackground(new Color(red, 0, blue));
+ if (!sb.getValueIsAdjusting()) {
+ System.out.println("(" + red + ",0," + blue + ")");
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3712 frame = new Listing3712();
+ frame.setLocation(100, 100);
+ frame.setSize(200, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java new file mode 100644 index 0000000..193f244 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java @@ -0,0 +1,68 @@ +/* Listing3713.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.border.*;
+import javax.swing.event.*;
+
+public class Listing3713
+extends JFrame
+implements ChangeListener
+{
+ private JPanel coloredPanel;
+ private JSlider slEast;
+ private JSlider slSouth;
+ private int blue = 0;
+ private int red = 0;
+
+ public Listing3713()
+ {
+ super("JSlider");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ //Vertikaler Schieberegler
+ slEast = new JSlider(JSlider.VERTICAL, 0, 255, 0);
+ slEast.setMajorTickSpacing(50);
+ slEast.setMinorTickSpacing(10);
+ slEast.setPaintTicks(true);
+ slEast.setPaintLabels(true);
+ slEast.addChangeListener(this);
+ cp.add(slEast, BorderLayout.EAST);
+ //Horizontaler Schieberegler
+ slSouth = new JSlider(JSlider.HORIZONTAL, 0, 255, 0);
+ slSouth.setMajorTickSpacing(100);
+ slSouth.setMinorTickSpacing(25);
+ slSouth.setPaintTicks(true);
+ slSouth.setPaintLabels(true);
+ slSouth.setSnapToTicks(true);
+ slSouth.addChangeListener(this);
+ cp.add(slSouth, BorderLayout.SOUTH);
+ //Farbiges Panel
+ coloredPanel = new JPanel();
+ coloredPanel.setBackground(new Color(red, 0, blue));
+ cp.add(coloredPanel, BorderLayout.CENTER);
+ }
+
+ public void stateChanged(ChangeEvent event)
+ {
+ JSlider sl = (JSlider)event.getSource();
+ if (sl == slEast) {
+ blue = sl.getValue();
+ } else {
+ red = sl.getValue();
+ }
+ coloredPanel.setBackground(new Color(red, 0, blue));
+ if (!sl.getValueIsAdjusting()) {
+ System.out.println("(" + red + ",0," + blue + ")");
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3713 frame = new Listing3713();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 250);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3714.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3714.java new file mode 100644 index 0000000..4b9e8e3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3714.java @@ -0,0 +1,42 @@ +/* Listing3714.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3714
+extends JFrame
+implements ActionListener
+{
+ private JProgressBar pb;
+ private int value = 0;
+
+ public Listing3714()
+ {
+ super("JProgressBar");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ //Fortschrittsanzeige
+ pb = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100);
+ pb.setStringPainted(true);
+ cp.add(pb, BorderLayout.NORTH);
+ //Weiter-Button
+ JButton button = new JButton("Weiter");
+ button.addActionListener(this);
+ cp.add(button, BorderLayout.SOUTH);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ value = (value >= 100 ? 0 : value + 5);
+ pb.setValue(value);
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3714 frame = new Listing3714();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 150);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3801.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3801.java new file mode 100644 index 0000000..8a78326 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3801.java @@ -0,0 +1,73 @@ +/* Listing3801.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3801
+extends JFrame
+{
+ public Listing3801()
+ {
+ super("JScrollPane");
+ addWindowListener(new WindowClosingAdapter(true));
+ //Dialogpanel erzeugen
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(10, 10));
+ for (int i = 1; i <= 100; ++i) {
+ panel.add(new JCheckBox("Frage " + i));
+ }
+ //JScrollPane erzeugen
+ JScrollPane scroll = new JScrollPane(panel);
+ scroll.setCorner(
+ JScrollPane.UPPER_RIGHT_CORNER,
+ new JLabel("1", JLabel.CENTER)
+ );
+ scroll.setCorner(
+ JScrollPane.LOWER_RIGHT_CORNER,
+ new JLabel("2", JLabel.CENTER)
+ );
+ scroll.setColumnHeaderView(new ColumnHeader(panel, 10));
+ //JScrollPane zur ContentPane hinzufügen
+ getContentPane().add(scroll, BorderLayout.CENTER);
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3801 frame = new Listing3801();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 150);
+ frame.setVisible(true);
+ }
+}
+
+class ColumnHeader
+extends JComponent
+{
+ JComponent component;
+ int columns;
+
+ public ColumnHeader(JComponent component, int columns)
+ {
+ this.component = component;
+ this.columns = columns;
+ }
+
+ public void paintComponent(Graphics g)
+ {
+ int width = component.getSize().width;
+ int height = getSize().height;
+ int colwid = width / columns;
+ for (int i = 0; i < columns; ++i) {
+ g.setColor(i % 2 == 0 ? Color.yellow : Color.gray);
+ g.fillRect(i * colwid, 0, colwid, height);
+ }
+ g.setColor(Color.black);
+ g.drawLine(0, height - 1, width, height - 1);
+ }
+
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(component.getSize().width, 20);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3802.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3802.java new file mode 100644 index 0000000..03e2935 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3802.java @@ -0,0 +1,57 @@ +/* Listing3802.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3802
+extends JFrame
+{
+ public Listing3802()
+ {
+ super("JSplitPane");
+ addWindowListener(new WindowClosingAdapter(true));
+ //Linkes Element erzeugen
+ GridComponent grid1 = new GridComponent();
+ grid1.setMinimumSize(new Dimension(50, 100));
+ grid1.setPreferredSize(new Dimension(180, 100));
+ //Rechtes Element erzeugen
+ GridComponent grid2 = new GridComponent();
+ grid2.setMinimumSize(new Dimension(100, 100));
+ grid2.setPreferredSize(new Dimension(80, 100));
+ //JSplitPane erzeugen
+ JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
+ sp.setLeftComponent(grid1);
+ sp.setRightComponent(grid2);
+ sp.setOneTouchExpandable(true);
+ sp.setContinuousLayout(true);
+ getContentPane().add(sp, BorderLayout.CENTER);
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3802 frame = new Listing3802();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 200);
+ frame.setVisible(true);
+ }
+}
+
+class GridComponent
+extends JComponent
+{
+ public void paintComponent(Graphics g)
+ {
+ g.setColor(Color.gray);
+ int width = getSize().width;
+ int height = getSize().height;
+ for (int i = 0; i < 10; ++i) {
+ g.drawLine(i * width / 10, 0, i * width / 10, height);
+ }
+ for (int i = 0; i < 10; ++i) {
+ g.drawLine(0, i * height / 10, width, i * height / 10);
+ }
+ g.setColor(Color.black);
+ g.drawString("" + width, 5, 15);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3803.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3803.java new file mode 100644 index 0000000..ff162c4 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3803.java @@ -0,0 +1,47 @@ +/* Listing3803.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3803
+extends JFrame
+{
+ JTabbedPane tp;
+
+ public Listing3803()
+ {
+ super("JTabbedPane");
+ addWindowListener(new WindowClosingAdapter(true));
+ tp = new JTabbedPane();
+ for (int i = 0; i < 5; ++i) {
+ JPanel panel = new JPanel();
+ panel.add(new JLabel("Karte " + i));
+ JButton next = new JButton("Weiter");
+ next.addActionListener(new NextTabActionListener());
+ panel.add(next);
+ tp.addTab("Tab" + i, panel);
+ }
+ getContentPane().add(tp, BorderLayout.CENTER);
+ }
+
+ class NextTabActionListener
+ implements ActionListener
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ int tab = tp.getSelectedIndex();
+ tab = (tab >= tp.getTabCount() - 1 ? 0 : tab + 1);
+ tp.setSelectedIndex(tab);
+ ((JPanel)tp.getSelectedComponent()).requestDefaultFocus();
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3803 frame = new Listing3803();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3804.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3804.java new file mode 100644 index 0000000..7bd1f0a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3804.java @@ -0,0 +1,28 @@ +/* Listing3804.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3804
+extends JFrame
+implements TableData
+{
+ public Listing3804()
+ {
+ super("JTable 1");
+ addWindowListener(new WindowClosingAdapter(true));
+ JTable table = new JTable(DATA, COLHEADS);
+ Container cp = getContentPane();
+ cp.add(new JLabel("Alte c\'t-Ausgaben:"), BorderLayout.NORTH);
+ cp.add(new JScrollPane(table), BorderLayout.CENTER);
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3804 frame = new Listing3804();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3807.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3807.java new file mode 100644 index 0000000..78ee67e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3807.java @@ -0,0 +1,42 @@ +/* Listing3807.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3807
+extends JFrame
+implements ActionListener
+{
+ JTable table;
+ SparseTableModel tableModel;
+
+ public Listing3807()
+ {
+ super("JTable 2");
+ addWindowListener(new WindowClosingAdapter(true));
+ tableModel = new SparseTableModel(1000);
+ table = new JTable(tableModel, null);
+ table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
+ table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
+ table.setCellSelectionEnabled(true);
+ Container cp = getContentPane();
+ cp.add(new JScrollPane(table), BorderLayout.CENTER);
+ JButton button = new JButton("Drucken");
+ button.addActionListener(this);
+ cp.add(button, BorderLayout.SOUTH);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ tableModel.printData();
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3807 frame = new Listing3807();
+ frame.setLocation(100, 100);
+ frame.setSize(320, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3808.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3808.java new file mode 100644 index 0000000..373c35f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3808.java @@ -0,0 +1,51 @@ +/* Listing3808.java */
+
+import java.awt.*;
+import javax.swing.*;
+import javax.swing.table.*;
+
+public class Listing3808
+extends JFrame
+implements TableData
+{
+ public Listing3808()
+ {
+ super("JTable 3");
+ addWindowListener(new WindowClosingAdapter(true));
+ //Spaltenmodell erzeugen
+ DefaultTableColumnModel cm = new DefaultTableColumnModel();
+ for (int i = 0; i < COLHEADS.length; ++i) {
+ TableColumn col = new TableColumn(i, i == 2 ? 150 : 60);
+ col.setHeaderValue(COLHEADS[i]);
+ cm.addColumn(col);
+ }
+ //Tabellenmodell erzeugen
+ TableModel tm = new AbstractTableModel() {
+ public int getRowCount()
+ {
+ return DATA.length;
+ }
+ public int getColumnCount()
+ {
+ return DATA[0].length;
+ }
+ public Object getValueAt(int row, int column)
+ {
+ return DATA[row][column];
+ }
+ };
+ //Tabelle erzeugen und ContentPane füllen
+ JTable table = new JTable(tm, cm);
+ Container cp = getContentPane();
+ cp.add(new JLabel("Alte c\'t-Ausgaben:"), BorderLayout.NORTH);
+ cp.add(new JScrollPane(table), BorderLayout.CENTER);
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3808 frame = new Listing3808();
+ frame.setLocation(100, 100);
+ frame.setSize(350, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3810.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3810.java new file mode 100644 index 0000000..3555f12 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3810.java @@ -0,0 +1,31 @@ +/* Listing3810.java */
+
+import java.awt.*;
+import javax.swing.*;
+
+public class Listing3810
+extends JFrame
+implements TableData
+{
+ public Listing3810()
+ {
+ super("JTable 4");
+ addWindowListener(new WindowClosingAdapter(true));
+ JTable table = new JTable(DATA, COLHEADS);
+ table.setDefaultRenderer(
+ Object.class,
+ new ColoredTableCellRenderer()
+ );
+ Container cp = getContentPane();
+ cp.add(new JLabel("Alte c\'t-Ausgaben:"), BorderLayout.NORTH);
+ cp.add(new JScrollPane(table), BorderLayout.CENTER);
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3810 frame = new Listing3810();
+ frame.setLocation(100, 100);
+ frame.setSize(350, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3811.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3811.java new file mode 100644 index 0000000..1448c9d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3811.java @@ -0,0 +1,42 @@ +/* Listing3811.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.tree.*;
+
+public class Listing3811
+extends JFrame
+{
+ public Listing3811()
+ {
+ super("JTree 1");
+ addWindowListener(new WindowClosingAdapter(true));
+ //Einfaches TreeModel bauen
+ DefaultMutableTreeNode root, child, subchild;
+ root = new DefaultMutableTreeNode("Root");
+ for (int i = 1; i <= 5; ++i) {
+ String name = "Child-" + i;
+ child = new DefaultMutableTreeNode(name);
+ root.add(child);
+ for (int j = 1; j <= 3; ++j) {
+ subchild = new DefaultMutableTreeNode(name + "-" + j);
+ child.add(subchild);
+ }
+ }
+ //JTree erzeugen
+ JTree tree = new JTree(root);
+ tree.setRootVisible(true);
+ //JTree einfügen
+ Container cp = getContentPane();
+ cp.add(new JScrollPane(tree), BorderLayout.CENTER);
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3811 frame = new Listing3811();
+ frame.setLocation(100, 100);
+ frame.setSize(250, 200);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3812.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3812.java new file mode 100644 index 0000000..69aff2c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3812.java @@ -0,0 +1,64 @@ +/* Listing3812.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.tree.*;
+
+public class Listing3812
+extends JFrame
+{
+ public Listing3812()
+ {
+ super("JTree 2");
+ addWindowListener(new WindowClosingAdapter(true));
+ //Einfaches TreeModel bauen
+ DefaultMutableTreeNode root, child, subchild;
+ root = new DefaultMutableTreeNode("Root");
+ for (int i = 1; i <= 5; ++i) {
+ String name = "Child-" + i;
+ child = new DefaultMutableTreeNode(name);
+ root.add(child);
+ for (int j = 1; j <= 3; ++j) {
+ subchild = new DefaultMutableTreeNode(name + "-" + j);
+ child.add(subchild);
+ }
+ }
+ //JTree erzeugen und Einfachselektion aktivieren
+ JTree tree = new JTree(root);
+ TreeSelectionModel tsm = new DefaultTreeSelectionModel();
+ tsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+ tree.setSelectionModel(tsm);
+ tree.setRootVisible(true);
+ //JTree einfügen
+ Container cp = getContentPane();
+ cp.add(new JScrollPane(tree), BorderLayout.CENTER);
+ //TreeSelectionListener hinzufügen
+ tree.addTreeSelectionListener(
+ new TreeSelectionListener()
+ {
+ public void valueChanged(TreeSelectionEvent event)
+ {
+ TreePath tp = event.getNewLeadSelectionPath();
+ if (tp != null) {
+ System.out.println(" Selektiert: " + tp.toString());
+ } else {
+ System.out.println(" Kein Element selektiert");
+ }
+ }
+ }
+ );
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ Listing3812 frame = new Listing3812();
+ frame.setLocation(100, 100);
+ frame.setSize(250, 200);
+ frame.setVisible(true);
+ } catch (Exception e) {
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3813.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3813.java new file mode 100644 index 0000000..94958e9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3813.java @@ -0,0 +1,83 @@ +/* Listing3813.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.tree.*;
+
+public class Listing3813
+extends JFrame
+implements ActionListener
+{
+ protected DefaultMutableTreeNode root;
+ protected DefaultTreeModel treeModel;
+ protected JTree tree;
+
+ public Listing3813()
+ {
+ super("JTree 3");
+ addWindowListener(new WindowClosingAdapter(true));
+ //JTree erzeugen und Einfachselektion aktivieren
+ root = new DefaultMutableTreeNode("Root");
+ treeModel = new DefaultTreeModel(root);
+ tree = new JTree(treeModel);
+ TreeSelectionModel tsm = new DefaultTreeSelectionModel();
+ tsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+ tree.setSelectionModel(tsm);
+ tree.setRootVisible(true);
+ //JTree einfügen
+ Container cp = getContentPane();
+ cp.add(new JScrollPane(tree), BorderLayout.CENTER);
+ //ButtonPanel
+ JPanel panel = new JPanel(new FlowLayout());
+ String[] buttons = new String[]{"AddChild", "Delete", "Change"};
+ for (int i = 0; i < buttons.length; ++i) {
+ JButton button = new JButton(buttons[i]);
+ button.addActionListener(this);
+ panel.add(button);
+ }
+ cp.add(panel, BorderLayout.SOUTH);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ TreePath tp = tree.getLeadSelectionPath();
+ if (tp != null) {
+ DefaultMutableTreeNode node;
+ node = (DefaultMutableTreeNode)tp.getLastPathComponent();
+ if (cmd.equals("AddChild")) {
+ DefaultMutableTreeNode child;
+ child = new DefaultMutableTreeNode("child");
+ treeModel.insertNodeInto(child, node, node.getChildCount());
+ TreeNode[] path = treeModel.getPathToRoot(node);
+ tree.expandPath(new TreePath(path));
+ } else if (cmd.equals("Delete")) {
+ if (node != root) {
+ TreeNode parent = node.getParent();
+ TreeNode[] path = treeModel.getPathToRoot(parent);
+ treeModel.removeNodeFromParent(node);
+ tree.setSelectionPath(new TreePath(path));
+ }
+ } else if (cmd.equals("Change")) {
+ String name = node.toString();
+ node.setUserObject(name + "C");
+ treeModel.nodeChanged(node);
+ }
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ String plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
+ UIManager.setLookAndFeel(plaf);
+ Listing3813 frame = new Listing3813();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 300);
+ frame.setVisible(true);
+ } catch (Exception e) {
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3901.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3901.java new file mode 100644 index 0000000..d10553b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3901.java @@ -0,0 +1,14 @@ +/* Listing3901.java */
+
+import java.awt.*;
+import java.applet.*;
+
+public class Listing3901
+extends Applet
+{
+ public void paint(Graphics g)
+ {
+ showStatus("Hello, world");
+ g.drawString("Hello, world",10,50);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4102.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4102.java new file mode 100644 index 0000000..798e5ec --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4102.java @@ -0,0 +1,20 @@ +/* Listing4102.java */
+
+import java.io.*;
+import java.util.*;
+
+public class Listing4102
+{
+ public static void main(String[] args)
+ {
+ try {
+ FileOutputStream fs = new FileOutputStream("test1.ser");
+ ObjectOutputStream os = new ObjectOutputStream(fs);
+ Time time = new Time(10,20);
+ os.writeObject(time);
+ os.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4103.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4103.java new file mode 100644 index 0000000..51eda64 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4103.java @@ -0,0 +1,22 @@ +/* Listing4103.java */
+
+import java.io.*;
+import java.util.*;
+
+public class Listing4103
+{
+ public static void main(String[] args)
+ {
+ try {
+ FileOutputStream fs = new FileOutputStream("test2.ser");
+ ObjectOutputStream os = new ObjectOutputStream(fs);
+ os.writeInt(123);
+ os.writeObject("Hallo");
+ os.writeObject(new Time(10, 30));
+ os.writeObject(new Time(11, 25));
+ os.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4104.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4104.java new file mode 100644 index 0000000..da24a45 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4104.java @@ -0,0 +1,22 @@ +/* Listing4104.java */
+
+import java.io.*;
+import java.util.*;
+
+public class Listing4104
+{
+ public static void main(String[] args)
+ {
+ try {
+ FileInputStream fs = new FileInputStream("test1.ser");
+ ObjectInputStream is = new ObjectInputStream(fs);
+ Time time = (Time)is.readObject();
+ System.out.println(time.toString());
+ is.close();
+ } catch (ClassNotFoundException e) {
+ System.err.println(e.toString());
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4105.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4105.java new file mode 100644 index 0000000..bf3ade7 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4105.java @@ -0,0 +1,26 @@ +/* Listing4105.java */
+
+import java.io.*;
+import java.util.*;
+
+public class Listing4105
+{
+ public static void main(String[] args)
+ {
+ try {
+ FileInputStream fs = new FileInputStream("test2.ser");
+ ObjectInputStream is = new ObjectInputStream(fs);
+ System.out.println("" + is.readInt());
+ System.out.println((String)is.readObject());
+ Time time = (Time)is.readObject();
+ System.out.println(time.toString());
+ time = (Time)is.readObject();
+ System.out.println(time.toString());
+ is.close();
+ } catch (ClassNotFoundException e) {
+ System.err.println(e.toString());
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4108.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4108.java new file mode 100644 index 0000000..e9b06e3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4108.java @@ -0,0 +1,68 @@ +/* Listing4108.java */
+
+import java.io.*;
+import java.util.*;
+
+public class Listing4108
+{
+ public static void main(String[] args)
+ {
+ //Erzeugen der Familie
+ Person opa = new Person("Eugen");
+ Person oma = new Person("Therese");
+ Person vater = new Person("Barny");
+ Person mutter = new Person("Wilma");
+ Person kind1 = new Person("Fritzchen");
+ Person kind2 = new Person("Kalli");
+ vater.father = opa;
+ vater.mother = oma;
+ kind1.father = kind2.father = vater;
+ kind1.mother = kind2.mother = mutter;
+
+ //Serialisieren der Familie
+ try {
+ FileOutputStream fs = new FileOutputStream("test3.ser");
+ ObjectOutputStream os = new ObjectOutputStream(fs);
+ os.writeObject(kind1);
+ os.writeObject(kind2);
+ os.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+
+ //Rekonstruieren der Familie
+ kind1 = kind2 = null;
+ try {
+ FileInputStream fs = new FileInputStream("test3.ser");
+ ObjectInputStream is = new ObjectInputStream(fs);
+ kind1 = (Person)is.readObject();
+ kind2 = (Person)is.readObject();
+ //Überprüfen der Objekte
+ System.out.println(kind1.name);
+ System.out.println(kind2.name);
+ System.out.println(kind1.father.name);
+ System.out.println(kind1.mother.name);
+ System.out.println(kind2.father.name);
+ System.out.println(kind2.mother.name);
+ System.out.println(kind1.father.father.name);
+ System.out.println(kind1.father.mother.name);
+ //Name des Vaters ändern
+ kind1.father.name = "Fred";
+ //Erneutes Überprüfen der Objekte
+ System.out.println("---");
+ System.out.println(kind1.name);
+ System.out.println(kind2.name);
+ System.out.println(kind1.father.name);
+ System.out.println(kind1.mother.name);
+ System.out.println(kind2.father.name);
+ System.out.println(kind2.mother.name);
+ System.out.println(kind1.father.father.name);
+ System.out.println(kind1.father.mother.name);
+ is.close();
+ } catch (ClassNotFoundException e) {
+ System.err.println(e.toString());
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4110.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4110.java new file mode 100644 index 0000000..5c48011 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4110.java @@ -0,0 +1,52 @@ +/* Listing4110.java */
+
+import java.io.*;
+import java.util.*;
+
+public class Listing4110
+{
+ public static void main(String[] args)
+ {
+ //Erzeugen und Speichern des Objektspeichers
+ TrivialObjectStore tos = new TrivialObjectStore("shop");
+ tos.putObject("name", "Tami-Shop Norderelbe");
+ tos.putObject("besitzer", "Meier, Fridolin");
+ Vector products = new Vector(10);
+ products.addElement("Dinky Dino");
+ products.addElement("96er Classic");
+ products.addElement("Black Frog");
+ products.addElement("SmartGotchi");
+ products.addElement("Pretty Dolly");
+ tos.putObject("produkte", products);
+ try {
+ tos.save();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+
+ //Einlesen des Objektspeichers
+ TrivialObjectStore tos2 = new TrivialObjectStore("shop");
+ try {
+ tos2.load();
+ Enumeration names = tos2.getAllNames();
+ while (names.hasMoreElements()) {
+ String name = (String)names.nextElement();
+ Object obj = tos2.getObject(name);
+ System.out.print(name + ": ");
+ System.out.println(obj.getClass().toString());
+ if (obj instanceof Collection) {
+ Iterator it = ((Collection)obj).iterator();
+ while (it.hasNext()) {
+ System.out.println(" " + it.next().toString());
+ }
+ } else {
+ System.out.println(" " + obj.toString());
+ }
+ }
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ } catch (ClassNotFoundException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4111.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4111.java new file mode 100644 index 0000000..c847a7f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4111.java @@ -0,0 +1,93 @@ +/* Listing4111.java */
+
+import java.io.*;
+import java.util.*;
+
+public class Listing4111
+{
+ public static Object seriaClone(Object o)
+ throws IOException, ClassNotFoundException
+ {
+ //Serialisieren des Objekts
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ObjectOutputStream os = new ObjectOutputStream(out);
+ os.writeObject(o);
+ os.flush();
+ //Deserialisieren des Objekts
+ ByteArrayInputStream in = new ByteArrayInputStream(
+ out.toByteArray()
+ );
+ ObjectInputStream is = new ObjectInputStream(in);
+ Object ret = is.readObject();
+ is.close();
+ os.close();
+ return ret;
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ //Erzeugen des Buchobjekts
+ Book book = new Book();
+ book.author = "Peitgen, Heinz-Otto";
+ String[] s = {"Jürgens, Hartmut", "Saupe, Dietmar"};
+ book.coAuthors = s;
+ book.title = "Bausteine des Chaos";
+ book.publisher = "rororo science";
+ book.pubyear = 1998;
+ book.pages = 514;
+ book.isbn = "3-499-60250-4";
+ book.reflist = new Vector();
+ book.reflist.addElement("The World of MC Escher");
+ book.reflist.addElement(
+ "Die fraktale Geometrie der Natur"
+ );
+ book.reflist.addElement("Gödel, Escher, Bach");
+ System.out.println(book.toString());
+ //Erzeugen und Verändern der Kopie
+ Book copy = (Book)seriaClone(book);
+ copy.title += " - Fraktale";
+ copy.reflist.addElement("Fractal Creations");
+ //Ausgeben von Original und Kopie
+ System.out.print(book.toString());
+ System.out.println("---");
+ System.out.print(copy.toString());
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ } catch (ClassNotFoundException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
+
+class Book
+implements Serializable
+{
+ public String author;
+ public String[] coAuthors;
+ public String title;
+ public String publisher;
+ public int pubyear;
+ public int pages;
+ public String isbn;
+ public Vector reflist;
+
+ public String toString()
+ {
+ String NL = System.getProperty("line.separator");
+ StringBuffer ret = new StringBuffer(200);
+ ret.append(author + NL);
+ for (int i = 0; i < coAuthors.length; ++i) {
+ ret.append(coAuthors[i] + NL);
+ }
+ ret.append("\"" + title + "\"" + NL);
+ ret.append(publisher + " " + pubyear + NL);
+ ret.append(pages + " pages" + NL);
+ ret.append(isbn + NL);
+ Enumeration e = reflist.elements();
+ while (e.hasMoreElements()) {
+ ret.append(" " + (String)e.nextElement() + NL);
+ }
+ return ret.toString();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4301.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4301.java new file mode 100644 index 0000000..562bd1c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4301.java @@ -0,0 +1,75 @@ +/* Listing4301.java */
+
+import java.io.*;
+
+interface HelloMeth
+{
+ public void hello();
+}
+
+class CA
+implements HelloMeth
+{
+ public void hello()
+ {
+ System.out.println("hello CA");
+ }
+}
+
+class CB
+implements HelloMeth
+{
+ public void hello()
+ {
+ System.out.println("hello CB");
+ }
+}
+
+class CC
+{
+ public void hello()
+ {
+ System.out.println("hello CC");
+ }
+}
+
+class CD
+{
+ public void hallo()
+ {
+ System.out.println("hallo CD");
+ }
+}
+
+public class Listing4301
+{
+ public static void main(String[] args)
+ {
+ String buf = "";
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(
+ new DataInputStream(System.in)));
+ while (true) {
+ try {
+ System.out.print("Klassenname oder ende eingeben: ");
+ buf = in.readLine();
+ if (buf.equals("ende")) {
+ break;
+ }
+ Class c = Class.forName(buf);
+ Object o = c.newInstance();
+ ((HelloMeth)o).hello();
+ } catch (IOException e) {
+ System.out.println(e.toString());
+ } catch (ClassNotFoundException e) {
+ System.out.println("Klasse nicht gefunden");
+ } catch (ClassCastException e) {
+ System.out.println(e.toString());
+ } catch (InstantiationException e) {
+ System.out.println(e.toString());
+ } catch (IllegalAccessException e) {
+ System.out.println(e.toString());
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4306.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4306.java new file mode 100644 index 0000000..d4c6740 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4306.java @@ -0,0 +1,56 @@ +/* Listing4306.java */
+
+import java.lang.reflect.*;
+
+public class Listing4306
+{
+ public static void main(String[] args)
+ {
+ Class clazz = TestConstructors.class;
+ //Formale Parameter definieren
+ Class[] formparas = new Class[2];
+ formparas[0] = String.class;
+ formparas[1] = String.class;
+ try {
+ Constructor cons = clazz.getConstructor(formparas);
+ //Aktuelle Argumente definieren
+ Object[] actargs = new Object[] {"eins", "zwei"};
+ Object obj = cons.newInstance(actargs);
+ ((TestConstructors)obj).print();
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
+
+class TestConstructors
+{
+ private String arg1;
+ private String arg2;
+
+ public TestConstructors()
+ {
+ arg1 = "leer";
+ arg2 = "leer";
+ }
+
+ public TestConstructors(String arg1)
+ {
+ this();
+ this.arg1 = arg1;
+ }
+
+ public TestConstructors(String arg1, String arg2)
+ {
+ this();
+ this.arg1 = arg1;
+ this.arg2 = arg2;
+ }
+
+ public void print()
+ {
+ System.out.println("arg1 = " + arg1);
+ System.out.println("arg2 = " + arg2);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4308.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4308.java new file mode 100644 index 0000000..a17a26a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4308.java @@ -0,0 +1,38 @@ +/* Listing4308.java */
+
+import java.lang.reflect.*;
+
+public class Listing4308
+{
+ public static void createArray1()
+ {
+ //Erzeugt ein eindimensionales int-Array
+ Object ar = Array.newInstance(Integer.TYPE, 3);
+ int[] iar = (int[])ar;
+ for (int i = 0; i < iar.length; ++i) {
+ iar[i] = i;
+ System.out.println(iar[i]);
+ };
+ }
+
+ public static void createArray2()
+ {
+ //Erzeugt ein zweidimensionales String-Array
+ Object ar = Array.newInstance(String.class, new int[]{7, 4});
+ String[][] sar = (String[][])ar;
+ for (int i = 0; i < sar.length; ++i) {
+ for (int j = 0; j < sar[i].length; ++j) {
+ sar[i][j] = "(" + i + "," + j + ")";
+ System.out.print(sar[i][j] + " ");
+ }
+ System.out.println();
+ };
+ }
+
+ public static void main(String[] args)
+ {
+ createArray1();
+ System.out.println("--");
+ createArray2();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4309.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4309.java new file mode 100644 index 0000000..00ffc6f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4309.java @@ -0,0 +1,38 @@ +/* Listing4309.java */
+
+import java.lang.reflect.*;
+
+public class Listing4309
+{
+ public static void createArray1()
+ {
+ //Erzeugt ein eindimensionales int-Array
+ Object ar = Array.newInstance(Integer.TYPE, 3);
+ for (int i = 0; i < Array.getLength(ar); ++i) {
+ Array.set(ar, i, new Integer(i));
+ System.out.println(Array.getInt(ar, i));
+ };
+ }
+
+ public static void createArray2()
+ {
+ //Erzeugt ein zweidimensionales String-Array
+ Object ar = Array.newInstance(String.class, new int[]{7, 4});
+ for (int i = 0; i < Array.getLength(ar); ++i) {
+ Object subArray = Array.get(ar, i);
+ for (int j = 0; j < Array.getLength(subArray); ++j) {
+ String value = "(" + i + "," + j + ")";
+ Array.set(subArray, j, value);
+ System.out.print(Array.get(subArray, j) + " ");
+ }
+ System.out.println();
+ };
+ }
+
+ public static void main(String[] args)
+ {
+ createArray1();
+ System.out.println("--");
+ createArray2();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4404.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4404.java new file mode 100644 index 0000000..287d8fd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4404.java @@ -0,0 +1,37 @@ +/* Listing4404.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing4404
+extends Frame
+{
+ public Listing4404()
+ {
+ super("Bean einbinden");
+ setLayout(new FlowLayout());
+ setBackground(Color.lightGray);
+ LightBulb bulb1 = new LightBulb();
+ bulb1.setLightOn(false);
+ add(bulb1);
+ LightBulb bulb2 = new LightBulb();
+ bulb2.setLightOn(true);
+ add(bulb2);
+ addWindowListener(
+ new WindowAdapter() {
+ public void windowClosing(WindowEvent event)
+ {
+ System.exit(0);
+ }
+ }
+ );
+ }
+
+ public static void main(String[] args)
+ {
+ Listing4404 frm = new Listing4404();
+ frm.setLocation(100, 100);
+ frm.pack();
+ frm.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4405.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4405.java new file mode 100644 index 0000000..fb2ea79 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4405.java @@ -0,0 +1,48 @@ +/* Listing4405.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+
+public class Listing4405
+extends Frame
+{
+ public Listing4405()
+ {
+ super("LighBulbTest");
+ setLayout(new FlowLayout());
+ setBackground(Color.gray);
+ addWindowListener(
+ new WindowAdapter() {
+ public void windowClosing(WindowEvent event)
+ {
+ System.exit(0);
+ }
+ }
+ );
+ loadLightBulb();
+ }
+
+ private void loadLightBulb()
+ {
+ try {
+ ObjectInputStream is = new ObjectInputStream(
+ new FileInputStream("lb1.ser"));
+ LightBulb bulb = (LightBulb)is.readObject();
+ is.close();
+ add(bulb);
+ } catch (ClassNotFoundException e) {
+ System.err.println(e.toString());
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing4405 frm = new Listing4405();
+ frm.setLocation(100, 100);
+ frm.pack();
+ frm.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4408.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4408.java new file mode 100644 index 0000000..a2e689a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4408.java @@ -0,0 +1,53 @@ +/* Listing4408.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+
+public class Listing4408
+extends Frame
+{
+ public Listing4408()
+ {
+ //Initialisierung
+ super("BeanPropertiesTest");
+ setLayout(new FlowLayout());
+ setBackground(Color.lightGray);
+ addWindowListener(
+ new WindowAdapter() {
+ public void windowClosing(WindowEvent event)
+ {
+ System.exit(0);
+ }
+ }
+ );
+ //Dialogelemente hinzufügen
+ LightedPushButton button1 = new LightedPushButton();
+ VetoSwitch veto1 = new VetoSwitch();
+ final LightBulb bulb1 = new LightBulb();
+ add(button1);
+ add(veto1);
+ add(bulb1);
+ button1.addPropertyChangeListener(
+ new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ if (e.getPropertyName().equals("lighton")) {
+ Boolean on = (Boolean)e.getNewValue();
+ bulb1.setLightOn(on.booleanValue());
+ }
+ }
+ }
+ );
+ button1.addVetoableChangeListener(veto1);
+ }
+
+ //---main-------------------------------------------------
+ public static void main(String[] args)
+ {
+ Listing4408 frm = new Listing4408();
+ frm.setLocation(100, 100);
+ frm.pack();
+ frm.setVisible(true);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4504.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4504.java new file mode 100644 index 0000000..76798b7 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4504.java @@ -0,0 +1,28 @@ +/* Listing4504.java */
+
+import javax.persistence.*;
+
+public class Listing4504
+{
+ public static void main(String[] args)
+ {
+ //Erzeugen einer EntityManagerFactory mit Hilfe des symbolischen
+ //Namens aus dem Persistenz Descriptor (persistence.xml)
+ EntityManagerFactory emf =
+ Persistence.createEntityManagerFactory("persistenceExample");
+
+ //Erzeugen eines EntityManagers für den Zugriff auf
+ //die Datenbank
+ EntityManager manager = emf.createEntityManager();
+
+ //An dieser Stelle können Sie mit Hilfe des EntityManagers auf
+ //die Datenbank zugreifen
+
+ //Freigabe der Ressourcen des EntityManagers
+ manager.close();
+
+ //Schließen der EntityManagerFactory und Freigeben der
+ //belegten Ressourcen
+ emf.close();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4505.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4505.java new file mode 100644 index 0000000..528e33b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4505.java @@ -0,0 +1,35 @@ +/* Listing4505.java */
+
+import javax.persistence.*;
+
+public class Listing4505
+{
+ public static void main(String[] args)
+ {
+ //Erzeugen einer EntityManagerFactory mit Hilfe des symbolischen
+ //Namens aus dem Persistenz Descriptor (persistence.xml)
+ EntityManagerFactory emf =
+ Persistence.createEntityManagerFactory("persistenceExample");
+
+ //Erzeugen eines EntityManagers für den Zugriff auf
+ //die Datenbank
+ EntityManager manager = emf.createEntityManager();
+
+ //Beginn einer neuen Transanktion
+ EntityTransaction tx = manager.getTransaction();
+ tx.begin();
+
+ //An dieser Stelle können Sie mit Hilfe des EntityManagers auf
+ //die Datenbank zugreifen
+
+ //Abschluss der Transaktion mit einem Commit
+ tx.commit();
+
+ //Freigabe der Ressourcen des EntityManagers
+ manager.close();
+
+ //Schließen der EntityManagerFactory und Freigeben der
+ //belegten Ressourcen
+ emf.close();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4506.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4506.java new file mode 100644 index 0000000..bca40a4 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4506.java @@ -0,0 +1,40 @@ +/* Listing4506.java */
+
+import javax.persistence.*;
+
+public class Listing4506
+{
+ public static void main(String[] args)
+ {
+ //Erzeugen einer EntityManagerFactory mit Hilfe des symbolischen
+ //Namens aus dem Persistenz Descriptor (persistence.xml)
+ EntityManagerFactory emf =
+ Persistence.createEntityManagerFactory("persistenceExample");
+
+ //Erzeugen eines EntityManagers für den Zugriff auf
+ //die Datenbank
+ EntityManager manager = emf.createEntityManager();
+
+ //Beginn einer neuen Transanktion
+ EntityTransaction tx = manager.getTransaction();
+ tx.begin();
+
+ //Erzeugen eines neuen JavaObjektes
+ Directory dir = new Directory();
+ dir.setDid(0);
+ dir.setDname("temp");
+
+ //Speichern des JavaObjektes mit Hilfe des EntityManagers
+ manager.persist(dir);
+
+ //Abschluss der Transaktion mit einem Commit
+ tx.commit();
+
+ //Freigabe der Ressourcen des EntityManagers
+ manager.close();
+
+ //Schließen der EntityManagerFactory und Freigeben der
+ //belegten Ressourcen
+ emf.close();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4507.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4507.java new file mode 100644 index 0000000..f5d150a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4507.java @@ -0,0 +1,31 @@ +/* Listing4507.java */
+
+import javax.persistence.*;
+
+public class Listing4507
+{
+ public static void main(String[] args)
+ {
+ //Erzeugen einer EntityManagerFactory mit Hilfe des symbolischen
+ //Namens aus dem Persistenz Descriptor (persistence.xml)
+ EntityManagerFactory emf =
+ Persistence.createEntityManagerFactory("persistenceExample");
+
+ //Erzeugen eines EntityManagers für den Zugriff auf
+ //die Datenbank
+ EntityManager manager = emf.createEntityManager();
+
+ //Laden des Directory-Objektes mit der Id=0
+ Directory dir = manager.find(Directory.class, 0);
+
+ //Ausgabe des gefundenen Objektes
+ System.out.println(dir);
+
+ //Freigabe der Ressourcen des EntityManagers
+ manager.close();
+
+ //Schließen der EntityManagerFactory und Freigeben der
+ //belegten Ressourcen
+ emf.close();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4508.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4508.java new file mode 100644 index 0000000..dcee3c0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4508.java @@ -0,0 +1,40 @@ +/* Listing4508.java */
+
+import javax.persistence.*;
+
+public class Listing4508
+{
+ public static void main(String[] args)
+ {
+ //Erzeugen einer EntityManagerFactory mit Hilfe des symbolischen
+ //Namens aus dem Persistenz Descriptor (persistence.xml)
+ EntityManagerFactory emf =
+ Persistence.createEntityManagerFactory("persistenceExample");
+
+ //Erzeugen eines EntityManagers für den Zugriff auf
+ //die Datenbank
+ EntityManager manager = emf.createEntityManager();
+
+ //Beginn einer neuen Transanktion
+ EntityTransaction tx = manager.getTransaction();
+ tx.begin();
+
+ //Laden des Directory-Objektes mit der Id=0
+ Directory dir = manager.find(Directory.class, 0);
+
+ if(dir != null) {
+ //Löschen des Datensatzes aus der Datenbank
+ manager.remove(dir);
+ }
+
+ //Abschluss der Transaktion mit einem Commit
+ tx.commit();
+
+ //Freigabe der Ressourcen des EntityManagers
+ manager.close();
+
+ //Schließen der EntityManagerFactory und Freigeben der
+ //belegten Ressourcen
+ emf.close();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4601.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4601.java new file mode 100644 index 0000000..a812132 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4601.java @@ -0,0 +1,23 @@ +/* Listing4601.java */
+
+import java.net.*;
+
+public class Listing4601
+{
+ public static void main(String[] args)
+ {
+ if (args.length != 1) {
+ System.err.println("Usage: java Listing4601 <host>");
+ System.exit(1);
+ }
+ try {
+ //Get requested address
+ InetAddress addr = InetAddress.getByName(args[0]);
+ System.out.println(addr.getHostName());
+ System.out.println(addr.getHostAddress());
+ } catch (UnknownHostException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4602.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4602.java new file mode 100644 index 0000000..5b4ecf9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4602.java @@ -0,0 +1,29 @@ +/* Listing4602.java */
+
+import java.net.*;
+import java.io.*;
+
+public class Listing4602
+{
+ public static void main(String[] args)
+ {
+ if (args.length != 1) {
+ System.err.println("Usage: java Listing4602 <host>");
+ System.exit(1);
+ }
+ try {
+ Socket sock = new Socket(args[0], 13);
+ InputStream in = sock.getInputStream();
+ int len;
+ byte[] b = new byte[100];
+ while ((len = in.read(b)) != -1) {
+ System.out.write(b, 0, len);
+ }
+ in.close();
+ sock.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4604.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4604.java new file mode 100644 index 0000000..82b272d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4604.java @@ -0,0 +1,38 @@ +/* Listing4604.java */
+
+import java.net.*;
+import java.io.*;
+
+public class Listing4604
+{
+ public static void main(String[] args)
+ {
+ if (args.length != 2) {
+ System.err.println(
+ "Usage: java Listing4604 <host> <file>"
+ );
+ System.exit(1);
+ }
+ try {
+ Socket sock = new Socket(args[0], 80);
+ OutputStream out = sock.getOutputStream();
+ InputStream in = sock.getInputStream();
+ //GET-Kommando senden
+ String s = "GET " + args[1] + " HTTP/1.0" + "\r\n\r\n";
+ out.write(s.getBytes());
+ //Ausgabe lesen und anzeigen
+ int len;
+ byte[] b = new byte[100];
+ while ((len = in.read(b)) != -1) {
+ System.out.write(b, 0, len);
+ }
+ //Programm beenden
+ in.close();
+ out.close();
+ sock.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4801.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4801.java new file mode 100644 index 0000000..37e5781 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4801.java @@ -0,0 +1,14 @@ +/* Listing4801.java */
+
+public class Listing4801
+{
+ public static void main(String[] args)
+ {
+ int key = Integer.parseInt(args[0]);
+ String msg = args[1];
+ for (int i = 0; i < msg.length(); ++i) {
+ int c = (msg.charAt(i) - 'A' + key) % 26 + 'A';
+ System.out.print((char)c);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4802.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4802.java new file mode 100644 index 0000000..8a83a04 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4802.java @@ -0,0 +1,13 @@ +/* Listing4802.java */
+
+public class Listing4802
+{
+ public static void main(String[] args)
+ {
+ int key = Integer.parseInt(args[0]);
+ String msg = args[1];
+ for (int i = 0; i < msg.length(); ++i) {
+ System.out.print((char)(msg.charAt(i) ^ key));
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4803.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4803.java new file mode 100644 index 0000000..dcc1e99 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4803.java @@ -0,0 +1,49 @@ +/* Listing4803.java */
+
+import java.io.*;
+import java.security.*;
+
+public class Listing4803
+{
+ /**
+ * Konvertiert ein Byte in einen Hex-String.
+ */
+ public static String toHexString(byte b)
+ {
+ int value = (b & 0x7F) + (b < 0 ? 128 : 0);
+ String ret = (value < 16 ? "0" : "");
+ ret += Integer.toHexString(value).toUpperCase();
+ return ret;
+ }
+
+ public static void main(String[] args)
+ {
+ if (args.length < 2) {
+ System.out.println(
+ "Usage: java Listing4803 md-algorithm filename"
+ );
+ System.exit(0);
+ }
+ try {
+ //MessageDigest erstellen
+ MessageDigest md = MessageDigest.getInstance(args[0]);
+ FileInputStream in = new FileInputStream(args[1]);
+ int len;
+ byte[] data = new byte[1024];
+ while ((len = in.read(data)) > 0) {
+ //MessageDigest updaten
+ md.update(data, 0, len);
+ }
+ in.close();
+ //MessageDigest berechnen und ausgeben
+ byte[] result = md.digest();
+ for (int i = 0; i < result.length; ++i) {
+ System.out.print(toHexString(result[i]) + " ");
+ }
+ System.out.println();
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4804.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4804.java new file mode 100644 index 0000000..ede4464 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4804.java @@ -0,0 +1,40 @@ +/* Listing4804.java */
+
+import java.security.*;
+
+public class Listing4804
+{
+ /**
+ * Konvertiert ein Byte in einen Hex-String.
+ */
+ public static String toHexString(byte b)
+ {
+ int value = (b & 0x7F) + (b < 0 ? 128 : 0);
+ String ret = (value < 16 ? "0" : "");
+ ret += Integer.toHexString(value).toUpperCase();
+ return ret;
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ //Zufallszahlengenerator erstellen
+ SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
+ byte[] data = new byte[8];
+ //Startwert initialisieren
+ rand.setSeed(0x123456789ABCDEF0L);
+ for (int i = 0; i < 10; ++i) {
+ //Zufallszahlen berechnen
+ rand.nextBytes(data);
+ //Ausgeben
+ for (int j = 0; j < 8; ++j) {
+ System.out.print(toHexString(data[j]) + " ");
+ }
+ System.out.println();
+ }
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4901.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4901.java new file mode 100644 index 0000000..59c0cdd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4901.java @@ -0,0 +1,80 @@ +/* Listing4901.java */
+
+import java.io.*;
+import javax.sound.sampled.*;
+
+public class Listing4901
+{
+ private static void playSampleFile(String name, float pan, float gain)
+ throws Exception
+ {
+ //AudioInputStream öffnen
+ AudioInputStream ais = AudioSystem.getAudioInputStream(
+ new File(name)
+ );
+ AudioFormat format = ais.getFormat();
+ //ALAW/ULAW samples in PCM konvertieren
+ if ((format.getEncoding() == AudioFormat.Encoding.ULAW) ||
+ (format.getEncoding() == AudioFormat.Encoding.ALAW))
+ {
+ AudioFormat tmp = new AudioFormat(
+ AudioFormat.Encoding.PCM_SIGNED,
+ format.getSampleRate(),
+ format.getSampleSizeInBits() * 2,
+ format.getChannels(),
+ format.getFrameSize() * 2,
+ format.getFrameRate(),
+ true
+ );
+ ais = AudioSystem.getAudioInputStream(tmp, ais);
+ format = tmp;
+ }
+ //Clip erzeugen und öffnen
+ DataLine.Info info = new DataLine.Info(
+ Clip.class,
+ format,
+ ((int) ais.getFrameLength() * format.getFrameSize())
+ );
+ Clip clip = (Clip)AudioSystem.getLine(info);
+ clip.open(ais);
+ //PAN einstellen
+ FloatControl panControl = (FloatControl)clip.getControl(
+ FloatControl.Type.PAN
+ );
+ panControl.setValue(pan);
+ //MASTER_GAIN einstellen
+ FloatControl gainControl = (FloatControl)clip.getControl(
+ FloatControl.Type.MASTER_GAIN
+ );
+ gainControl.setValue(gain);
+ //Clip abspielen
+ clip.start();
+ while (true) {
+ try {
+ Thread.sleep(100);
+ } catch (Exception e) {
+ //nothing
+ }
+ if (!clip.isRunning()) {
+ break;
+ }
+ }
+ clip.stop();
+ clip.close();
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ playSampleFile(
+ args[0],
+ Float.parseFloat(args[1]),
+ Float.parseFloat(args[2])
+ );
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ System.exit(0);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4902.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4902.java new file mode 100644 index 0000000..c028c8b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4902.java @@ -0,0 +1,62 @@ +/* Listing4902.java */
+
+import javax.sound.midi.*;
+
+public class Listing4902
+{
+ private static void playAlleMeineEntchen()
+ throws Exception
+ {
+ //Partitur {{Tonhoehe, DauerInViertelNoten, AnzahlWdh},...}
+ final int DATA[][] = {
+ {60, 1, 1}, //C
+ {62, 1, 1}, //D
+ {64, 1, 1}, //E
+ {65, 1, 1}, //F
+ {67, 2, 2}, //G,G
+ {69, 1, 4}, //A,A,A,A
+ {67, 4, 1}, //G
+ {69, 1, 4}, //A,A,A,A
+ {67, 4, 1}, //G
+ {65, 1, 4}, //F,F,F,F
+ {64, 2, 2}, //E,E
+ {62, 1, 4}, //D,D,D,D
+ {60, 4, 1} //C
+ };
+ //Synthesizer öffnen und Receiver holen
+ Synthesizer synth = MidiSystem.getSynthesizer();
+ synth.open();
+ Receiver rcvr = synth.getReceiver();
+ //Melodie spielen
+ ShortMessage msg = new ShortMessage();
+ for (int i = 0; i < DATA.length; ++i) {
+ for (int j = 0; j < DATA[i][2]; ++j) { //Anzahl Wdh. je Note
+ //Note an
+ msg.setMessage(ShortMessage.NOTE_ON, 0, DATA[i][0], 64);
+ rcvr.send(msg, -1);
+ //Pause
+ try {
+ Thread.sleep(DATA[i][1] * 400);
+ } catch (Exception e) {
+ //nothing
+ }
+ //Note aus
+ msg.setMessage(ShortMessage.NOTE_OFF, 0, DATA[i][0], 0);
+ rcvr.send(msg, -1);
+ }
+ }
+ //Synthesizer schließen
+ synth.close();
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ playAlleMeineEntchen();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ System.exit(0);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4903.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4903.java new file mode 100644 index 0000000..598a654 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4903.java @@ -0,0 +1,89 @@ +/* Listing4903.java */
+
+import javax.sound.midi.*;
+
+public class Listing4903
+{
+ private static void playAlleMeineEntchen()
+ throws Exception
+ {
+ //Partitur {{Tonhoehe, DauerInViertelNoten, AnzahlWdh},...}
+ final int DATA[][] = {
+ {60, 1, 1}, //C
+ {62, 1, 1}, //D
+ {64, 1, 1}, //E
+ {65, 1, 1}, //F
+ {67, 2, 2}, //G,G
+ {69, 1, 4}, //A,A,A,A
+ {67, 4, 1}, //G
+ {69, 1, 4}, //A,A,A,A
+ {67, 4, 1}, //G
+ {65, 1, 4}, //F,F,F,F
+ {64, 2, 2}, //E,E
+ {62, 1, 4}, //D,D,D,D
+ {60, 4, 1} //C
+ };
+ //Sequence bauen
+ final int PPQS = 16;
+ final int STAKKATO = 4;
+ Sequence seq = new Sequence(Sequence.PPQ, PPQS);
+ Track track = seq.createTrack();
+ long currentTick = 0;
+ ShortMessage msg;
+ //Kanal 0 auf "EnsembleStrings" umschalten
+ msg = new ShortMessage();
+ msg.setMessage(ShortMessage.PROGRAM_CHANGE, 0, 48, 0);
+ track.add(new MidiEvent(msg, currentTick));
+ //Partiturdaten hinzufügen
+ for (int i = 0; i < DATA.length; ++i) {
+ for (int j = 0; j < DATA[i][2]; ++j) { //Anzahl Wdh. je Note
+ msg = new ShortMessage();
+ msg.setMessage(ShortMessage.NOTE_ON, 0, DATA[i][0], 64);
+ track.add(new MidiEvent(msg, currentTick));
+ currentTick += PPQS * DATA[i][1] - STAKKATO;
+ msg = new ShortMessage();
+ msg.setMessage(ShortMessage.NOTE_OFF, 0, DATA[i][0], 0);
+ track.add(new MidiEvent(msg, currentTick));
+ currentTick += STAKKATO;
+ }
+ }
+ //Sequencer und Synthesizer initialisieren
+ Sequencer sequencer = MidiSystem.getSequencer();
+ Transmitter trans = sequencer.getTransmitter();
+ Synthesizer synth = MidiSystem.getSynthesizer();
+ Receiver rcvr = synth.getReceiver();
+ //Beide öffnen und verbinden
+ sequencer.open();
+ synth.open();
+ trans.setReceiver(rcvr);
+ //Sequence abspielen
+ sequencer.setSequence(seq);
+ sequencer.setTempoInBPM(145);
+ sequencer.start();
+ while (true) {
+ try {
+ Thread.sleep(100);
+ } catch (Exception e) {
+ //nothing
+ }
+ if (!sequencer.isRunning()) {
+ break;
+ }
+ }
+ //Sequencer anhalten und Geräte schließen
+ sequencer.stop();
+ sequencer.close();
+ synth.close();
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ playAlleMeineEntchen();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ System.exit(0);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4904.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4904.java new file mode 100644 index 0000000..7aff2cd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4904.java @@ -0,0 +1,51 @@ +/* Listing4904.java */
+
+import java.io.*;
+import javax.sound.midi.*;
+
+public class Listing4904
+{
+ private static void playMidiFile(String name)
+ throws Exception
+ {
+ //Sequencer und Synthesizer initialisieren
+ Sequencer sequencer = MidiSystem.getSequencer();
+ Transmitter trans = sequencer.getTransmitter();
+ Synthesizer synth = MidiSystem.getSynthesizer();
+ Receiver rcvr = synth.getReceiver();
+ //Beide öffnen und verbinden
+ sequencer.open();
+ synth.open();
+ trans.setReceiver(rcvr);
+ //Sequence lesen und abspielen
+ Sequence seq = MidiSystem.getSequence(new File(name));
+ sequencer.setSequence(seq);
+ sequencer.setTempoInBPM(145);
+ sequencer.start();
+ while (true) {
+ try {
+ Thread.sleep(100);
+ } catch (Exception e) {
+ //nothing
+ }
+ if (!sequencer.isRunning()) {
+ break;
+ }
+ }
+ //Sequencer anhalten und Geräte schließen
+ sequencer.stop();
+ sequencer.close();
+ synth.close();
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ playMidiFile(args[0]);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ System.exit(0);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/MainMenu2.inc b/Master/Reference Architectures and Patterns/hjp5/examples/MainMenu2.inc new file mode 100644 index 0000000..308c959 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/MainMenu2.inc @@ -0,0 +1,55 @@ +/* MainMenu2.inc */
+
+class MainMenu2
+extends MenuBar
+{
+ public MainMenu2()
+ {
+ Menu m;
+ MenuItem mi;
+ MenuShortcut ms;
+
+ //Datei
+ m = new Menu("Datei");
+
+ ms = new MenuShortcut(KeyEvent.VK_N);
+ mi = new MenuItem("Neu",ms);
+ mi.setActionCommand("Neu");
+ m.add(mi);
+
+ ms = new MenuShortcut(KeyEvent.VK_L);
+ mi = new MenuItem("Laden",ms);
+ mi.setActionCommand("Laden");
+ m.add(mi);
+
+ ms = new MenuShortcut(KeyEvent.VK_S);
+ mi = new MenuItem("Speichern",ms);
+ mi.setActionCommand("Speichern");
+ m.add(mi);
+
+ ms = new MenuShortcut(KeyEvent.VK_E);
+ mi = new MenuItem("Beenden",ms);
+ mi.setActionCommand("Beenden");
+ m.add(mi);
+ add(m);
+
+ //Bearbeiten
+ m = new Menu("Bearbeiten");
+
+ ms = new MenuShortcut(KeyEvent.VK_X);
+ mi = new MenuItem("Ausschneiden",ms);
+ mi.setActionCommand("Ausschneiden");
+ m.add(mi);
+
+ ms = new MenuShortcut(KeyEvent.VK_C);
+ mi = new MenuItem("Kopieren",ms);
+ mi.setActionCommand("Kopieren");
+ m.add(mi);
+
+ ms = new MenuShortcut(KeyEvent.VK_V);
+ mi = new MenuItem("Einfügen",ms);
+ mi.setActionCommand("Einfügen");
+ m.add(mi);
+ add(m);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/MainMenu3.inc b/Master/Reference Architectures and Patterns/hjp5/examples/MainMenu3.inc new file mode 100644 index 0000000..8024c32 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/MainMenu3.inc @@ -0,0 +1,64 @@ +/* MainMenu3.inc */
+
+class MainMenu3
+extends MenuBar
+{
+ private MenuItem miRueck;
+ private CheckboxMenuItem miFarbe;
+
+ public MainMenu3()
+ {
+ Menu m;
+
+ //Datei
+ m = new Menu("Datei");
+ m.add(new MenuItem("Neu"));
+ m.add(new MenuItem("Laden"));
+ m.add(new MenuItem("Speichern"));
+ m.addSeparator();
+ m.add(new MenuItem("Beenden"));
+ add(m);
+ //Bearbeiten
+ m = new Menu("Bearbeiten");
+ m.add((miRueck = new MenuItem("Rueckgaengig")));
+ m.addSeparator();
+ m.add(new MenuItem("Ausschneiden"));
+ m.add(new MenuItem("Kopieren"));
+ m.add(new MenuItem("Einfuegen"));
+ m.add(new MenuItem("Loeschen"));
+ add(m);
+ //Optionen
+ m = new Menu("Optionen");
+ m.add(new MenuItem("Einstellungen"));
+
+ //Untermenü Schriftart
+ Menu m1 = new Menu("Schriftart");
+ m1.add(new MenuItem("Arial"));
+ m1.add(new MenuItem("TimesRoman"));
+ m1.add(new MenuItem("Courier"));
+ m1.add(new MenuItem("System"));
+ m.add(m1);
+ //Ende Untermenü Schriftart
+
+ m.add((miFarbe = new CheckboxMenuItem("Farbe")));
+ add(m);
+ //Rueckgaengig deaktivieren
+ enableRueckgaengig(false);
+ //Farbe anschalten
+ setFarbe(true);
+ }
+
+ public void enableRueckgaengig(boolean ena)
+ {
+ if (ena) {
+ miRueck.setEnabled(true);
+ } else {
+ miRueck.setEnabled(false);
+ }
+ }
+
+ public void setFarbe(boolean on)
+ {
+ miFarbe.setState(on);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/MiniListe.java b/Master/Reference Architectures and Patterns/hjp5/examples/MiniListe.java new file mode 100644 index 0000000..d3d884a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/MiniListe.java @@ -0,0 +1,112 @@ +import java.util.*;
+
+/**
+ * Die folgende Klasse realisiert eine einfache Liste mit einer
+ * festen Größe. Die Liste kann typisiert werden, so dass
+ * Zugriffs- und Hinzufügemethoden typsicher werden. Darüber
+ * hinaus implementiert sie das Interface Iterable und stellt
+ * einen typsicheren Iterator zur Verfügung, um die Verwendung
+ * in J2SE-5.0-foreach-Schleifen zu ermöglichen.
+ */
+public class MiniListe<E>
+implements Iterable<E>
+{
+ private Object[] data;
+ private int size;
+
+ /**
+ * Erzeugt eine leere Liste, die maximal maxSize Elemente
+ * aufnehmen kann.
+ */
+ public MiniListe(int maxSize)
+ {
+ this.data = new Object[maxSize];
+ this.size = 0;
+ }
+
+ /**
+ * Fügt ein Element zur Liste hinzu. Falls diese schon
+ * voll ist, wird eine Exception ausgelöst.
+ */
+ public void addElement(E element)
+ {
+ if (size >= data.length) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ data[size++] = element;
+ }
+
+ /**
+ * Liefert die Anzahl der Elemente in der Liste.
+ */
+ public int size()
+ {
+ return size;
+ }
+
+ /**
+ * Liefert das Element an Position pos. Falls kein solches
+ * Element vorhanden ist, wird eine Exception ausgelöst.
+ */
+ public E elementAt(int pos)
+ {
+ if (pos >= size) {
+ throw new NoSuchElementException();
+ }
+ return (E)data[pos];
+ }
+
+ /**
+ * Liefert einen Iterator zum Durchlaufen der Elemente.
+ */
+ public Iterator<E> iterator()
+ {
+ return new Iterator<E>()
+ {
+ int pos = 0;
+
+ public boolean hasNext()
+ {
+ return pos < size;
+ }
+ public E next()
+ {
+ if (pos >= size) {
+ throw new NoSuchElementException();
+ }
+ return (E)data[pos++];
+ }
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ //------------------------------------------
+ public static void main(String[] args)
+ {
+ //Untypisierte Verwendung
+ MiniListe l1 = new MiniListe(10);
+ l1.addElement(3.14);
+ l1.addElement("world");
+ for (Object o : l1) {
+ System.out.println(o);
+ }
+ //Ganzzahlige Typisierung
+ System.out.println("---");
+ MiniListe<Integer> l2 = new MiniListe<Integer>(5);
+ l2.addElement(3);
+ l2.addElement(1);
+ l2.addElement(4);
+ for (Integer i : l2) {
+ System.out.println(i + 1000);
+ }
+ //Verwendung read-only
+ System.out.println("---");
+ MiniListe<? extends Number> l3 = l2;
+ for (Number i : l3) {
+ System.out.println(i.intValue() + 1000);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource.java b/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource.java new file mode 100644 index 0000000..d7ad43f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource.java @@ -0,0 +1,11 @@ +/* MyTextResource.java */
+
+public class MyTextResource
+extends SimpleTextResource
+{
+ public MyTextResource()
+ {
+ data.put("Hi", "Hello");
+ data.put("To", "World");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_de.java b/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_de.java new file mode 100644 index 0000000..6de99cb --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_de.java @@ -0,0 +1,11 @@ +/* MyTextResource_de.java */
+
+public class MyTextResource_de
+extends SimpleTextResource
+{
+ public MyTextResource_de()
+ {
+ data.put("Hi", "Hallo");
+ data.put("To", "Welt");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_de_CH.java b/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_de_CH.java new file mode 100644 index 0000000..044e022 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_de_CH.java @@ -0,0 +1,11 @@ +/* MyTextResource_de_CH.java */
+
+public class MyTextResource_de_CH
+extends SimpleTextResource
+{
+ public MyTextResource_de_CH()
+ {
+ data.put("Hi", "Grüezi");
+ data.put("To", "Schweiz");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_en.java b/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_en.java new file mode 100644 index 0000000..15e4926 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_en.java @@ -0,0 +1,10 @@ +/* MyTextResource_en.java */
+
+public class MyTextResource_en
+extends SimpleTextResource
+{
+ public MyTextResource_en()
+ {
+ data.put("To", "World of English");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_fr.properties b/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_fr.properties new file mode 100644 index 0000000..e612cc9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/MyTextResource_fr.properties @@ -0,0 +1,2 @@ +Hi=Salut
+To=monde francais
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/MyTimeStore.java b/Master/Reference Architectures and Patterns/hjp5/examples/MyTimeStore.java new file mode 100644 index 0000000..0e74d3e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/MyTimeStore.java @@ -0,0 +1,19 @@ +/* MyTimeStore.java */
+
+import java.io.*;
+
+public class MyTimeStore
+implements TimeStore, Serializable
+{
+ String time;
+
+ public void setTime(String time)
+ {
+ this.time = time;
+ }
+
+ public String getTime()
+ {
+ return this.time;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/PackageDemo.java b/Master/Reference Architectures and Patterns/hjp5/examples/PackageDemo.java new file mode 100644 index 0000000..8c6b2f4 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/PackageDemo.java @@ -0,0 +1,12 @@ +import demo.*;
+import demo.tools.*;
+
+public class PackageDemo
+{
+ public static void main(String[] args)
+ {
+ (new A()).hello();
+ (new B()).hello();
+ (new C()).hello();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/PapierBlatt.java b/Master/Reference Architectures and Patterns/hjp5/examples/PapierBlatt.java new file mode 100644 index 0000000..2271265 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/PapierBlatt.java @@ -0,0 +1,48 @@ +/* PapierBlatt.java */
+
+public class PapierBlatt
+implements Groesse
+{
+ public int format; //0=DIN A0, 1=DIN A1 usw.
+
+ public int laenge()
+ {
+ int ret = 0;
+ if (format == 0) {
+ ret = 1189;
+ } else if (format == 1) {
+ ret = 841;
+ } else if (format == 2) {
+ ret = 594;
+ } else if (format == 3) {
+ ret = 420;
+ } else if (format == 4) {
+ ret = 297;
+ }
+ //usw...
+ return ret;
+ }
+
+ public int hoehe()
+ {
+ return 0;
+ }
+
+ public int breite()
+ {
+ int ret = 0;
+ if (format == 0) {
+ ret = 841;
+ } else if (format == 1) {
+ ret = 594;
+ } else if (format == 2) {
+ ret = 420;
+ } else if (format == 3) {
+ ret = 297;
+ } else if (format == 4) {
+ ret = 210;
+ }
+ //usw...
+ return ret;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Person.java b/Master/Reference Architectures and Patterns/hjp5/examples/Person.java new file mode 100644 index 0000000..b279022 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Person.java @@ -0,0 +1,14 @@ +import java.io.*;
+
+public class Person
+implements Serializable
+{
+ public String name;
+ public Person mother;
+ public Person father;
+
+ public Person(String name)
+ {
+ this.name = name;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/PlaySound.java b/Master/Reference Architectures and Patterns/hjp5/examples/PlaySound.java new file mode 100644 index 0000000..dc4a93e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/PlaySound.java @@ -0,0 +1,25 @@ +/* PlaySound.java */
+
+import java.net.*;
+import java.applet.*;
+
+public class PlaySound
+{
+ public static void main(String[] args)
+ {
+ if (args.length >= 1) {
+ try {
+ URL url = new URL(args[0]);
+ AudioClip clip = Applet.newAudioClip(url);
+ clip.play();
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ }
+ System.exit(0);
+ } catch (MalformedURLException e) {
+ System.out.println(e.toString());
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Polygon.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Polygon.inc new file mode 100644 index 0000000..cb1cebc --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Polygon.inc @@ -0,0 +1,9 @@ +/* Polygon.inc */
+
+public void paint(Graphics g)
+{
+ int[] arx = {50,50,120,120,80,80,100,100,80,80};
+ int[] ary = {170,40,40,70,70,100,100,130,130,170};
+
+ g.drawPolygon(arx,ary,arx.length);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/PrimeNumberTools.java b/Master/Reference Architectures and Patterns/hjp5/examples/PrimeNumberTools.java new file mode 100644 index 0000000..02ddbfb --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/PrimeNumberTools.java @@ -0,0 +1,48 @@ +/* PrimeNumberTools.java */
+
+public class PrimeNumberTools
+{
+ public void printPrimeFactors(int num)
+ {
+ int whichprime = 1;
+ int prime;
+ String prefix;
+
+ prefix = "primeFactors("+num+")= ";
+ while (num > 1) {
+ prime = getPrime(whichprime);
+ if (num % prime == 0) {
+ System.out.print(prefix+prime);
+ prefix = " ";
+ num /= prime;
+ } else {
+ ++whichprime;
+ }
+ }
+ System.out.println();
+ }
+
+ public int getPrime(int cnt)
+ {
+ int i = 1;
+ int ret = 2;
+
+ while (i < cnt) {
+ ++ret;
+ if (isPrime(ret)) {
+ ++i;
+ }
+ }
+ return ret;
+ }
+
+ private boolean isPrime(int num)
+ {
+ for (int i = 2; i < num; ++i) {
+ if (num % i == 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/PrintableObject.java b/Master/Reference Architectures and Patterns/hjp5/examples/PrintableObject.java new file mode 100644 index 0000000..63e8a5c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/PrintableObject.java @@ -0,0 +1,70 @@ +/* PrintableObject.java */
+
+import java.lang.reflect.*;
+
+public class PrintableObject
+{
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer(200);
+ Class clazz = getClass();
+ while (clazz != null) {
+ Field[] fields = clazz.getDeclaredFields();
+ for (int i = 0; i < fields.length; ++i) {
+ sb.append(fields[i].getName() + " = ");
+ try {
+ Object obj = fields[i].get(this);
+ if (obj.getClass().isArray()) {
+ Object[] ar = (Object[])obj;
+ for (int j = 0; j < ar.length; ++j) {
+ sb.append(ar[j].toString() + " ");
+ }
+ sb.append("\n");
+ } else {
+ sb.append(obj.toString() + "\n");
+ }
+ } catch (IllegalAccessException e) {
+ sb.append(e.toString() + "\n");
+ }
+ }
+ clazz = clazz.getSuperclass();
+ }
+ return sb.toString();
+ }
+
+ public static void main(String[] args)
+ {
+ JavaProgrammer jim = new JavaProgrammer();
+ jim.name = "Jim Miller";
+ jim.department = "Operating Systems";
+ jim.age = 32;
+ String[] langs = {"C", "Pascal", "PERL", "Java"};
+ jim.languages = langs;
+ jim.linesofcode = 55000;
+ jim.jdk12 = true;
+ jim.swing = false;
+ System.out.println(jim);
+ }
+}
+
+class Employee
+extends PrintableObject
+{
+ public String name;
+ public String department;
+ public int age;
+}
+
+class Programmer
+extends Employee
+{
+ public String[] languages;
+ public int linesofcode;
+}
+
+class JavaProgrammer
+extends Programmer
+{
+ public boolean jdk12;
+ public boolean swing;
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/ProfTest1A.java b/Master/Reference Architectures and Patterns/hjp5/examples/ProfTest1A.java new file mode 100644 index 0000000..384b2ed --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/ProfTest1A.java @@ -0,0 +1,21 @@ +/* ProfTest1A.java */
+
+import java.util.*;
+
+public class ProfTest1A
+{
+ public static String dots(int len)
+ {
+ String ret = "";
+ for (int i = 0; i < len; ++i) {
+ ret += ".";
+ }
+ return ret;
+ }
+
+ public static void main(String[] args)
+ {
+ String s = dots(10000);
+ System.out.println(s);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/ProfTest1B.java b/Master/Reference Architectures and Patterns/hjp5/examples/ProfTest1B.java new file mode 100644 index 0000000..98b068e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/ProfTest1B.java @@ -0,0 +1,21 @@ +/* ProfTest1B.java */
+
+import java.util.*;
+
+public class ProfTest1B
+{
+ public static String dots(int len)
+ {
+ StringBuilder sb = new StringBuilder(len + 10);
+ for (int i = 0; i < len; ++i) {
+ sb.append('.');
+ }
+ return sb.toString();
+ }
+
+ public static void main(String[] args)
+ {
+ String s = dots(10000);
+ System.out.println(s);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Puzzle.java b/Master/Reference Architectures and Patterns/hjp5/examples/Puzzle.java new file mode 100644 index 0000000..68ccfd0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Puzzle.java @@ -0,0 +1,345 @@ +/**
+ * @(#)Puzzle.java 1.000 97/07/23
+ *
+ * Copyright (c) 1997 Guido Krueger. All Rights Reserved.
+ *
+ * Dieses Applet ist die Implementierung eines Schiebepuzzles
+ * mit 4 x 4 Feldern. Auf den zunächst unsortierten Spielsteinen
+ * werden die Bestandteile eines Images angezeigt, die dann per
+ * Drag & Drop sortiert werden können. Der einzig erlaubte Zug
+ * besteht darin, einen Stein in die benachbarte Lücke zu
+ * verschieben. Durch Klicken auf den Rahmen kann die Sortierung
+ * umgekehrt werden.
+ *
+ * Das applet-Tag erwartet folgende Parameter:
+ *
+ * bordersize = Breite des Spielfeldrandes
+ * src = Name der Bilddatei (gif oder jpeg)
+ *
+ */
+import java.awt.*;
+import java.awt.event.*;
+import java.applet.*;
+import java.util.*;
+
+public class Puzzle
+extends Applet
+{
+ int aFields[][]; //Brett mit allen Feldern
+ Image image; //Bildspeicher
+ int bordersize; //Randbreite
+ Dimension fieldsize; //Größe eines Feldes
+ Dimension imagesize; //Größe des Bildes
+ Point sourcefield; //Bei Mausklick ausgewähltes Feld
+ Point lastpoint; //Ursprung des letzten Rechtecks
+ Point drawoffset; //Offset zur Mausdragposition
+
+ public void init()
+ {
+ aFields = new int[4][4];
+ sourcefield = new Point(-1, -1);
+ lastpoint = new Point(-1, -1);
+ drawoffset = new Point(0,0);
+ bordersize = Integer.parseInt(getParameter("bordersize"));
+ if (bordersize < 1 || bordersize > 50) {
+ bordersize = 5;
+ }
+ setBackground(Color.lightGray);
+ addMouseListener(new MyMouseListener());
+ addMouseMotionListener(new MyMouseMotionListener());
+ prepareImage();
+ randomizeField(true);
+ }
+
+ public void update(Graphics g)
+ {
+ Image dbImage;
+ Graphics dbGraphics;
+
+ //Double-Buffer initialisieren
+ dbImage = createImage(getSize().width,getSize().height);
+ dbGraphics = dbImage.getGraphics();
+ //Hintergrund löschen
+ dbGraphics.setColor(getBackground());
+ dbGraphics.fillRect(0,0,getSize().width,getSize().height);
+ //Vordergrund zeichnen
+ dbGraphics.setColor(getForeground());
+ paint(dbGraphics);
+ //Offscreen-Image anzeigen
+ g.drawImage(dbImage,0,0,this);
+ dbGraphics.dispose();
+ }
+
+ public void paint(Graphics g)
+ {
+ paintBorder(g);
+ paintField(g);
+ }
+
+ /**
+ * Zeichnet den Rahmen des Spielbretts.
+ */
+ private void paintBorder(Graphics g)
+ {
+ Insets insets = getInsets();
+ Dimension size = getSize();
+ size.height -= insets.top + insets.bottom;
+ size.width -= insets.left + insets.right;
+ fieldsize = new Dimension();
+ fieldsize.width = (size.width - (2 * bordersize)) / 4;
+ fieldsize.height = (size.height - (2 * bordersize)) / 4;
+ g.setColor(Color.black);
+ g.drawRect(
+ insets.left,
+ insets.top,
+ size.width - 1,
+ size.height - 2
+ );
+ g.drawRect(
+ insets.left + bordersize,
+ insets.top + bordersize,
+ 4 * fieldsize.width,
+ 4 * fieldsize.height
+ );
+ }
+
+ /**
+ * Zeichnet die Spielsteine auf dem Brett.
+ */
+ private void paintField(Graphics g)
+ {
+ int imagenumber, image_i, image_j;
+ Insets insets = getInsets();
+ Point topleft = new Point();
+ topleft.x = insets.left + bordersize;
+ topleft.y = insets.top + bordersize;
+ g.setColor(Color.black);
+ for (int i = 0; i <= 3; ++i) {
+ for (int j = 0; j <= 3; ++j) {
+ imagenumber = aFields[i][j];
+ if (imagenumber == 15) {
+ //Lücke zeichnen
+ g.fillRect(
+ topleft.x + j * fieldsize.width,
+ topleft.y + i * fieldsize.height,
+ fieldsize.width,
+ fieldsize.height
+ );
+ } else {
+ //Image darstellen
+ image_i = imagenumber / 4;
+ image_j = imagenumber % 4;
+ g.drawImage(
+ image,
+ topleft.x + j * fieldsize.width,
+ topleft.y + i * fieldsize.height,
+ topleft.x + j * fieldsize.width + fieldsize.width,
+ topleft.y + i * fieldsize.height + fieldsize.height,
+ image_j * (imagesize.width / 4),
+ image_i * (imagesize.height / 4),
+ image_j * (imagesize.width / 4) + imagesize.width / 4,
+ image_i * (imagesize.height / 4) + imagesize.height / 4,
+ this
+ );
+ //Rahmen
+ g.drawRect(
+ topleft.x + j * fieldsize.width,
+ topleft.y + i * fieldsize.height,
+ fieldsize.width,
+ fieldsize.height
+ );
+ //Beschriftung
+ g.drawString(
+ "" + imagenumber,
+ topleft.x + j * fieldsize.width + 2,
+ topleft.y + i * fieldsize.height + 12
+ );
+ }
+ }
+ }
+ }
+
+ /**
+ * Lädt das Bild.
+ */
+ private void prepareImage()
+ {
+ //Bild laden
+ image = getImage(getDocumentBase(),getParameter("src"));
+ MediaTracker mt = new MediaTracker(this);
+ mt.addImage(image, 0);
+ try {
+ //Warten, bis das Image vollständig geladen ist,
+ mt.waitForAll();
+ } catch (InterruptedException e) {
+ //nothing
+ }
+ imagesize = new Dimension();
+ imagesize.height = image.getHeight(this);
+ imagesize.width = image.getWidth(this);
+ }
+
+ /**
+ * Mischt die Steine auf dem Spielfeld.
+ */
+ private void randomizeField(boolean unordered)
+ {
+ int i, j, k, tmp;
+
+ //Zuerst sortieren...
+ for (i = 0; i <= 15; ++i) {
+ aFields[i / 4][i % 4] = i;
+ }
+ //Dann mischen...
+ if (unordered) {
+ Random rand = new Random(System.currentTimeMillis());
+ for (i = 0; i < 20; ++i) {
+ j = Math.abs(rand.nextInt()) % 16;
+ k = Math.abs(rand.nextInt()) % 16;
+ tmp = aFields[j / 4][j % 4];
+ aFields[j / 4][j % 4] = aFields[k / 4][k % 4];
+ aFields[k / 4][k % 4] = tmp;
+ }
+ }
+ }
+
+ class MyMouseListener
+ extends MouseAdapter
+ {
+ /**
+ * Maustaste gedrückt.
+ */
+ public void mousePressed(MouseEvent event)
+ {
+ sourcefield = getFieldFromCursor(event.getX(), event.getY());
+ if (sourcefield.x == -1 || sourcefield.y == -1) {
+ swapRandomization();
+ repaint();
+ }
+ lastpoint.x = -1;
+ lastpoint.y = -1;
+ }
+
+ /**
+ * Maustaste losgelassen.
+ */
+ public void mouseReleased(MouseEvent event)
+ {
+ if (sourcefield.x != -1 && sourcefield.y != -1) {
+ Point destfield;
+ destfield = getFieldFromCursor(event.getX(), event.getY());
+ if (destfield.x != -1 && destfield.y != -1) {
+ if (aFields[destfield.y][destfield.x] == 15) {
+ if (areNeighbours(sourcefield, destfield)) {
+ aFields[destfield.y][destfield.x] =
+ aFields[sourcefield.y][sourcefield.x];
+ aFields[sourcefield.y][sourcefield.x] = 15;
+ }
+ }
+ }
+ repaint();
+ }
+ sourcefield.x = -1;
+ sourcefield.y = -1;
+ }
+
+ /**
+ * Liefert den zur Mausposition passenden horizontalen und
+ * vertikalen Index des darunterliegenden Steins. Liegt der
+ * Punkt auf dem Rahmen, wird (-1,-1) zurückgegeben.
+ */
+ private Point getFieldFromCursor(int x, int y)
+ {
+ Insets insets = getInsets();
+ Point topleft = new Point();
+ topleft.x = insets.left + bordersize;
+ topleft.y = insets.top + bordersize;
+ Point ret = new Point(-1, -1);
+ if (x >= topleft.x) {
+ if (x < topleft.x + 4 * fieldsize.width) {
+ if (y >= topleft.y) {
+ if (y < topleft.y + 4 * fieldsize.height) {
+ ret.x = (x - topleft.x) / fieldsize.width;
+ ret.y = (y - topleft.y) / fieldsize.height;
+ drawoffset.x = x - topleft.x -
+ ret.x * fieldsize.width;
+ drawoffset.y = y - topleft.y -
+ ret.y * fieldsize.height;
+ }
+ }
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * Testet, ob die durch p1 und p2 bezeichneten Spielsteine
+ * Nachbarn sind.
+ */
+ private boolean areNeighbours(Point p1, Point p2)
+ {
+ int aNeighbours[][] = {{-1,0},{0,-1},{0,1},{1,0}};
+ for (int i = 0; i < aNeighbours.length; ++i) {
+ if (p1.x + aNeighbours[i][0] == p2.x) {
+ if (p1.y + aNeighbours[i][1] == p2.y) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Kehrt die Steineordnung um: falls sie sortiert sind,
+ * werden sie gemischt und umgekehrt.
+ */
+ private void swapRandomization()
+ {
+ //Sind die Felder sortiert?
+ boolean sorted = true;
+ for (int i = 0; i <= 15; ++i) {
+ if (aFields[i / 4][i % 4] != i) {
+ sorted = false;
+ break;
+ }
+ }
+ //Neu mischen bzw. sortieren
+ randomizeField(sorted);
+ }
+ }
+
+ class MyMouseMotionListener
+ extends MouseMotionAdapter
+ {
+ /**
+ * Maus wurde bei gedrückter Taste bewegt.
+ */
+ public void mouseDragged(MouseEvent event)
+ {
+ if (sourcefield.x != -1 && sourcefield.y != -1) {
+ Graphics g = getGraphics();
+ g.setXORMode(getBackground());
+ g.setColor(Color.black);
+ //Das zuletzt gezeichnete Rechteck entfernen
+ if (lastpoint.x != -1) {
+ g.drawRect(
+ lastpoint.x - drawoffset.x,
+ lastpoint.y - drawoffset.y,
+ fieldsize.width,
+ fieldsize.height
+ );
+ }
+ //Neues Rechteck zeichnen
+ g.drawRect(
+ event.getX() - drawoffset.x,
+ event.getY() - drawoffset.y,
+ fieldsize.width,
+ fieldsize.height
+ );
+ lastpoint.x = event.getX();
+ lastpoint.y = event.getY();
+ g.dispose();
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/RTErrorProg1.java b/Master/Reference Architectures and Patterns/hjp5/examples/RTErrorProg1.java new file mode 100644 index 0000000..a36f0d9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/RTErrorProg1.java @@ -0,0 +1,14 @@ +/* RTErrorProg1.java */
+
+public class RTErrorProg1
+{
+ public static void main(String[] args)
+ {
+ int i, base = 0;
+
+ for (base = 10; base >= 2; --base) {
+ i = Integer.parseInt("40",base);
+ System.out.println("40 base "+base+" = "+i);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/RTErrorProg2.java b/Master/Reference Architectures and Patterns/hjp5/examples/RTErrorProg2.java new file mode 100644 index 0000000..7c4ce59 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/RTErrorProg2.java @@ -0,0 +1,20 @@ +/* RTErrorProg2.java */
+
+public class RTErrorProg2
+{
+ public static void main(String[] args)
+ {
+ int i, base = 0;
+
+ try {
+ for (base = 10; base >= 2; --base) {
+ i = Integer.parseInt("40",base);
+ System.out.println("40 base "+base+" = "+i);
+ }
+ } catch (NumberFormatException e) {
+ System.out.println("***Fehler aufgetreten***");
+ System.out.println("Ursache: "+e.getMessage());
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Rechtecke.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Rechtecke.inc new file mode 100644 index 0000000..9566c74 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Rechtecke.inc @@ -0,0 +1,20 @@ +/* Rechtecke.inc */
+
+public void paint(Graphics g)
+{
+ int x = 10, y = 80;
+ int sizex, sizey = 0;
+
+ while (x < 280 && y < 180) {
+ sizex = 4 + (int) (Math.random() * 9);
+ if (Math.random() > 0.5) {
+ y += sizey;
+ sizey = 4 + (int) (Math.random() * 6);
+ } else {
+ sizey = 4 + (int) (Math.random() * 6);
+ y -= sizey;
+ }
+ g.drawRect(x,y,sizex,sizey);
+ x += sizex;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Revision.java b/Master/Reference Architectures and Patterns/hjp5/examples/Revision.java new file mode 100644 index 0000000..32dca38 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Revision.java @@ -0,0 +1,17 @@ +import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+// Diese Annotation ist auf Klassen und Methoden beschränkt
+@Target({ElementType.TYPE, ElementType.METHOD})
+
+// Die Information soll auch zur Laufzeit zur Verfügung stehen
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Revision
+{
+ int id();
+ String name();
+ String vorname();
+ String notizen() default "";
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/RunCommand.java b/Master/Reference Architectures and Patterns/hjp5/examples/RunCommand.java new file mode 100644 index 0000000..03f1de9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/RunCommand.java @@ -0,0 +1,101 @@ +/* RunCommand.java */
+
+import java.io.*;
+
+public class RunCommand
+{
+ static final int MODE_UNCONNECTED = 0;
+ static final int MODE_WAITFOR = 1;
+ static final int MODE_CATCHOUTPUT = 2;
+
+ private static void runCommand(String cmd, int mode)
+ throws IOException
+ {
+ Runtime rt = Runtime.getRuntime();
+ System.out.println("Running " + cmd);
+ Process pr = rt.exec(cmd);
+ if (mode == MODE_WAITFOR) {
+ System.out.println("waiting for termination");
+ try {
+ pr.waitFor();
+ } catch (InterruptedException e) {
+ }
+ } else if (mode == MODE_CATCHOUTPUT) {
+ System.out.println("catching output");
+ BufferedReader procout = new BufferedReader(
+ new InputStreamReader(pr.getInputStream())
+ );
+ String line;
+ while ((line = procout.readLine()) != null) {
+ System.out.println(" OUT> " + line);
+ }
+ }
+ try {
+ System.out.println(
+ "done, return value is " + pr.exitValue()
+ );
+ } catch (IllegalThreadStateException e) {
+ System.out.println(
+ "ok, process is running asynchronously"
+ );
+ }
+ }
+
+ private static void runShellCommand(String cmd, int mode)
+ throws IOException
+ {
+ String prefix = "";
+ String osName = System.getProperty("os.name");
+ osName = osName.toLowerCase();
+ if (osName.indexOf("windows") != -1) {
+ if (osName.indexOf("95") != -1) {
+ prefix = "command.com /c ";
+ } else if (osName.indexOf("98") != -1) {
+ prefix = "command.com /c ";
+ }
+ }
+ if (prefix.length() <= 0) {
+ System.out.println(
+ "unknown OS: don\'t know how to invoke shell"
+ );
+ } else {
+ runCommand(prefix + cmd, mode);
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ if (args.length <= 0) {
+ System.out.println(
+ "Usage: java RunCommand [-shell] " +
+ "[-waitfor|-catchoutput] <command>"
+ );
+ System.exit(1);
+ }
+ boolean shell = false;
+ int mode = MODE_UNCONNECTED;
+ String cmd = "";
+ for (int i = 0; i < args.length; ++i) {
+ if (args[i].startsWith("-")) {
+ if (args[i].equals("-shell")) {
+ shell = true;
+ } else if (args[i].equals("-waitfor")) {
+ mode = MODE_WAITFOR;
+ } else if (args[i].equals("-catchoutput")) {
+ mode = MODE_CATCHOUTPUT;
+ }
+ } else {
+ cmd = args[i];
+ }
+ }
+ if (shell) {
+ runShellCommand(cmd, mode);
+ } else {
+ runCommand(cmd, mode);
+ }
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SaveURL.java b/Master/Reference Architectures and Patterns/hjp5/examples/SaveURL.java new file mode 100644 index 0000000..1493741 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SaveURL.java @@ -0,0 +1,35 @@ +/* SaveURL.java */
+
+import java.net.*;
+import java.io.*;
+
+public class SaveURL
+{
+ public static void main(String[] args)
+ {
+ if (args.length != 2) {
+ System.err.println(
+ "Usage: java SaveURL <url> <file>"
+ );
+ System.exit(1);
+ }
+ try {
+ URL url = new URL(args[0]);
+ OutputStream out = new FileOutputStream(args[1]);
+ InputStream in = url.openStream();
+ int len;
+ byte[] b = new byte[100];
+ while ((len = in.read(b)) != -1) {
+ out.write(b, 0, len);
+ }
+ out.close();
+ in.close();
+ } catch (MalformedURLException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc new file mode 100644 index 0000000..d50e494 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc @@ -0,0 +1,47 @@ +/* Schlange2.inc */
+
+public void run()
+{
+ //Schlange konstruieren
+ ColorRectangle cr;
+ int x = 100;
+ int y = 100;
+ for (int i=0; i < NUMELEMENTS; ++i) {
+ cr = new ColorRectangle();
+ cr.x = x;
+ cr.y = y;
+ cr.width = SIZERECT;
+ cr.height = SIZERECT;
+ x += SIZERECT;
+ cr.color = new Color(
+ i*(256/NUMELEMENTS),
+ 0,
+ 240-i*(256/NUMELEMENTS)
+ );
+ snake.addElement(cr);
+ }
+
+ //Löschelement anhängen
+ cr = new ColorRectangle();
+ cr.x = x;
+ cr.y = y;
+ cr.width = SIZERECT;
+ cr.height = SIZERECT;
+ cr.color = BGCOLOR;
+ snake.addElement(cr);
+
+ //Vorzugsrichtung festlegen
+ dx = -1;
+ dy = -1;
+
+ //Schlange laufen lassen
+ while (true) {
+ repaint();
+ try {
+ Thread.sleep(SLEEP);
+ } catch (InterruptedException e){
+ //nichts
+ }
+ moveSnake();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Schranke.html b/Master/Reference Architectures and Patterns/hjp5/examples/Schranke.html new file mode 100644 index 0000000..59b6d1c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Schranke.html @@ -0,0 +1,13 @@ +<html>
+<head>
+<title>Schranke</title>
+</head>
+<body>
+<h1>Schranke</h1>
+<applet code="Schranke.class" width=400 height=10>
+<param name="redwidth" value=10>
+<param name="whitewidth" value=7>
+Hier steht das Applet Schranke.class
+</applet>
+</body>
+</html>
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Schranke.java b/Master/Reference Architectures and Patterns/hjp5/examples/Schranke.java new file mode 100644 index 0000000..25f798d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Schranke.java @@ -0,0 +1,53 @@ +/* Schranke.java */
+
+import java.awt.*;
+import java.applet.*;
+
+public class Schranke
+extends Applet
+{
+ private int[] dx;
+ private Color[] color;
+
+ public void init()
+ {
+ String tmp;
+
+ dx = new int[2];
+ try {
+ dx[0] = Integer.parseInt(
+ getParameter("redwidth")
+ );
+ dx[1] = Integer.parseInt(
+ getParameter("whitewidth")
+ );
+ } catch (NumberFormatException e) {
+ dx[0] = 10;
+ dx[1] = 10;
+ }
+ color = new Color[2];
+ color[0] = Color.red;
+ color[1] = Color.white;
+ }
+
+ public void paint(Graphics g)
+ {
+ int maxX = getSize().width;
+ int maxY = getSize().height;
+ int x = 0;
+ int flg = 0;
+ Polygon p;
+ while (x <= maxX+maxY/2) {
+ p = new Polygon();
+ p.addPoint(x,0);
+ p.addPoint(x+dx[flg],0);
+ p.addPoint(x+dx[flg]-maxY/2,maxY);
+ p.addPoint(x-maxY/2,maxY);
+ p.addPoint(x,0);
+ g.setColor(color[flg]);
+ g.fillPolygon(p);
+ x += dx[flg];
+ flg = (flg==0) ? 1 : 0;
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SchriftGroesser.inc b/Master/Reference Architectures and Patterns/hjp5/examples/SchriftGroesser.inc new file mode 100644 index 0000000..235d3de --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SchriftGroesser.inc @@ -0,0 +1,17 @@ +/* SchriftGroesser.inc */
+
+public void paint(Graphics g)
+{
+ Font font = getFont();
+
+ if (font.getSize() <= 64) {
+ setFont(
+ new Font(
+ font.getFamily(),
+ font.getStyle(),
+ font.getSize() + 1
+ )
+ );
+ }
+ g.drawString("Hello, World",40,100);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Schriften.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Schriften.inc new file mode 100644 index 0000000..abab956 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Schriften.inc @@ -0,0 +1,13 @@ +/* Schriften.inc */
+
+public void paint(Graphics g)
+{
+ Font font;
+ String[] arfonts = {"Serif","SansSerif","Monospaced"};
+
+ for (int i=0; i<arfonts.length; ++i) {
+ font = new Font(arfonts[i],Font.PLAIN,36);
+ g.setFont(font);
+ g.drawString(arfonts[i],10,30 + (i+1)*(36+5));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Scrollbar.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Scrollbar.inc new file mode 100644 index 0000000..0d2e877 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Scrollbar.inc @@ -0,0 +1,40 @@ +/* Scrollbar.inc */
+
+public void adjustmentValueChanged(AdjustmentEvent event)
+{
+ Adjustable sb = event.getAdjustable();
+ if (sb.getOrientation() == Scrollbar.HORIZONTAL) {
+ System.out.print("Horizontal: ");
+ } else {
+ System.out.print("Vertikal: ");
+ }
+ switch (event.getAdjustmentType()) {
+ case AdjustmentEvent.UNIT_INCREMENT:
+ System.out.println("AdjustmentEvent.UNIT_INCREMENT");
+ break;
+ case AdjustmentEvent.UNIT_DECREMENT:
+ System.out.println("AdjustmentEvent.UNIT_DECREMENT");
+ break;
+ case AdjustmentEvent.BLOCK_DECREMENT:
+ System.out.println("AdjustmentEvent.BLOCK_DECREMENT");
+ break;
+ case AdjustmentEvent.BLOCK_INCREMENT:
+ System.out.println("AdjustmentEvent.BLOCK_INCREMENT");
+ break;
+ case AdjustmentEvent.TRACK:
+ System.out.println("AdjustmentEvent.TRACK");
+ break;
+ }
+ System.out.println(" value: " + event.getValue());
+}
+
+private void customizeLayout(Panel panel)
+{
+ panel.setLayout(new BorderLayout());
+ Scrollbar hsb=new Scrollbar(Scrollbar.HORIZONTAL,1,10,1,100);
+ hsb.addAdjustmentListener(this);
+ panel.add(hsb, BorderLayout.SOUTH);
+ Scrollbar vsb=new Scrollbar(Scrollbar.VERTICAL, 1,10,1,100);
+ vsb.addAdjustmentListener(this);
+ panel.add(vsb, BorderLayout.EAST);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SecuMgrTest.java b/Master/Reference Architectures and Patterns/hjp5/examples/SecuMgrTest.java new file mode 100644 index 0000000..fabacf3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SecuMgrTest.java @@ -0,0 +1,11 @@ +/* SecuMgrTest.java */
+
+public class SecuMgrTest
+{
+ public static void main(String[] args)
+ {
+ System.out.println(
+ "user.name is " + System.getProperty("user.name")
+ );
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Segment7.java b/Master/Reference Architectures and Patterns/hjp5/examples/Segment7.java new file mode 100644 index 0000000..8306cd5 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Segment7.java @@ -0,0 +1,170 @@ +/* Segment7.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+class Segment7
+extends Canvas
+{
+ private int digit;
+ private boolean hasfocus;
+ private int[][] polysx = {
+ { 1, 2, 8, 9, 8, 2}, //Segment 0
+ { 9,10,10, 9, 8, 8}, //Segment 1
+ { 9,10,10, 9, 8, 8}, //Segment 2
+ { 1, 2, 8, 9, 8, 2}, //Segment 3
+ { 1, 2, 2, 1, 0, 0}, //Segment 4
+ { 1, 2, 2, 1, 0, 0}, //Segment 5
+ { 1, 2, 8, 9, 8, 2}, //Segment 6
+ };
+ private int[][] polysy = {
+ { 1, 0, 0, 1, 2, 2}, //Segment 0
+ { 1, 2, 8, 9, 8, 2}, //Segment 1
+ { 9,10,16,17,16,10}, //Segment 2
+ {17,16,16,17,18,18}, //Segment 3
+ { 9,10,16,17,16,10}, //Segment 4
+ { 1, 2, 8, 9, 8, 2}, //Segment 5
+ { 9, 8, 8, 9,10,10}, //Segment 6
+ };
+ private int[][] digits = {
+ {1,1,1,1,1,1,0}, //Ziffer 0
+ {0,1,1,0,0,0,0}, //Ziffer 1
+ {1,1,0,1,1,0,1}, //Ziffer 2
+ {1,1,1,1,0,0,1}, //Ziffer 3
+ {0,1,1,0,0,1,1}, //Ziffer 4
+ {1,0,1,1,0,1,1}, //Ziffer 5
+ {1,0,1,1,1,1,1}, //Ziffer 6
+ {1,1,1,0,0,0,0}, //Ziffer 7
+ {1,1,1,1,1,1,1}, //Ziffer 8
+ {1,1,1,1,0,1,1} //Ziffer 9
+ };
+
+ public Segment7()
+ {
+ this(0);
+ }
+
+ public Segment7(int digit)
+ {
+ super();
+ this.digit = digit;
+ this.hasfocus = false;
+ enableEvents(AWTEvent.COMPONENT_EVENT_MASK);
+ enableEvents(AWTEvent.FOCUS_EVENT_MASK);
+ enableEvents(AWTEvent.MOUSE_EVENT_MASK);
+ enableEvents(AWTEvent.KEY_EVENT_MASK);
+ }
+
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(5*10,5*18);
+ }
+
+ public Dimension getMinimumSize()
+ {
+ return new Dimension(1*10,1*18);
+ }
+
+ public boolean isFocusTraversable()
+ {
+ return true;
+ }
+
+ public void paint(Graphics g)
+ {
+ Color darkred = new Color(127,0,0);
+ Color lightred = new Color(255,0,0);
+ Color yellow = new Color(255,255,0);
+ //dx und dy berechnen
+ int dx = getSize().width / 10;
+ int dy = getSize().height / 18;
+ //Hintergrund
+ g.setColor(darkred);
+ g.fillRect(0,0,getSize().width,getSize().height);
+ //Segmente
+ if (hasfocus) {
+ g.setColor(yellow);
+ } else {
+ g.setColor(lightred);
+ }
+ for (int i=0; i < 7; ++i) { //alle Segmente
+ if (digits[digit][i] == 1) {
+ Polygon poly = new Polygon();
+ for (int j = 0; j < 6; ++j) { //alle Eckpunkte
+ poly.addPoint(dx*polysx[i][j],dy*polysy[i][j]);
+ }
+ g.fillPolygon(poly);
+ }
+ }
+ //Trennlinien
+ g.setColor(darkred);
+ g.drawLine(0,0,dx*10,dy*10);
+ g.drawLine(0,8*dy,10*dx,18*dy);
+ g.drawLine(0,10*dy,10*dx,0);
+ g.drawLine(0,18*dy,10*dx,8*dy);
+ }
+
+ public int getValue()
+ {
+ return digit;
+ }
+
+ public void setValue(int value)
+ {
+ digit = value % 10;
+ }
+
+ protected void processComponentEvent(ComponentEvent event)
+ {
+ if (event.getID() == ComponentEvent.COMPONENT_SHOWN) {
+ requestFocus();
+ }
+ super.processComponentEvent(event);
+ }
+
+ protected void processFocusEvent(FocusEvent event)
+ {
+ if (event.getID() == FocusEvent.FOCUS_GAINED) {
+ hasfocus = true;
+ repaint();
+ } else if (event.getID() == FocusEvent.FOCUS_LOST) {
+ hasfocus = false;
+ repaint();
+ }
+ super.processFocusEvent(event);
+ }
+
+ protected void processMouseEvent(MouseEvent event)
+ {
+ if (event.getID() == MouseEvent.MOUSE_PRESSED) {
+ requestFocus();
+ if (!event.isShiftDown()) {
+ if (event.isMetaDown()) {
+ setValue(getValue() + 1); //increment by 1
+ } else {
+ setValue(getValue() + 9); //decrement by 1
+ }
+ }
+ repaint();
+ }
+ super.processMouseEvent(event);
+ }
+
+ protected void processKeyEvent(KeyEvent event)
+ {
+ if (event.getID() == KeyEvent.KEY_PRESSED) {
+ char key = event.getKeyChar();
+ if (key >= '0' && key <= '9') {
+ setValue(key - '0');
+ repaint();
+ } else if (key == '+') {
+ setValue(getValue() + 1); //increment by 1
+ repaint();
+ } else if (key == '-') {
+ setValue(getValue() + 9); //decrement by 1
+ repaint();
+ }
+ }
+ super.processKeyEvent(event);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SimpleEchoServer.java b/Master/Reference Architectures and Patterns/hjp5/examples/SimpleEchoServer.java new file mode 100644 index 0000000..c4d5379 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SimpleEchoServer.java @@ -0,0 +1,30 @@ +/* SimpleEchoServer.java */
+
+import java.net.*;
+import java.io.*;
+
+public class SimpleEchoServer
+{
+ public static void main(String[] args)
+ {
+ try {
+ System.out.println("Warte auf Verbindung auf Port 7...");
+ ServerSocket echod = new ServerSocket(7);
+ Socket socket = echod.accept();
+ System.out.println("Verbindung hergestellt");
+ InputStream in = socket.getInputStream();
+ OutputStream out = socket.getOutputStream();
+ int c;
+ while ((c = in.read()) != -1) {
+ out.write((char)c);
+ System.out.print((char)c);
+ }
+ System.out.println("Verbindung beenden");
+ socket.close();
+ echod.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SimpleFilePrinter.java b/Master/Reference Architectures and Patterns/hjp5/examples/SimpleFilePrinter.java new file mode 100644 index 0000000..043fa38 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SimpleFilePrinter.java @@ -0,0 +1,124 @@ +/* SimpleFilePrinter.java */
+
+import java.awt.*;
+import java.awt.print.*;
+import java.io.*;
+
+public class SimpleFilePrinter
+implements Printable
+{
+ //---Konstanten--------------------------------------
+ private static final int RESMUL = 4;
+
+ //---Membervariablen---------------------------------
+ private PrinterJob pjob;
+ private PageFormat pageformat;
+ private FilePrintHelper fph;
+ private String fname;
+ private RandomAccessFile in;
+
+ //---Konstruktoren-----------------------------------
+ public SimpleFilePrinter(String fname)
+ {
+ this.pjob = PrinterJob.getPrinterJob();
+ this.fname = fname;
+ }
+
+ //---Öffentliche Methoden----------------------------
+ public boolean setupPageFormat()
+ {
+ PageFormat defaultPF = pjob.defaultPage();
+ this.pageformat = pjob.pageDialog(defaultPF);
+ pjob.setPrintable(this, this.pageformat);
+ return (this.pageformat != defaultPF);
+ }
+
+ public boolean setupJobOptions()
+ {
+ return pjob.printDialog();
+ }
+
+ public void printFile()
+ throws PrinterException, IOException
+ {
+ fph = new FilePrintHelper();
+ in = new RandomAccessFile(fname, "r");
+ pjob.print();
+ in.close();
+ }
+
+ //---Implementierung von Printable-------------------
+ public int print(Graphics g, PageFormat pf, int page)
+ throws PrinterException
+ {
+ int ret = PAGE_EXISTS;
+ String line = null;
+ try {
+ if (fph.knownPage(page)) {
+ in.seek(fph.getFileOffset(page));
+ line = in.readLine();
+ } else {
+ long offset = in.getFilePointer();
+ line = in.readLine();
+ if (line == null) {
+ ret = NO_SUCH_PAGE;
+ } else {
+ fph.createPage(page);
+ fph.setFileOffset(page, offset);
+ }
+ }
+ if (ret == PAGE_EXISTS) {
+ //Seite ausgeben, Grafikkontext vorbereiten
+ Graphics2D g2 = (Graphics2D)g;
+ g2.scale(1.0 / RESMUL, 1.0 / RESMUL);
+ int ypos = (int)pf.getImageableY() * RESMUL;
+ int xpos = ((int)pf.getImageableX() + 2) * RESMUL;
+ int yd = 12 * RESMUL;
+ int ymax = ypos + (int)pf.getImageableHeight() * RESMUL - yd;
+ //Seitentitel ausgeben
+ ypos += yd;
+ g2.setColor(Color.black);
+ g2.setFont(new Font("Monospaced", Font.BOLD, 10 * RESMUL));
+ g.drawString(fname + ", Seite " + (page + 1), xpos, ypos);
+ g.drawLine(
+ xpos,
+ ypos + 6 * RESMUL,
+ xpos + (int)pf.getImageableWidth() * RESMUL,
+ ypos + 6 * RESMUL
+ );
+ ypos += 2 * yd;
+ //Zeilen ausgeben
+ g2.setColor(new Color(0, 0, 127));
+ g2.setFont(new Font("Monospaced", Font.PLAIN, 10 * RESMUL));
+ while (line != null) {
+ g.drawString(line, xpos, ypos);
+ ypos += yd;
+ if (ypos >= ymax) {
+ break;
+ }
+ line = in.readLine();
+ }
+ }
+ } catch (IOException e) {
+ throw new PrinterException(e.toString());
+ }
+ return ret;
+ }
+
+ //---Main--------------------------------------------
+ public static void main(String[] args)
+ {
+ SimpleFilePrinter sfp = new SimpleFilePrinter(args[0]);
+ if (sfp.setupPageFormat()) {
+ if (sfp.setupJobOptions()) {
+ try {
+ sfp.printFile();
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+ }
+ System.exit(0);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SimpleIntList.java b/Master/Reference Architectures and Patterns/hjp5/examples/SimpleIntList.java new file mode 100644 index 0000000..d1b77d7 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SimpleIntList.java @@ -0,0 +1,72 @@ +public class SimpleIntList
+{
+ private int[] data;
+ private int len;
+
+ public SimpleIntList(int size)
+ {
+ this.data = new int[size];
+ this.len = 0;
+ }
+
+ public void add(int value)
+ {
+ //Precondition als RuntimeException
+ if (full()) {
+ throw new RuntimeException("Liste voll");
+ }
+ //Implementierung
+ data[len++] = value;
+ //Postcondition
+ assert !empty();
+ }
+
+ public void bubblesort()
+ {
+ if (!empty()) {
+ int cnt = 0;
+ while (true) {
+ //Schleifeninvariante
+ assert cnt++ < len: "Zu viele Iterationen";
+ //Implementierung...
+ boolean sorted = true;
+ for (int i = 1; i < len; ++i) {
+ if (sortTwoElements(i - 1, i)) {
+ sorted = false;
+ }
+ }
+ if (sorted) {
+ break;
+ }
+ }
+ }
+ }
+
+ public boolean empty()
+ {
+ return len <= 0;
+ }
+
+ public boolean full()
+ {
+ return len >= data.length;
+ }
+
+ private boolean sortTwoElements(int pos1, int pos2)
+ {
+ //Private Preconditions
+ assert (pos1 >= 0 && pos1 < len);
+ assert (pos2 >= 0 && pos2 < len);
+ //Implementierung...
+ boolean ret = false;
+ if (data[pos1] > data[pos2]) {
+ int tmp = data[pos1];
+ data[pos1] = data[pos2];
+ data[pos2] = tmp;
+ ret = true;
+ }
+ //Postcondition
+ assert data[pos1] <= data[pos2] : "Sortierfehler";
+ return ret;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SimpleTextResource.java b/Master/Reference Architectures and Patterns/hjp5/examples/SimpleTextResource.java new file mode 100644 index 0000000..9ab5989 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SimpleTextResource.java @@ -0,0 +1,24 @@ +/* SimpleTextResource.java */
+
+import java.util.*;
+
+public class SimpleTextResource
+extends ResourceBundle
+{
+ protected Hashtable data = new Hashtable();
+
+ public Enumeration getKeys()
+ {
+ return data.keys();
+ }
+
+ public Object handleGetObject(String key)
+ {
+ return data.get(key);
+ }
+
+ public ResourceBundle getParent()
+ {
+ return parent;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SimpleTreeNode.java b/Master/Reference Architectures and Patterns/hjp5/examples/SimpleTreeNode.java new file mode 100644 index 0000000..ba96c14 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SimpleTreeNode.java @@ -0,0 +1,8 @@ +/* SimpleTreeNode.java */
+
+public interface SimpleTreeNode
+{
+ public void addChild(SimpleTreeNode child);
+ public int getChildCnt();
+ public SimpleTreeNode getChild(int pos);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Singleton.java b/Master/Reference Architectures and Patterns/hjp5/examples/Singleton.java new file mode 100644 index 0000000..b837e53 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Singleton.java @@ -0,0 +1,16 @@ +public class Singleton
+{
+ private static Singleton instance = null;
+
+ public static Singleton getInstance()
+ {
+ if (instance == null) {
+ instance = new Singleton();
+ }
+ return instance;
+ }
+
+ private Singleton()
+ {
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SkyscraperApplet.html b/Master/Reference Architectures and Patterns/hjp5/examples/SkyscraperApplet.html new file mode 100644 index 0000000..ade2a63 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SkyscraperApplet.html @@ -0,0 +1,14 @@ +<html>
+<head>
+<title>Skyscraper</title>
+</head>
+<body>
+<h1>Skyscraper</h1>
+<applet code=SkyscraperApplet.class width=500 height=300>
+<param name="delay" value=75>
+<param name="flash" value=0.01>
+<param name="thunder" value="thunder.au">
+Hier steht das Applet Skyscraper.class
+</applet>
+</body>
+</html>
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SkyscraperApplet.java b/Master/Reference Architectures and Patterns/hjp5/examples/SkyscraperApplet.java new file mode 100644 index 0000000..ad39822 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SkyscraperApplet.java @@ -0,0 +1,185 @@ +/* SkyscraperApplet.java */
+
+import java.awt.*;
+import java.util.*;
+import java.applet.*;
+
+class Skyscraper
+{
+ public int x;
+ public int y;
+ public int width;
+ public int height;
+ int wndcntx;
+ int wndcnty;
+ boolean blinkon = false;
+
+ Skyscraper(int x, int y)
+ {
+ this.x = x;
+ this.y = y;
+ this.width = (int)(30*(0.5+Math.random()));
+ this.height = (int)(100*(0.5+Math.random()));
+ wndcntx = (width-4)/5;
+ wndcnty = (height-4)/5;
+ }
+
+ void LightEvent(Graphics g)
+ {
+ double rnd = Math.random();
+ int xwnd = (int)(Math.random()*wndcntx);
+ int ywnd = (int)(Math.random()*wndcnty);
+ if (blinkon) {
+ g.setColor(Color.black);
+ g.fillRect(x+width/2,y-height-20,2,2);
+ blinkon = false;
+ }
+ if (rnd >= 0.9) {
+ blinkon = true;
+ g.setColor(Color.red);
+ g.fillRect(x+width/2,y-height-20,2,2);
+ } else if (rnd >= 0.7) {
+ g.setColor(Color.black);
+ g.fillRect(x+2+xwnd*5,y-height+2+ywnd*5,2,2);
+ } else {
+ g.setColor(Color.yellow);
+ g.fillRect(x+2+xwnd*5,y-height+2+ywnd*5,2,2);
+ }
+ }
+}
+
+public class SkyscraperApplet
+extends Applet
+implements Runnable
+{
+ //Membervariablen
+ Thread th;
+ Vector v = new Vector();
+ AudioClip thunder;
+ boolean running;
+
+ //Parameter
+ int DELAY;
+ float FLASH;
+ String THUNDER;
+
+ public void init()
+ {
+ Skyscraper house;
+ int x = 5;
+
+ //Häuser erzeugen
+ while (this.getSize().width-x-1 >= 30) {
+ house = new Skyscraper(x,this.getSize().height-10);
+ v.addElement(house);
+ x += house.width + 5;
+ }
+ setBackground(Color.black);
+
+ //Parameter einlesen
+ try {
+ DELAY = Integer.parseInt(getParameter("delay"));
+ } catch (NumberFormatException e) {
+ DELAY = 75;
+ }
+ try {
+ FLASH = (new Float(getParameter("flash"))).floatValue();
+ } catch (NumberFormatException e) {
+ FLASH = 0.01F;
+ }
+ THUNDER = getParameter("thunder");
+ if (THUNDER != null) {
+ thunder = getAudioClip(getCodeBase(),THUNDER);
+ }
+ System.out.println("DELAY = "+DELAY);
+ System.out.println("FLASH = "+FLASH);
+ System.out.println("THUNDER = "+THUNDER);
+ }
+
+ public void start()
+ {
+ if (th == null) {
+ running = true;
+ th = new Thread(this);
+ th.start();
+ }
+ }
+
+ public void stop()
+ {
+ if (th != null) {
+ running = false;
+ th = null;
+ }
+ }
+
+ public void run()
+ {
+ while (running) {
+ repaint();
+ try {
+ Thread.sleep(DELAY);
+ } catch (InterruptedException e) {
+ //nothing
+ }
+ }
+ }
+
+ public void update(Graphics g)
+ {
+ paint(g);
+ }
+
+ public void paint(Graphics g)
+ {
+ int i;
+ Skyscraper house;
+
+ i = (int)Math.floor(Math.random()*v.size());
+ house = (Skyscraper)v.elementAt(i);
+ house.LightEvent(g);
+ if (Math.random() < FLASH) {
+ Lightning(g,house.x+10,house.y-house.height);
+ }
+ }
+
+ public void Lightning(Graphics g, int x, int y)
+ {
+ Vector poly = new Vector();
+ int dx, dy, i, polysize;
+
+ thunder.play();
+ //Blitzpolygon berechnen
+ poly.addElement(new Point(x,y));
+ polysize = 1;
+ while (y > 10) {
+ dx = 10 - (int)(Math.floor(Math.random()*20));
+ dy = - (int)(Math.floor(Math.random()*20));
+ x += dx;
+ y += dy;
+ poly.addElement(new Point(x,y));
+ ++polysize;
+ }
+ //Blitzvector in Koordinaten-Arrays umwandeln
+ int[] xpoints = new int[poly.size()];
+ int[] ypoints = new int[poly.size()];
+ for (i = 0; i < polysize; ++i) {
+ Point p = (Point)poly.elementAt(i);
+ xpoints[i] = p.x;
+ ypoints[i] = p.y;
+ }
+ //Blitz zeichnen
+ for (i = 0; i <= 1; ++i) {
+ g.setColor(Color.white);
+ g.drawPolyline(xpoints, ypoints, polysize);
+ try {
+ Thread.sleep(20);
+ } catch (InterruptedException e) {}
+ g.setColor(Color.black);
+ g.drawPolyline(xpoints, ypoints, polysize);
+ try {
+ Thread.sleep(20);
+ } catch (InterruptedException e) {}
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SparseTableModel.java b/Master/Reference Architectures and Patterns/hjp5/examples/SparseTableModel.java new file mode 100644 index 0000000..cd9c3d2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SparseTableModel.java @@ -0,0 +1,75 @@ +/* SparseTableModel.java */
+
+import java.util.*;
+import javax.swing.*;
+import javax.swing.table.*;
+
+public class SparseTableModel
+extends AbstractTableModel
+{
+ private int size;
+ private Hashtable data;
+
+ //Konstruktor
+ public SparseTableModel(int size)
+ {
+ this.size = size;
+ this.data = new Hashtable();
+ }
+
+ //Methoden für das TableModel-Interface
+ public int getRowCount()
+ {
+ return size;
+ }
+
+ public int getColumnCount()
+ {
+ return size;
+ }
+
+ public String getColumnName(int columnIndex)
+ {
+ return "C" + columnIndex;
+ }
+
+ public Class getColumnClass(int columnIndex)
+ {
+ return String.class;
+ }
+
+ public boolean isCellEditable(int rowIndex, int columnIndex)
+ {
+ return rowIndex < size && columnIndex < size;
+ }
+
+ public Object getValueAt(int rowIndex, int columnIndex)
+ {
+ String key = "[" + rowIndex + "," + columnIndex + "]";
+ String value = (String)data.get(key);
+ return value == null ? "-" : value;
+ }
+
+ public void setValueAt(Object aValue, int rowIndex, int columnIndex)
+ {
+ String key = "[" + rowIndex + "," + columnIndex + "]";
+ String value = (String)aValue;
+ if (value.length() <= 0) {
+ data.remove(key);
+ } else {
+ data.put(key, value);
+ }
+ }
+
+ //Zusätzliche Methoden
+ public void printData()
+ {
+ Enumeration e = data.keys();
+ while (e.hasMoreElements()) {
+ String key = (String)e.nextElement();
+ System.out.println(
+ "At " + key + ": " + (String)data.get(key)
+ );
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SplashScreen.java b/Master/Reference Architectures and Patterns/hjp5/examples/SplashScreen.java new file mode 100644 index 0000000..29f3cd4 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/SplashScreen.java @@ -0,0 +1,50 @@ +/* SplashScreen.java */
+
+import javax.swing.*;
+import javax.swing.border.*;
+import java.awt.*;
+import java.awt.event.*;
+
+public class SplashScreen
+extends JWindow
+{
+ public SplashScreen(String image, String text)
+ {
+ JPanel contentPane = new JPanel();
+ contentPane.setLayout(new BorderLayout());
+ Border bd1 = BorderFactory.createBevelBorder(
+ BevelBorder.RAISED
+ );
+ Border bd2 = BorderFactory.createEtchedBorder();
+ Border bd3 = BorderFactory.createCompoundBorder(bd1, bd2);
+ ((JPanel)contentPane).setBorder(bd3);
+ ImageIcon icon = new ImageIcon(image);
+ contentPane.add(new JLabel(" ", JLabel.CENTER), BorderLayout.NORTH);
+ contentPane.add(new JLabel(icon, JLabel.CENTER), BorderLayout.CENTER);
+ contentPane.add(new JLabel(text, JLabel.CENTER), BorderLayout.SOUTH);
+ setContentPane(contentPane);
+ }
+
+ public void showFor(int millis)
+ {
+ Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
+ setLocation(dim.width / 3, dim.height / 3);
+ setSize(dim.width / 3, dim.height / 3);
+ setVisible(true);
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException e) {
+ }
+ setVisible(false);
+ }
+
+ public static void main(String[] args)
+ {
+ SplashScreen intro = new SplashScreen(
+ "mine.gif",
+ "(C) Copyright 2000, J. Krüger, All Rights Reserved"
+ );
+ intro.showFor(3000);
+ System.exit(0);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Standardschriften.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Standardschriften.inc new file mode 100644 index 0000000..32d4990 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Standardschriften.inc @@ -0,0 +1,13 @@ +/* Standardschriften.inc */
+
+public void paint(Graphics g)
+{
+ Font font;
+ String[] arfonts = Toolkit.getDefaultToolkit().getFontList();
+
+ for (int i=0; i<arfonts.length; ++i) {
+ font = new Font(arfonts[i],Font.PLAIN,36);
+ g.setFont(font);
+ g.drawString(arfonts[i],10,(i+1)*(36+5));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Standardschriften12.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Standardschriften12.inc new file mode 100644 index 0000000..4016b3e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Standardschriften12.inc @@ -0,0 +1,15 @@ +/* Standardschriften12.inc */
+
+public void paint(Graphics g)
+{
+ Font font;
+ GraphicsEnvironment ge =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ String[] arfonts = ge.getAvailableFontFamilyNames();
+
+ for (int i=0; i<arfonts.length; ++i) {
+ font = new Font(arfonts[i],Font.PLAIN,36);
+ g.setFont(font);
+ g.drawString(arfonts[i],10,(i+1)*(36+5));
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TableData.java b/Master/Reference Architectures and Patterns/hjp5/examples/TableData.java new file mode 100644 index 0000000..4f122a0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TableData.java @@ -0,0 +1,29 @@ +/* TableData.java */
+
+public interface TableData
+{
+ public static final String[][] DATA = {
+ {" 1/1987", "195", "Vergleichstest EGA-Karten"},
+ {" 2/1987", "171", "Schneider PC: Bewährungsprobe"},
+ {" 3/1987", "235", "Luxus-Textsyteme im Vergleich"},
+ {" 4/1987", "195", "Turbo BASIC"},
+ {" 5/1987", "211", "640-K-Grenze durchbrochen"},
+ {" 6/1987", "211", "Expertensysteme"},
+ {" 7/1987", "199", "IBM Model 30 im Detail"},
+ {" 8/1987", "211", "PAK-68: Tuning für 68000er"},
+ {" 9/1987", "215", "Desktop Publishing"},
+ {"10/1987", "279", "2,5 MByte im ST"},
+ {"11/1987", "279", "Transputer-Praxis"},
+ {"12/1987", "271", "Preiswert mit 24 Nadeln"},
+ {" 1/1988", "247", "Schnelle 386er"},
+ {" 2/1988", "231", "Hayes-kompatible Modems"},
+ {" 3/1988", "295", "TOS/GEM auf 68020"},
+ {" 4/1988", "263", "Projekt Super-EGA"},
+ {" 5/1988", "263", "Neuheiten auf der CeBIT 88"},
+ {" 6/1988", "231", "9600-Baud-Modem am Postnetz"}
+ };
+
+ public static final String[] COLHEADS = {
+ "Ausgabe", "Seiten", "Titelthema"
+ };
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Test.java b/Master/Reference Architectures and Patterns/hjp5/examples/Test.java new file mode 100644 index 0000000..e1c90c3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Test.java @@ -0,0 +1,82 @@ +/* Test.java */
+
+import java.lang.reflect.*;
+
+public class Test
+{
+ public static Object createTestObject(String name)
+ {
+ //Klassennamen zusammenbauen
+ int pos = name.lastIndexOf('.');
+ if (pos == -1) {
+ name = "Test" + name;
+ } else {
+ name = name.substring(0, pos + 1) + "Test" +
+ name.substring(pos + 1);
+ }
+ //Klasse laden
+ Object ret = null;
+ try {
+ Class testclass = Class.forName(name);
+ //Testobjekt instanzieren
+ System.out.println("==============================");
+ System.out.println("Instanzieren von: " + name);
+ System.out.println("--");
+ ret = testclass.newInstance();
+ } catch (ClassNotFoundException e) {
+ System.err.println("Kann Klasse nicht laden: " + name);
+ } catch (InstantiationException e) {
+ System.err.println("Fehler beim Instanzieren: " + name);
+ } catch (IllegalAccessException e) {
+ System.err.println("Unerlaubter Zugriff auf: " + name);
+ }
+ return ret;
+ }
+
+ public static void runTests(Object tester)
+ {
+ Class clazz = tester.getClass();
+ Method[] methods = clazz.getMethods();
+ int cnt = 0;
+ for (int i = 0; i < methods.length; ++i) {
+ //Methodenname muss mit "test" anfangen
+ String name = methods[i].getName();
+ if (!name.startsWith("test")) {
+ continue;
+ }
+ //Methode muss parameterlos sein
+ Class[] paras = methods[i].getParameterTypes();
+ if (paras.length > 0) {
+ continue;
+ }
+ //Methode darf nicht static sein
+ int modifiers = methods[i].getModifiers();
+ if (Modifier.isStatic(modifiers)) {
+ continue;
+ }
+ //Nun kann die Methode aufgerufen werden
+ ++cnt;
+ System.out.println("==============================");
+ System.out.println("Aufgerufen wird: " + name);
+ System.out.println("--");
+ try {
+ methods[i].invoke(tester, new Object[0]);
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ }
+ }
+ if (cnt <= 0) {
+ System.out.println("Keine Testmethoden gefunden");
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ if (args.length <= 0) {
+ System.err.println("Aufruf: java Test <KlassenName>");
+ System.exit(1);
+ }
+ Object tester = createTestObject(args[0]);
+ runTests(tester);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TestFile.java b/Master/Reference Architectures and Patterns/hjp5/examples/TestFile.java new file mode 100644 index 0000000..91bae8a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TestFile.java @@ -0,0 +1,40 @@ +/* TestFile.java */
+
+import java.io.*;
+import java.util.*;
+
+public class TestFile
+{
+ public static void main(String[] args)
+ {
+ File fil = new File("TestFile.java");
+ TestFile.printFileInfo(fil);
+ fil = new File("..");
+ TestFile.printFileInfo(fil);
+ }
+
+ static void printFileInfo(File fil)
+ {
+ System.out.println("Name= "+fil.getName());
+ System.out.println("Path= "+fil.getPath());
+ System.out.println("AbsolutePath= "+fil.getAbsolutePath());
+ System.out.println("Parent= "+fil.getParent());
+ System.out.println("exists= "+fil.exists());
+ System.out.println("canWrite= "+fil.canWrite());
+ System.out.println("canRead= "+fil.canRead());
+ System.out.println("isFile= "+fil.isFile());
+ System.out.println("isDirectory= "+fil.isDirectory());
+ if (fil.isDirectory()) {
+ String[] fils = fil.list();
+ for (int i=0; i<fils.length; ++i) {
+ System.out.println(" "+fils[i]);
+ }
+ }
+ System.out.println("isAbsolute= "+fil.isAbsolute());
+ System.out.println(
+ "lastModified= "+(new Date(fil.lastModified()))
+ );
+ System.out.println("length= "+fil.length());
+ System.out.println("");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TestResource.inc b/Master/Reference Architectures and Patterns/hjp5/examples/TestResource.inc new file mode 100644 index 0000000..b499e8f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TestResource.inc @@ -0,0 +1,28 @@ +/* TestResource.inc */
+
+import java.io.*;
+import java.awt.*;
+
+//...
+
+public String loadTextResource(String pkgname, String fname)
+throws IOException
+{
+ String ret = null;
+ InputStream is = getResourceStream(pkgname, fname);
+ if (is != null) {
+ StringBuffer sb = new StringBuffer();
+ while (true) {
+ int c = is.read();
+ if (c == -1) {
+ break;
+ }
+ sb.append((char)c);
+ }
+ is.close();
+ ret = sb.toString();
+ }
+ return ret;
+}
+
+//...
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Testauto.java b/Master/Reference Architectures and Patterns/hjp5/examples/Testauto.java new file mode 100644 index 0000000..54ce94b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Testauto.java @@ -0,0 +1,25 @@ +/* Testauto.java */
+
+public class Testauto
+{
+ static private int objcnt = 0;
+
+ public Testauto()
+ {
+ ++objcnt;
+ }
+
+ public void finalize()
+ {
+ --objcnt;
+ }
+
+ public static void main(String[] args)
+ {
+ Testauto auto1;
+ Testauto auto2 = new Testauto();
+ System.out.println(
+ "Anzahl Testauto-Objekte: " + Testauto.objcnt
+ );
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TextArea1.inc b/Master/Reference Architectures and Patterns/hjp5/examples/TextArea1.inc new file mode 100644 index 0000000..dba22aa --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TextArea1.inc @@ -0,0 +1,9 @@ +/* TextArea1.inc */
+
+private void customizeLayout(Panel panel)
+{
+ panel.setLayout(new FlowLayout(FlowLayout.LEFT));
+ TextArea ta = new TextArea(10,40);
+ ta.addTextListener(this);
+ panel.add(ta);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TextArea2.inc b/Master/Reference Architectures and Patterns/hjp5/examples/TextArea2.inc new file mode 100644 index 0000000..0fcca36 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TextArea2.inc @@ -0,0 +1,7 @@ +/* TextArea2.inc */
+
+public void textValueChanged(TextEvent event)
+{
+ TextArea tf = (TextArea)event.getSource();
+ System.out.println("textValueChanged: "+tf.getText());
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TextField1.inc b/Master/Reference Architectures and Patterns/hjp5/examples/TextField1.inc new file mode 100644 index 0000000..a56259a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TextField1.inc @@ -0,0 +1,15 @@ +/* TextField1.inc */
+
+public void actionPerformed(ActionEvent event)
+{
+ Object obj = event.getSource();
+ if (obj instanceof TextField) {
+ System.out.println(
+ "ButtonAction: "+event.getActionCommand()
+ );
+ } else if (obj instanceof Button) {
+ if (event.getActionCommand().equals("Ende")) {
+ endDialog();
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TextField2.inc b/Master/Reference Architectures and Patterns/hjp5/examples/TextField2.inc new file mode 100644 index 0000000..3e9f750 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TextField2.inc @@ -0,0 +1,7 @@ +/* TextField2.inc */
+
+public void textValueChanged(TextEvent event)
+{
+ TextField tf = (TextField)event.getSource();
+ System.out.println("textValueChanged: "+tf.getText());
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TextField3.inc b/Master/Reference Architectures and Patterns/hjp5/examples/TextField3.inc new file mode 100644 index 0000000..3628d2f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TextField3.inc @@ -0,0 +1,25 @@ +/* TextField3.inc */
+
+private void customizeLayout(Panel panel)
+{
+ panel.setLayout(new FlowLayout(FlowLayout.LEFT));
+ Panel labelPanel = new Panel();
+ labelPanel.setLayout(new GridLayout(3,1));
+ labelPanel.add(new Label("Name",Label.LEFT));
+ labelPanel.add(new Label("Vorname",Label.LEFT));
+ labelPanel.add(new Label("Ort",Label.LEFT));
+ Panel editPanel = new Panel();
+ editPanel.setLayout(new GridLayout(3,1));
+
+ //Dieses Textfeld sendet Action- und Text-Ereignisse
+ TextField tf = new TextField("Meier",20);
+ tf.addActionListener(this);
+ tf.addTextListener(this);
+ editPanel.add(tf);
+
+ //Diese Textfelder senden keine Ereignisse
+ editPanel.add(new TextField("Luise",20));
+ editPanel.add(new TextField("Hamburg",20));
+ panel.add(labelPanel);
+ panel.add(editPanel);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Textausgabe.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Textausgabe.inc new file mode 100644 index 0000000..e11e36a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Textausgabe.inc @@ -0,0 +1,13 @@ +/* Textausgabe.inc */
+
+public void paint(Graphics g)
+{
+ int maxX=getSize().width-getInsets().left-getInsets().right;
+ int maxY=getSize().height-getInsets().top-getInsets().bottom;
+
+ g.drawString(
+ "Die Client-Area ist "+maxX+"*"+maxY+" Pixel groß",
+ getInsets().left + maxX/2,
+ getInsets().top + maxY/2
+ );
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/ThreadedPrimeNumberTools.java b/Master/Reference Architectures and Patterns/hjp5/examples/ThreadedPrimeNumberTools.java new file mode 100644 index 0000000..b162918 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/ThreadedPrimeNumberTools.java @@ -0,0 +1,37 @@ +/* ThreadedPrimeNumberTools.java */
+
+public class ThreadedPrimeNumberTools
+extends PrimeNumberTools
+implements Runnable
+{
+ private int arg;
+ private int func;
+
+ public void printPrimeFactors(int num)
+ {
+ execAsynchron(1,num);
+ }
+
+ public void printPrime(int cnt)
+ {
+ execAsynchron(2,cnt);
+ }
+
+ public void run()
+ {
+ if (func == 1) {
+ super.printPrimeFactors(arg);
+ } else if (func == 2) {
+ int result = super.getPrime(arg);
+ System.out.println("prime number #"+arg+" is: "+result);
+ }
+ }
+
+ private void execAsynchron(int func, int arg)
+ {
+ Thread t = new Thread(this);
+ this.func = func;
+ this.arg = arg;
+ t.start();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/ThreeApplets.html b/Master/Reference Architectures and Patterns/hjp5/examples/ThreeApplets.html new file mode 100644 index 0000000..2f66e48 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/ThreeApplets.html @@ -0,0 +1,28 @@ +<html>
+<head>
+<title>ThreeApplets</title>
+</head>
+<body>
+
+A1:
+<applet code="ChgNextApplet.class" width=90 height=30 name="A1">
+<param name="next" value="A2">
+Applet A1
+</applet>
+
+<p>
+A2:
+<applet code="ChgNextApplet.class" width=90 height=30 name="A2">
+<param name="next" value="A3">
+Applet A2
+</applet>
+
+<p>
+A3:
+<applet code="ChgNextApplet.class" width=90 height=30 name="A3">
+<param name="next" value="A1">
+Applet A3
+</applet>
+
+</body>
+</html>
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Time.java b/Master/Reference Architectures and Patterns/hjp5/examples/Time.java new file mode 100644 index 0000000..1a1831c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Time.java @@ -0,0 +1,21 @@ +/* Time.java */
+
+import java.io.*;
+
+public class Time
+implements Serializable
+{
+ private int hour;
+ private int minute;
+
+ public Time(int hour, int minute)
+ {
+ this.hour = hour;
+ this.minute = minute;
+ }
+
+ public String toString()
+ {
+ return hour + ":" + minute;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TimeService.java b/Master/Reference Architectures and Patterns/hjp5/examples/TimeService.java new file mode 100644 index 0000000..6848dd6 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TimeService.java @@ -0,0 +1,14 @@ +/* TimeService.java */
+
+import java.rmi.*;
+import java.util.*;
+
+public interface TimeService
+extends Remote
+{
+ public String getTime()
+ throws RemoteException;
+
+ public TimeStore storeTime(TimeStore store)
+ throws RemoteException;
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TimeServiceClient.java b/Master/Reference Architectures and Patterns/hjp5/examples/TimeServiceClient.java new file mode 100644 index 0000000..2321ccb --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TimeServiceClient.java @@ -0,0 +1,27 @@ +/* TimeServiceClient.java */
+
+import java.rmi.*;
+
+public class TimeServiceClient
+{
+ public static void main(String[] args)
+ {
+ try {
+ String host = "ph01";
+ String port = "1099";
+ String srv = "TimeService";
+ String url = "rmi://" + host + ":" + port + "/" + srv;
+ System.out.println("Looking-up TimeService " + url);
+ TimeService ts = (TimeService)Naming.lookup(url);
+ System.out.println(" Server time is " + ts.getTime());
+ System.out.print(" MyTimeStore contains ");
+ TimeStore tsd = new MyTimeStore();
+ tsd = ts.storeTime(tsd);
+ System.out.println(tsd.getTime());
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TimeServiceImpl.java b/Master/Reference Architectures and Patterns/hjp5/examples/TimeServiceImpl.java new file mode 100644 index 0000000..0b9a4ea --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TimeServiceImpl.java @@ -0,0 +1,33 @@ +/* TimeServiceImpl.java */
+
+import java.rmi.*;
+import java.rmi.server.*;
+import java.util.*;
+
+public class TimeServiceImpl
+extends UnicastRemoteObject
+implements TimeService
+{
+ public TimeServiceImpl()
+ throws RemoteException
+ {
+ }
+
+ public String getTime()
+ throws RemoteException
+ {
+ GregorianCalendar cal = new GregorianCalendar();
+ StringBuffer sb = new StringBuffer();
+ sb.append(cal.get(Calendar.HOUR_OF_DAY));
+ sb.append(":" + cal.get(Calendar.MINUTE));
+ sb.append(":" + cal.get(Calendar.SECOND));
+ return sb.toString();
+ }
+
+ public TimeStore storeTime(TimeStore store)
+ throws RemoteException
+ {
+ store.setTime(getTime());
+ return store;
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TimeServiceRegistration.java b/Master/Reference Architectures and Patterns/hjp5/examples/TimeServiceRegistration.java new file mode 100644 index 0000000..7ce4741 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TimeServiceRegistration.java @@ -0,0 +1,21 @@ +/* TimeServiceRegistration.java */
+
+import java.rmi.*;
+import java.util.*;
+
+public class TimeServiceRegistration
+{
+ public static void main(String[] args)
+ {
+ System.setSecurityManager(new RMISecurityManager());
+ try {
+ System.out.println("Registering TimeService");
+ TimeServiceImpl tsi = new TimeServiceImpl();
+ Naming.rebind("TimeService", tsi);
+ System.out.println(" Done.");
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TimeStore.java b/Master/Reference Architectures and Patterns/hjp5/examples/TimeStore.java new file mode 100644 index 0000000..b79703b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TimeStore.java @@ -0,0 +1,9 @@ +import java.io.Serializable;
+
+public interface TimeStore
+extends Serializable
+{
+ public void setTime(String time);
+
+ public String getTime();
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TrivialObjectStore.java b/Master/Reference Architectures and Patterns/hjp5/examples/TrivialObjectStore.java new file mode 100644 index 0000000..3322481 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TrivialObjectStore.java @@ -0,0 +1,81 @@ +/* TrivialObjectStore.java */
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Trivialer Objektspeicher, der Mengen von Name-Objekt-
+ * Paaren aufnehmen und persistent speichern kann.
+ */
+public class TrivialObjectStore
+{
+ //Instance variables
+ private String fname;
+ private Hashtable objects;
+
+ /**
+ * Erzeugt einen neuen Objektspeicher mit dem angegebenen
+ * Namen (die Erweiterung ".tos" ("trivial object store")
+ * wird ggfs. automatisch angehängt.
+ */
+ public TrivialObjectStore(String fname)
+ {
+ this.fname = fname;
+ if (!fname.endsWith(".tos")) {
+ this.fname += ".tos";
+ }
+ this.objects = new Hashtable(50);
+ }
+
+ /**
+ * Sichert den Objektspeicher unter dem im Konstruktor
+ * angegebenen Namen.
+ */
+ public void save()
+ throws IOException
+ {
+ FileOutputStream fs = new FileOutputStream(fname);
+ ObjectOutputStream os = new ObjectOutputStream(fs);
+ os.writeObject(objects);
+ os.close();
+ }
+
+ /**
+ * Lädt den Objektspeicher mit dem im Konstruktor
+ * angegebenen Namen.
+ */
+ public void load()
+ throws ClassNotFoundException, IOException
+ {
+ FileInputStream fs = new FileInputStream(fname);
+ ObjectInputStream is = new ObjectInputStream(fs);
+ objects = (Hashtable)is.readObject();
+ is.close();
+ }
+
+ /**
+ * Fügt ein Objekt in den Objektspeicher ein.
+ */
+ public void putObject(String name, Object object)
+ {
+ objects.put(name, object);
+ }
+
+ /**
+ * Liest das Objekt mit dem angegebenen Namen aus dem
+ * Objektspeicher. Ist es nicht vorhanden, wird null
+ * zurückgegeben.
+ */
+ public Object getObject(String name)
+ {
+ return objects.get(name);
+ }
+
+ /**
+ * Liefert eine Aufzählung aller gespeicherten Namen.
+ */
+ public Enumeration getAllNames()
+ {
+ return objects.keys();
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/TrustedApplet.html b/Master/Reference Architectures and Patterns/hjp5/examples/TrustedApplet.html new file mode 100644 index 0000000..868ab88 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/TrustedApplet.html @@ -0,0 +1,21 @@ +<-- TrustedApplet.html -->
+
+<html>
+<head>
+<title>TrustedApplet Demo</title>
+</head>
+
+<body>
+<h1>TrustedApplet Demo</h1>
+
+<applet
+ archive="strapp.jar"
+ code="TrustedApplet.class"
+ width=600
+ height=200
+>
+TrustedApplet Demo
+</applet>
+
+</body>
+</html>
\ No newline at end of file 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 diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/URLLaden.html b/Master/Reference Architectures and Patterns/hjp5/examples/URLLaden.html new file mode 100644 index 0000000..7d76787 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/URLLaden.html @@ -0,0 +1,23 @@ +<html>
+<head>
+<title>URLLaden</title>
+</head>
+<body>
+<h1>URLLaden</h1>
+<applet code=URLLaden.class width=400 height=200>
+<param
+ name="button1"
+ value="JAVA-Home,http://java.sun.com/">
+<param
+ name="button2"
+ value="Guido-Home,http://www.gkrueger.com">
+<param
+ name="button3"
+ value="Schranke,=Schranke.html">
+<param
+ name="button4"
+ value="Jana30,=images/jana30.gif">
+Hier steht das Applet URLLaden.class
+</applet>
+</body>
+</html>
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/URLLaden.java b/Master/Reference Architectures and Patterns/hjp5/examples/URLLaden.java new file mode 100644 index 0000000..ca55ceb --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/URLLaden.java @@ -0,0 +1,82 @@ +/* URLLaden.java */
+
+import java.applet.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import java.net.*;
+
+class URLButton
+extends Button
+{
+ private URL url;
+
+ public URLButton(String label, URL url)
+ {
+ super(label);
+ this.url = url;
+ }
+
+ public URL getURL()
+ {
+ return url;
+ }
+}
+
+public class URLLaden
+extends Applet
+implements ActionListener
+{
+ Vector buttons;
+
+ public void init()
+ {
+ super.init();
+ setLayout(new FlowLayout());
+ addNotify();
+ buttons = new Vector();
+ for (int i=1; ; ++i) {
+ String s = getParameter("button"+i);
+ if (s == null) {
+ break;
+ }
+ try {
+ StringTokenizer st = new StringTokenizer(s,",");
+ String label = st.nextToken();
+ String urlstring = st.nextToken();
+ URL url;
+ if (urlstring.charAt(0) == '=') {
+ urlstring = urlstring.substring(1);
+ url = new URL(getDocumentBase(),urlstring);
+ } else {
+ url = new URL(urlstring);
+ }
+ URLButton button = new URLButton(label,url);
+ button.addActionListener(this);
+ add(button);
+ buttons.addElement(button);
+ } catch (NoSuchElementException e) {
+ System.out.println("Button"+i+": "+e.toString());
+ break;
+ } catch (MalformedURLException e) {
+ System.out.println("Button"+i+": "+e.toString());
+ break;
+ }
+ }
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ URLButton source = (URLButton)event.getSource();
+ Enumeration en = buttons.elements();
+ while (en.hasMoreElements()) {
+ URLButton button = (URLButton)en.nextElement();
+ if (button == source) {
+ System.out.println(
+ "showDocument("+button.getURL().toString()+")"
+ );
+ getAppletContext().showDocument(button.getURL());
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Unzip.java b/Master/Reference Architectures and Patterns/hjp5/examples/Unzip.java new file mode 100644 index 0000000..2b5c154 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Unzip.java @@ -0,0 +1,47 @@ +/* Unzip.java */
+
+import java.io.*;
+import java.util.zip.*;
+
+public class Unzip
+{
+ public static void main(String[] args)
+ {
+ if (args.length != 1) {
+ System.out.println("Usage: java Unzip zipfile");
+ System.exit(1);
+ }
+ try {
+ byte[] buf = new byte[4096];
+ ZipInputStream in = new ZipInputStream(
+ new FileInputStream(args[0]));
+ while (true) {
+ //Nächsten Eintrag lesen
+ ZipEntry entry = in.getNextEntry();
+ if (entry == null) {
+ break;
+ }
+ //Beschreibung ausgeben
+ System.out.println(
+ entry.getName() +
+ " (" + entry.getCompressedSize() + "/" +
+ entry.getSize() + ")"
+ );
+ //Ausgabedatei erzeugen
+ FileOutputStream out = new FileOutputStream(
+ entry.getName()
+ );
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ out.close();
+ //Eintrag schließen
+ in.closeEntry();
+ }
+ in.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/VerifySignature.java b/Master/Reference Architectures and Patterns/hjp5/examples/VerifySignature.java new file mode 100644 index 0000000..c3597bc --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/VerifySignature.java @@ -0,0 +1,49 @@ +/* VerifySignature.java */
+
+import java.io.*;
+import java.security.cert.Certificate;
+import java.security.*;
+
+public class VerifySignature
+{
+ static final String KEYSTORE = "c:\\windows\\.keystore";
+ static final char[] KSPASS = {'h','j','p','3','k','s'};
+ static final String ALIAS = "hjp3";
+
+ public static void main(String[] args)
+ {
+ try {
+ //Laden der Schlüsseldatenbank
+ KeyStore ks = KeyStore.getInstance("JKS");
+ FileInputStream ksin = new FileInputStream(KEYSTORE);
+ ks.load(ksin, KSPASS);
+ ksin.close();
+ //Zertifikat "hjp3" lesen
+ Certificate cert = ks.getCertificate(ALIAS);
+ //Signature-Objekt erstellen
+ Signature signature = Signature.getInstance("SHA/DSA");
+ signature.initVerify(cert.getPublicKey());
+ //Eingabedatei lesen
+ FileInputStream in = new FileInputStream(args[0]);
+ int len;
+ byte[] data = new byte[1024];
+ while ((len = in.read(data)) > 0) {
+ //Signatur updaten
+ signature.update(data, 0, len);
+ }
+ in.close();
+ //Signaturdatei einlesen
+ in = new FileInputStream(args[1]);
+ len = in.read(data);
+ in.close();
+ byte[] sign = new byte[len];
+ System.arraycopy(data, 0, sign, 0, len);
+ //Signatur ausgeben
+ boolean result = signature.verify(sign);
+ System.out.println("verification result: " + result);
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/VetoSwitch.java b/Master/Reference Architectures and Patterns/hjp5/examples/VetoSwitch.java new file mode 100644 index 0000000..ddc8a87 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/VetoSwitch.java @@ -0,0 +1,114 @@ +/* VetoSwitch.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import java.beans.*;
+
+public class VetoSwitch
+extends Canvas
+implements Serializable, VetoableChangeListener
+{
+ //---Instanzvariablen----------------------------------------
+ protected Color linecolor;
+ protected boolean vetoallchanges;
+
+ //---Methoden------------------------------------------------
+ public VetoSwitch()
+ {
+ this.linecolor = Color.black;
+ this.vetoallchanges = false;
+ initTransientState();
+ }
+
+ //---Konturenfarbe---
+ public void setLineColor(Color color)
+ {
+ this.linecolor = color;
+ }
+
+ public Color getLineColor()
+ {
+ return this.linecolor;
+ }
+
+ //---Zustandsumschaltung Licht an/aus---
+ public void setVetoAllChanges(boolean b)
+ {
+ if (this.vetoallchanges != b) {
+ this.vetoallchanges = b;
+ repaint();
+ }
+ }
+
+ public boolean getVetoAllChanges()
+ {
+ return this.vetoallchanges;
+ }
+
+ //---Veto---
+ public void vetoableChange(PropertyChangeEvent e)
+ throws PropertyVetoException
+ {
+ if (this.vetoallchanges) {
+ throw new PropertyVetoException("!!!VETO!!!", e);
+ }
+ }
+
+ //---Implementierung der Oberfläche---
+ public void paint(Graphics g)
+ {
+ int width = getSize().width;
+ int height = getSize().height;
+ g.setColor(linecolor);
+ g.drawRect(0, 0, width - 1, height - 1);
+ g.drawLine(width * 1 / 8, height / 2, width * 3 / 8, height / 2);
+ g.drawLine(width * 5 / 8, height / 2, width * 7 / 8, height / 2);
+ g.fillRect(width * 3 / 8 - 1, height / 2 - 1, 3, 3);
+ g.fillRect(width * 5 / 8 - 1, height / 2 - 1, 3, 3);
+ if (this.vetoallchanges) {
+ //draw open connection
+ g.drawLine(width * 3 / 8, height / 2, width * 5 / 8, height / 4);
+ } else {
+ //draw short-cutted connection
+ g.drawLine(width * 3 / 8, height / 2, width * 5 / 8, height / 2);
+ }
+ }
+
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(60, 20);
+ }
+
+ public Dimension getMinimumSize()
+ {
+ return new Dimension(28, 10);
+ }
+
+ //---Private Klassen----------------------------------------
+ private void initTransientState()
+ {
+ addMouseListener(new MouseClickAdapter());
+ }
+
+ /**
+ * Wird überlagert, um nach dem Deserialisieren den transienten
+ * Zustand zu initialisieren.
+ */
+ private void readObject(ObjectInputStream stream)
+ throws IOException, ClassNotFoundException
+ {
+ stream.defaultReadObject();
+ initTransientState();
+ }
+
+ //---Lokale Klassen----------------------------------------
+ class MouseClickAdapter
+ extends MouseAdapter
+ {
+ public void mouseClicked(MouseEvent event)
+ {
+ setVetoAllChanges(!getVetoAllChanges());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/WebStartTest2.java b/Master/Reference Architectures and Patterns/hjp5/examples/WebStartTest2.java new file mode 100644 index 0000000..43c383f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/WebStartTest2.java @@ -0,0 +1,40 @@ +/* WebStartTest2.java */
+
+import java.io.*;
+import javax.jnlp.*;
+
+public class WebStartTest2
+{
+ public static void main(String[] args)
+ {
+ try {
+ //FileOpenService anfordern
+ FileOpenService fos = (FileOpenService)ServiceManager.lookup(
+ "javax.jnlp.FileOpenService"
+ );
+ //DateiÖffnen-Dialog aufrufen
+ FileContents fc = fos.openFileDialog(null, null);
+ if (fc == null) {
+ System.err.println("openFileDialog fehlgeschlagen");
+ } else {
+ //Dateiinhalt auf der Konsole ausgeben
+ InputStream is = fc.getInputStream();
+ int c;
+ while ((c = is.read()) != -1) {
+ System.out.print((char)c);
+ }
+ is.close();
+ }
+ } catch (UnavailableServiceException e) {
+ System.err.println("***" + e + "***");
+ } catch (IOException e) {
+ System.err.println("***" + e + "***");
+ }
+ //10 Sekunden warten, dann Programm beenden
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ }
+ System.exit(0);
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/WindowClosingAdapter.java b/Master/Reference Architectures and Patterns/hjp5/examples/WindowClosingAdapter.java new file mode 100644 index 0000000..921fe57 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/WindowClosingAdapter.java @@ -0,0 +1,38 @@ +/* WindowClosingAdapter.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class WindowClosingAdapter
+extends WindowAdapter
+{
+ private boolean exitSystem;
+
+ /**
+ * Erzeugt einen WindowClosingAdapter zum Schliessen
+ * des Fensters. Ist exitSystem true, wird das komplette
+ * Programm beendet.
+ */
+ public WindowClosingAdapter(boolean exitSystem)
+ {
+ this.exitSystem = exitSystem;
+ }
+
+ /**
+ * Erzeugt einen WindowClosingAdapter zum Schliessen
+ * des Fensters. Das Programm wird nicht beendet.
+ */
+ public WindowClosingAdapter()
+ {
+ this(false);
+ }
+
+ public void windowClosing(WindowEvent event)
+ {
+ event.getWindow().setVisible(false);
+ event.getWindow().dispose();
+ if (exitSystem) {
+ System.exit(0);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Zentriert.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Zentriert.inc new file mode 100644 index 0000000..aa27d85 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Zentriert.inc @@ -0,0 +1,15 @@ +/* Zentriert.inc */
+
+public void paint(Graphics g)
+{
+ int maxX=getSize().width-getInsets().left-getInsets().right;
+ int maxY=getSize().height-getInsets().top-getInsets().bottom;
+ String s="Die Client-Area ist "+maxX+"*"+maxY+" Pixel groß";
+ FontMetrics fm = g.getFontMetrics();
+ int slen = fm.stringWidth(s);
+ g.drawString(
+ s,
+ getInsets().left + ((maxX - slen)/2),
+ getInsets().top + (maxY/2)
+ );
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Zip.java b/Master/Reference Architectures and Patterns/hjp5/examples/Zip.java new file mode 100644 index 0000000..6126656 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Zip.java @@ -0,0 +1,34 @@ +/* Zip.java */
+
+import java.io.*;
+import java.util.zip.*;
+
+public class Zip
+{
+ public static void main(String[] args)
+ {
+ if (args.length < 2) {
+ System.out.println("Usage: java Zip zipfile files...");
+ System.exit(1);
+ }
+ try {
+ byte[] buf = new byte[4096];
+ ZipOutputStream out = new ZipOutputStream(
+ new FileOutputStream(args[0]));
+ for (int i = 1; i < args.length; ++i) {
+ String fname = args[i];
+ System.out.println("adding " + fname);
+ FileInputStream in = new FileInputStream(fname);
+ out.putNextEntry(new ZipEntry(fname));
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ }
+ out.close();
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/ame.mid b/Master/Reference Architectures and Patterns/hjp5/examples/ame.mid Binary files differnew file mode 100644 index 0000000..a2aaabd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/ame.mid diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/bulb1.gif b/Master/Reference Architectures and Patterns/hjp5/examples/bulb1.gif Binary files differnew file mode 100644 index 0000000..98e152a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/bulb1.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/bulb2.gif b/Master/Reference Architectures and Patterns/hjp5/examples/bulb2.gif Binary files differnew file mode 100644 index 0000000..e11b903 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/bulb2.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/bulbico16.gif b/Master/Reference Architectures and Patterns/hjp5/examples/bulbico16.gif Binary files differnew file mode 100644 index 0000000..b7c66a0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/bulbico16.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/bulbico32.gif b/Master/Reference Architectures and Patterns/hjp5/examples/bulbico32.gif Binary files differnew file mode 100644 index 0000000..0888b68 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/bulbico32.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/chimes.au b/Master/Reference Architectures and Patterns/hjp5/examples/chimes.au Binary files differnew file mode 100644 index 0000000..c972351 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/chimes.au diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/clpbrd.inc b/Master/Reference Architectures and Patterns/hjp5/examples/clpbrd.inc new file mode 100644 index 0000000..94e2e53 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/clpbrd.inc @@ -0,0 +1,33 @@ +/* clpbrd.inc */
+
+public void actionPerformed(ActionEvent event)
+{
+ Clipboard clip = getToolkit().getSystemClipboard();
+ String cmd = event.getActionCommand();
+ if (cmd.equals("Kopieren")) {
+ String s = "Es ist " + System.currentTimeMillis() + "Uhr";
+ StringSelection cont = new StringSelection(s);
+ clip.setContents(cont, this);
+ } else if (cmd.equals("Einfuegen")) {
+ Transferable cont = clip.getContents(this);
+ if (cont == null) {
+ System.out.println("Zwischenablage ist leer");
+ } else {
+ try {
+ String s = (String) cont.getTransferData(
+ DataFlavor.stringFlavor
+ );
+ System.out.println(s);
+ } catch (Exception e) {
+ System.out.println(
+ "Zwischenablage enthält keinen Text"
+ );
+ }
+ }
+ }
+}
+
+public void lostOwnership(Clipboard clip, Transferable cont)
+{
+ System.out.println("Inhalt der Zwischenablage ersetzt");
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/demo/A.java b/Master/Reference Architectures and Patterns/hjp5/examples/demo/A.java new file mode 100644 index 0000000..5d2202a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/demo/A.java @@ -0,0 +1,9 @@ +package demo;
+
+public class A
+{
+ public void hello()
+ {
+ System.out.println("Hier ist A");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/demo/B.java b/Master/Reference Architectures and Patterns/hjp5/examples/demo/B.java new file mode 100644 index 0000000..1153b01 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/demo/B.java @@ -0,0 +1,9 @@ +package demo;
+
+public class B
+{
+ public void hello()
+ {
+ System.out.println("Hier ist B");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/demo/tools/C.java b/Master/Reference Architectures and Patterns/hjp5/examples/demo/tools/C.java new file mode 100644 index 0000000..b392740 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/demo/tools/C.java @@ -0,0 +1,9 @@ +package demo.tools;
+
+public class C
+{
+ public void hello()
+ {
+ System.out.println("Hier ist C");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/duke.gif b/Master/Reference Architectures and Patterns/hjp5/examples/duke.gif Binary files differnew file mode 100644 index 0000000..fb4ce3a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/duke.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/emptydb.mdb b/Master/Reference Architectures and Patterns/hjp5/examples/emptydb.mdb Binary files differnew file mode 100644 index 0000000..55fe90f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/emptydb.mdb diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/hello.au b/Master/Reference Architectures and Patterns/hjp5/examples/hello.au Binary files differnew file mode 100644 index 0000000..009121d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/hello.au diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/hello.jar b/Master/Reference Architectures and Patterns/hjp5/examples/hello.jar Binary files differnew file mode 100644 index 0000000..36665bc --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/hello.jar diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana1.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana1.gif Binary files differnew file mode 100644 index 0000000..dfe3c87 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana1.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana10.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana10.gif Binary files differnew file mode 100644 index 0000000..2977f88 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana10.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana11.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana11.gif Binary files differnew file mode 100644 index 0000000..646208b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana11.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana12.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana12.gif Binary files differnew file mode 100644 index 0000000..b248bcb --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana12.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana13.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana13.gif Binary files differnew file mode 100644 index 0000000..4ed4498 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana13.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana14.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana14.gif Binary files differnew file mode 100644 index 0000000..b779866 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana14.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana15.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana15.gif Binary files differnew file mode 100644 index 0000000..abb69dd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana15.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana16.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana16.gif Binary files differnew file mode 100644 index 0000000..4cf3de8 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana16.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana17.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana17.gif Binary files differnew file mode 100644 index 0000000..fc7364b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana17.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana18.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana18.gif Binary files differnew file mode 100644 index 0000000..d44912b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana18.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana19.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana19.gif Binary files differnew file mode 100644 index 0000000..5c6214c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana19.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana2.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana2.gif Binary files differnew file mode 100644 index 0000000..8566e46 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana2.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana20.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana20.gif Binary files differnew file mode 100644 index 0000000..ae99ccc --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana20.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana21.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana21.gif Binary files differnew file mode 100644 index 0000000..a1ec7fc --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana21.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana22.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana22.gif Binary files differnew file mode 100644 index 0000000..469e22f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana22.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana23.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana23.gif Binary files differnew file mode 100644 index 0000000..f73695a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana23.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana24.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana24.gif Binary files differnew file mode 100644 index 0000000..f1e289f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana24.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana25.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana25.gif Binary files differnew file mode 100644 index 0000000..adfa8c9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana25.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana26.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana26.gif Binary files differnew file mode 100644 index 0000000..55ab01f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana26.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana27.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana27.gif Binary files differnew file mode 100644 index 0000000..7913fa3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana27.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana28.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana28.gif Binary files differnew file mode 100644 index 0000000..190486e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana28.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana29.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana29.gif Binary files differnew file mode 100644 index 0000000..8315f2d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana29.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana3.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana3.gif Binary files differnew file mode 100644 index 0000000..82ad0db --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana3.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana30.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana30.gif Binary files differnew file mode 100644 index 0000000..d39eef0 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana30.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana4.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana4.gif Binary files differnew file mode 100644 index 0000000..79e73af --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana4.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana5.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana5.gif Binary files differnew file mode 100644 index 0000000..da62606 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana5.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana6.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana6.gif Binary files differnew file mode 100644 index 0000000..1f8e487 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana6.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana7.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana7.gif Binary files differnew file mode 100644 index 0000000..9e649ea --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana7.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana8.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana8.gif Binary files differnew file mode 100644 index 0000000..bc9b720 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana8.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/images/jana9.gif b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana9.gif Binary files differnew file mode 100644 index 0000000..e66a8a3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/images/jana9.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/japplet.html b/Master/Reference Architectures and Patterns/hjp5/examples/japplet.html new file mode 100644 index 0000000..88896ff --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/japplet.html @@ -0,0 +1,12 @@ +<html>
+<head><title>JAppletTest</title></head>
+
+<body>
+<h1>JAppletTest</h1>
+
+<applet code="JAppletTest.class" width=300 height=200>
+Hier steht das JAppletTest
+</applet>
+
+</body>
+</html>
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/lb1.ser b/Master/Reference Architectures and Patterns/hjp5/examples/lb1.ser Binary files differnew file mode 100644 index 0000000..e92238e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/lb1.ser diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/lock.gif b/Master/Reference Architectures and Patterns/hjp5/examples/lock.gif Binary files differnew file mode 100644 index 0000000..3220701 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/lock.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/manifest.txt b/Master/Reference Architectures and Patterns/hjp5/examples/manifest.txt new file mode 100644 index 0000000..307537b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/manifest.txt @@ -0,0 +1,11 @@ +Name: LightedPushButton.class
+Java-Bean: True
+
+Name: LightBulb.class
+Java-Bean: True
+
+Name: VetoSwitch.class
+Java-Bean: True
+
+Name: ButtonPanel.class
+Java-Bean: True
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/mine.gif b/Master/Reference Architectures and Patterns/hjp5/examples/mine.gif Binary files differnew file mode 100644 index 0000000..623d2f2 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/mine.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/persistence.xml b/Master/Reference Architectures and Patterns/hjp5/examples/persistence.xml new file mode 100644 index 0000000..235657e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/persistence.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!-- Persistenz Descriptor zur Konfiguration -->
+<persistence>
+
+ <!-- Hinterlegen eines symbolischen Namens -->
+ <persistence-unit name="persistenceExample"
+ transaction-type="RESOURCE_LOCAL">
+
+ <!-- Zu verwendende Implementierung -->
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+
+ <!-- Persistierbare Klassen -->
+ <class>Directory</class>
+
+ <!-- Konfiguration der Hibernate Implementierung -->
+ <properties>
+ <!-- Name des intern verwendeten JDBC-Treibers -->
+ <property name="hibernate.connection.driver_class"
+ value="org.hsqldb.jdbcDriver"/>
+
+ <!-- URL der zu verwendenden Datenbank -->
+ <property name="hibernate.connection.url"
+ value="jdbc:hsqldb:hsqldbtest"/>
+
+ <!-- SQL-Dialect, den Hibernate verwenden soll -->
+ <property name="hibernate.dialect"
+ value="org.hibernate.dialect.HSQLDialect"/>
+
+ <!-- Benutzername und Passwort; Standardwerte der HSQLDB -->
+ <property name="hibernate.connection.username" value="SA"/>
+ <property name="hibernate.connection.password" value=""/>
+
+ <!-- Flag, ob Tabellen automatisch erzeugt werden sollen -->
+ <property name="hibernate.hbm2ddl.auto" value="create"/>
+
+ <!-- Flag, ob SQL-Statements ausgegeben werden sollen -->
+ <property name="hibernate.show_sql" value="true"/>
+ </properties>
+ </persistence-unit>
+</persistence>
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/testicon.gif b/Master/Reference Architectures and Patterns/hjp5/examples/testicon.gif Binary files differnew file mode 100644 index 0000000..7909d6e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/testicon.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/thunder.au b/Master/Reference Architectures and Patterns/hjp5/examples/thunder.au Binary files differnew file mode 100644 index 0000000..1abf52f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/thunder.au diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/update1.inc b/Master/Reference Architectures and Patterns/hjp5/examples/update1.inc new file mode 100644 index 0000000..75edc2c --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/update1.inc @@ -0,0 +1,6 @@ +/* update1.inc */
+
+public void update(Graphics g)
+{
+ paint(g);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/update2.inc b/Master/Reference Architectures and Patterns/hjp5/examples/update2.inc new file mode 100644 index 0000000..e0a9379 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/update2.inc @@ -0,0 +1,26 @@ +/* update2.inc */
+
+public void update(Graphics g)
+{
+ //Double-Buffer initialisieren
+ if (dbImage == null) {
+ dbImage = createImage(
+ this.getSize().width,
+ this.getSize().height
+ );
+ dbGraphics = dbImage.getGraphics();
+ }
+ //Hintergrund löschen
+ dbGraphics.setColor(getBackground());
+ dbGraphics.fillRect(
+ 0,
+ 0,
+ this.getSize().width,
+ this.getSize().height
+ );
+ //Vordergrund zeichnen
+ dbGraphics.setColor(getForeground());
+ paint(dbGraphics);
+ //Offscreen anzeigen
+ g.drawImage(dbImage,0,0,this);
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/world.au b/Master/Reference Architectures and Patterns/hjp5/examples/world.au Binary files differnew file mode 100644 index 0000000..909cb1a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/world.au diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/wstest/BrowserClientThread.class b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/BrowserClientThread.class Binary files differnew file mode 100644 index 0000000..6ebc0ca --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/BrowserClientThread.class diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/wstest/ExperimentalWebServer.class b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/ExperimentalWebServer.class Binary files differnew file mode 100644 index 0000000..8792d6e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/ExperimentalWebServer.class diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/wstest/ExperimentalWebServer.java b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/ExperimentalWebServer.java new file mode 100644 index 0000000..b09d03b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/ExperimentalWebServer.java @@ -0,0 +1,241 @@ +/* ExperimentalWebServer.java */
+
+import java.io.*;
+import java.util.*;
+import java.net.*;
+
+/**
+ * Ein ganz einfacher Web-Server auf TCP und einem
+ * beliebigen Port. Der Server ist in der Lage,
+ * Seitenanforderungen lokal zu dem Verzeichnis,
+ * aus dem er gestartet wurde, zu bearbeiten. Wurde
+ * der Server z.B. im Verzeichnis c:\tmp gestartet, so
+ * würde eine Seitenanforderung
+ * http://localhost:80/test/index.html die Datei
+ * c:\tmp\test\index.html laden. CGIs, SSIs, Servlets
+ * oder ähnliches wird nicht unterstützt.
+ * <p>
+ * Die Dateitypen .htm, .html, .gif, .jpg und .jpeg werden
+ * erkannt und mit korrekten MIME-Headern übertragen, alle
+ * anderen Dateien werden als "application/octet-stream"
+ * übertragen. Jeder Request wird durch einen eigenen
+ * Client-Thread bearbeitet, nach Übertragung der Antwort
+ * schließt der Server den Socket. Antworten werden mit
+ * HTTP/1.0-Header gesendet.
+ */
+public class ExperimentalWebServer
+{
+ public static void main(String[] args)
+ {
+ if (args.length != 1) {
+ System.err.println(
+ "Usage: java ExperimentalWebServer <port>"
+ );
+ System.exit(1);
+ }
+ try {
+ int port = Integer.parseInt(args[0]);
+ System.out.println("Listening to port " + port);
+ int calls = 0;
+ ServerSocket httpd = new ServerSocket(port);
+ while (true) {
+ Socket socket = httpd.accept();
+ (new BrowserClientThread(++calls, socket)).start();
+ }
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
+
+/**
+ * Die Thread-Klasse für die Client-Verbindung.
+ */
+class BrowserClientThread
+extends Thread
+{
+ static final String[][] mimetypes = {
+ {"html", "text/html"},
+ {"htm", "text/html"},
+ {"txt", "text/plain"},
+ {"gif", "image/gif"},
+ {"jpg", "image/jpeg"},
+ {"jpeg", "image/jpeg"},
+ {"jnlp", "application/x-java-jnlp-file"}
+ };
+
+ private Socket socket;
+ private int id;
+ private PrintStream out;
+ private InputStream in;
+ private String cmd;
+ private String url;
+ private String httpversion;
+
+ /**
+ * Erzeugt einen neuen Client-Thread mit der angegebenen
+ * id und dem angegebenen Socket.
+ */
+ public BrowserClientThread(int id, Socket socket)
+ {
+ this.id = id;
+ this.socket = socket;
+ }
+
+ /**
+ * Hauptschleife für den Thread.
+ */
+ public void run()
+ {
+ try {
+ System.out.println(id + ": Incoming call...");
+ out = new PrintStream(socket.getOutputStream());
+ in = socket.getInputStream();
+ readRequest();
+ createResponse();
+ socket.close();
+ System.out.println(id + ": Closed.");
+ } catch (IOException e) {
+ System.out.println(id + ": " + e.toString());
+ System.out.println(id + ": Aborted.");
+ }
+ }
+
+ /**
+ * Liest den nächsten HTTP-Request vom Browser ein.
+ */
+ private void readRequest()
+ throws IOException
+ {
+ //Request-Zeilen lesen
+ Vector request = new Vector(10);
+ StringBuffer sb = new StringBuffer(100);
+ int c;
+ while ((c = in.read()) != -1) {
+ if (c == '\r') {
+ //ignore
+ } else if (c == '\n') { //line terminator
+ if (sb.length() <= 0) {
+ break;
+ } else {
+ request.addElement(sb);
+ sb = new StringBuffer(100);
+ }
+ } else {
+ sb.append((char)c);
+ }
+ }
+ //Request-Zeilen auf der Konsole ausgeben
+ Enumeration e = request.elements();
+ while (e.hasMoreElements()) {
+ sb = (StringBuffer)e.nextElement();
+ System.out.println("< " + sb.toString());
+ }
+ //Kommando, URL und HTTP-Version extrahieren
+ String s = ((StringBuffer)request.elementAt(0)).toString();
+ cmd = "";
+ url = "";
+ httpversion = "";
+ int pos = s.indexOf(' ');
+ if (pos != -1) {
+ cmd = s.substring(0, pos).toUpperCase();
+ s = s.substring(pos + 1);
+ //URL
+ pos = s.indexOf(' ');
+ if (pos != -1) {
+ url = s.substring(0, pos);
+ s = s.substring(pos + 1);
+ //HTTP-Version
+ pos = s.indexOf('\r');
+ if (pos != -1) {
+ httpversion = s.substring(0, pos);
+ } else {
+ httpversion = s;
+ }
+ } else {
+ url = s;
+ }
+ }
+ }
+
+ /**
+ * Request bearbeiten und Antwort erzeugen.
+ */
+ private void createResponse()
+ {
+ if (cmd.equals("GET") || cmd.equals("HEAD")) {
+ if (!url.startsWith("/")) {
+ httpError(400, "Bad Request");
+ } else {
+ //MIME-Typ aus Dateierweiterung bestimmen
+ String mimestring = "application/octet-stream";
+ for (int i = 0; i < mimetypes.length; ++i) {
+ if (url.endsWith(mimetypes[i][0])) {
+ mimestring = mimetypes[i][1];
+ break;
+ }
+ }
+ //URL in lokalen Dateinamen konvertieren
+ String fsep = System.getProperty("file.separator", "/");
+ StringBuffer sb = new StringBuffer(url.length());
+ for (int i = 1; i < url.length(); ++i) {
+ char c = url.charAt(i);
+ if (c == '/') {
+ sb.append(fsep);
+ } else {
+ sb.append(c);
+ }
+ }
+ try {
+ FileInputStream is = new FileInputStream(sb.toString());
+ //HTTP-Header senden
+ out.print("HTTP/1.0 200 OK\r\n");
+ System.out.println("> HTTP/1.0 200 OK");
+ out.print("Server: ExperimentalWebServer 0.5\r\n");
+ System.out.println(
+ "> Server: ExperimentalWebServer 0.5"
+ );
+ out.print("Content-type: " + mimestring + "\r\n\r\n");
+ System.out.println("> Content-type: " + mimestring);
+ if (cmd.equals("GET")) {
+ //Dateiinhalt senden
+ byte[] buf = new byte[256];
+ int len;
+ while ((len = is.read(buf)) != -1) {
+ out.write(buf, 0, len);
+ }
+ }
+ is.close();
+ } catch (FileNotFoundException e) {
+ httpError(404, "Error Reading File");
+ } catch (IOException e) {
+ httpError(404, "Not Found");
+ } catch (Exception e) {
+ httpError(404, "Unknown exception");
+ }
+ }
+ } else {
+ httpError(501, "Not implemented");
+ }
+ }
+
+ /**
+ * Eine Fehlerseite an den Browser senden.
+ */
+ private void httpError(int code, String description)
+ {
+ System.out.println("> ***" + code + ": " + description + "***");
+ out.print("HTTP/1.0 " + code + " " + description + "\r\n");
+ out.print("Content-type: text/html\r\n\r\n");
+ out.println("<html>");
+ out.println("<head>");
+ out.println("<title>ExperimentalWebServer-Error</title>");
+ out.println("</head>");
+ out.println("<body>");
+ out.println("<h1>HTTP/1.0 " + code + "</h1>");
+ out.println("<h3>" + description + "</h3>");
+ out.println("</body>");
+ out.println("</html>");
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/wstest/Listing3813.class b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/Listing3813.class Binary files differnew file mode 100644 index 0000000..8bf800a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/Listing3813.class diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/wstest/Listing3813.java b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/Listing3813.java new file mode 100644 index 0000000..94958e9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/Listing3813.java @@ -0,0 +1,83 @@ +/* Listing3813.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.tree.*;
+
+public class Listing3813
+extends JFrame
+implements ActionListener
+{
+ protected DefaultMutableTreeNode root;
+ protected DefaultTreeModel treeModel;
+ protected JTree tree;
+
+ public Listing3813()
+ {
+ super("JTree 3");
+ addWindowListener(new WindowClosingAdapter(true));
+ //JTree erzeugen und Einfachselektion aktivieren
+ root = new DefaultMutableTreeNode("Root");
+ treeModel = new DefaultTreeModel(root);
+ tree = new JTree(treeModel);
+ TreeSelectionModel tsm = new DefaultTreeSelectionModel();
+ tsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+ tree.setSelectionModel(tsm);
+ tree.setRootVisible(true);
+ //JTree einfügen
+ Container cp = getContentPane();
+ cp.add(new JScrollPane(tree), BorderLayout.CENTER);
+ //ButtonPanel
+ JPanel panel = new JPanel(new FlowLayout());
+ String[] buttons = new String[]{"AddChild", "Delete", "Change"};
+ for (int i = 0; i < buttons.length; ++i) {
+ JButton button = new JButton(buttons[i]);
+ button.addActionListener(this);
+ panel.add(button);
+ }
+ cp.add(panel, BorderLayout.SOUTH);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ TreePath tp = tree.getLeadSelectionPath();
+ if (tp != null) {
+ DefaultMutableTreeNode node;
+ node = (DefaultMutableTreeNode)tp.getLastPathComponent();
+ if (cmd.equals("AddChild")) {
+ DefaultMutableTreeNode child;
+ child = new DefaultMutableTreeNode("child");
+ treeModel.insertNodeInto(child, node, node.getChildCount());
+ TreeNode[] path = treeModel.getPathToRoot(node);
+ tree.expandPath(new TreePath(path));
+ } else if (cmd.equals("Delete")) {
+ if (node != root) {
+ TreeNode parent = node.getParent();
+ TreeNode[] path = treeModel.getPathToRoot(parent);
+ treeModel.removeNodeFromParent(node);
+ tree.setSelectionPath(new TreePath(path));
+ }
+ } else if (cmd.equals("Change")) {
+ String name = node.toString();
+ node.setUserObject(name + "C");
+ treeModel.nodeChanged(node);
+ }
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ String plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
+ UIManager.setLookAndFeel(plaf);
+ Listing3813 frame = new Listing3813();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 300);
+ frame.setVisible(true);
+ } catch (Exception e) {
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/wstest/WindowClosingAdapter.class b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/WindowClosingAdapter.class Binary files differnew file mode 100644 index 0000000..b1c3ae9 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/WindowClosingAdapter.class diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/wstest/WindowClosingAdapter.java b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/WindowClosingAdapter.java new file mode 100644 index 0000000..3dd14c8 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/WindowClosingAdapter.java @@ -0,0 +1,38 @@ +/* WindowClosingAdapter.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class WindowClosingAdapter
+extends WindowAdapter
+{
+ private boolean exitSystem;
+
+ /**
+ * Erzeugt einen WindowClosingAdapter zum Schliessen
+ * des Fensters. Ist exitSystem true, wird das komplette
+ * Programm beendet.
+ */
+ public WindowClosingAdapter(boolean exitSystem)
+ {
+ this.exitSystem = exitSystem;
+ }
+
+ /**
+ * Erzeugt einen WindowClosingAdapter zum Schliessen
+ * des Fensters. Das Programm wird nicht beendet.
+ */
+ public WindowClosingAdapter()
+ {
+ this(false);
+ }
+
+ public void windowClosing(WindowEvent event)
+ {
+ event.getWindow().setVisible(false);
+ event.getWindow().dispose();
+ if (exitSystem) {
+ System.exit(0);
+ }
+ }
+}
\ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.gif b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.gif Binary files differnew file mode 100644 index 0000000..7bc66aa --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.gif diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.html b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.html new file mode 100644 index 0000000..8b48cd3 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.html @@ -0,0 +1,15 @@ +<html>
+
+<head>
+<title>HJP3 WebStart Demo Application</title>
+</head>
+
+<body>
+
+<h2>HJP3 WebStart Demo Application</h2>
+
+<a href="wstest.jnlp">Anwendung laden/starten</a>
+
+</body>
+
+</html>
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.jar b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.jar Binary files differnew file mode 100644 index 0000000..adeba7a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.jar diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.jnlp b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.jnlp new file mode 100644 index 0000000..703ea3e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/wstest/wstest.jnlp @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?>
+
+<!-- JNLP File fuer HJP3 WebStart Demo-Applikation -->
+<jnlp codebase="http://localhost:7777/" href="wstest.jnlp">
+
+<information>
+ <title>HJP3 WebStart Demo Application</title>
+ <vendor>Guido Krueger</vendor>
+ <homepage href="http://www.javabuch.de"/>
+ <description>HJP3 WebStart Demo Application</description>
+ <icon href="wstest.gif"/>
+ <offline-allowed/>
+</information>
+
+<information locale="de">
+ <description>HJP3 WebStart Demo-Applikation</description>
+ <offline-allowed/>
+</information>
+
+<security>
+ <!-- <all-permissions/> -->
+</security>
+
+<resources>
+ <j2se version="1.3+"/>
+ <jar href="wstest.jar"/>
+</resources>
+
+<application-desc main-class="Listing3813"/>
+
+</jnlp>
\ No newline at end of file |
