import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class Frame extends JFrame { private MachineState machine; public Frame( Machine machine ) { super("Getränkeautomat"); this.machine = machine; setLayout(new GridLayout(5, 2)); JButton insert10Cent = new JButton("10 Cent"); insert10Cent.addActionListener(new ActionListener() { public void actionPerformed( ActionEvent e ) { Frame.this.machine.insertCoin(10); } }); add(insert10Cent); JButton insert20Cent = new JButton("20 Cent"); insert20Cent.addActionListener(new ActionListener() { public void actionPerformed( ActionEvent e ) { Frame.this.machine.insertCoin(20); } }); add(insert20Cent); JButton insert50Cent = new JButton("50 Cent"); insert50Cent.addActionListener(new ActionListener() { public void actionPerformed( ActionEvent e ) { Frame.this.machine.insertCoin(50); } }); add(insert50Cent); JButton insert100Cent = new JButton("100 Cent"); insert100Cent.addActionListener(new ActionListener() { public void actionPerformed( ActionEvent e ) { Frame.this.machine.insertCoin(100); } }); add(insert100Cent); JButton selectCoffee = new JButton("Kaffee"); selectCoffee.addActionListener(new ActionListener() { public void actionPerformed( ActionEvent e ) { Frame.this.machine.selectProduct("Kaffee"); } }); add(selectCoffee); JButton selectTea = new JButton("Tee"); selectTea.addActionListener(new ActionListener() { public void actionPerformed( ActionEvent e ) { Frame.this.machine.selectProduct("Tee"); } }); add(selectTea); JButton selectChocolate = new JButton("Kakao"); selectChocolate.addActionListener(new ActionListener() { public void actionPerformed( ActionEvent e ) { Frame.this.machine.selectProduct("Kakao"); } }); add(selectChocolate); JButton abort = new JButton("Annulieren"); abort.addActionListener(new ActionListener() { public void actionPerformed( ActionEvent e ) { Frame.this.machine.abort(); } }); abort.setBackground(Color.RED); add(abort); JButton draw = new JButton("Zapfen"); draw.addActionListener(new ActionListener() { public void actionPerformed( ActionEvent e ) { Frame.this.machine.draw(); } }); draw.setBackground(Color.GREEN); add(draw); JButton timeout = new JButton("Timeout"); timeout.addActionListener(new ActionListener() { public void actionPerformed( ActionEvent e ) { Frame.this.machine.timeout(); } }); timeout.setBackground(Color.RED); add(timeout); pack(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } ///// public static void main( String[] args ) { new Frame(new Machine()).setVisible(true); } }