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 Facade_Bsp2_Kubik extends JFrame implements ActionListener { public Facade_Bsp2_Kubik() { setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); setGUI(); setVisible(true); } 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 Adapter"); JPanel pnButton = new JPanel(); pnButton.setLayout( new FlowLayout() ); pnButton.add( createButton("Test1","Test1") ); pnButton.add( createButton("Test2","Test2") ); 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("Test2") ) { test2(); } if (cmd.equals("Abbruch") ) { setVisible(false); dispose(); // System.exit(0); } } private void test1() { JTextArea editor = Editor.getInstance(); editor.setText("Ergebnisse:"); // hier fehlt Code } private void test2() { // hier fehlt Code } public static void main(String[] args) { new Bsp2_Kubik(); } } // Facade_Bsp2_Kubik 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) ); } } class Class1 { public int doSomethingComplicated(int x) { return x * x * x; } } class Class2 { public int doAnotherThing(Class1 class1, int x) { return 2 * class1.doSomethingComplicated(x); } } class Class3 { public int doMoreStuff(Class1 class1, Class2 class2, int x) { return class1.doSomethingComplicated(x) * class2.doAnotherThing(class1, x); } } class Facade { public int cubeX(int x) { return 0l; } public int cubeXTimes2(int x) { return 0; } public int xToSixthPowerTimes2(int x) { return 0; } }