import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*; import javax.swing.text.html.*; import java.io.*; import java.net.*; public class BridgeBsp1 extends JFrame implements ActionListener { public BridgeBsp1() { setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); setGUI(); } private JButton createButton(String caption, String command) { JButton bn = new JButton(caption); bn.setFont( new Font("Arial", Font.BOLD,18) ); bn.setActionCommand(command); bn.addActionListener(this); return bn; } private void setGUI() { setSize(600, 630); setLocation(20,20); setTitle("Test Bridge Beispiel 1"); JPanel pnButton = new JPanel(); pnButton.setLayout( new FlowLayout() ); pnButton.add( createButton("Test1","Test1") ); pnButton.add( createButton("Abbruch","Abbruch") ); this.getContentPane().setLayout( new BorderLayout() ); JTextArea editor = Editor.getInstance(); this.getContentPane().add( new JScrollPane(editor), BorderLayout.CENTER); this.getContentPane().add( pnButton, BorderLayout.SOUTH ); } // setGUI public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("Test1") ) { test1(); } if (cmd.equals("Abbruch") ) { setVisible(false); dispose(); // System.exit(0); } } private void test1() { Editor.getInstance().setText(""); } public static void main(String[] args) { BridgeBsp1 frame = new BridgeBsp1(); frame.setVisible(true); } } // PrintHashMap class Editor { static private JTextArea editor = new MyJTextArea(); // wird nicht automatisch aufgerufen private Editor() { editor.setFont( new Font("Arial", Font.BOLD,28) ); System.out.println("editor"); } public static JTextArea getInstance() { return editor; } } class MyJTextArea extends JTextArea{ public MyJTextArea() { setFont( new Font("Arial", Font.BOLD,28) ); } } public class Vehicle { } public class BigBus extends Vehicle { } public class SmallCar extends Vehicle { } public interface IEngine { } public class BigEngine implements IEngine { } public class SmallEngine implements IEngine { }