import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Game extends JFrame implements ActionListener { Slogan slogan; SloganList sloganList; JButton[] buttons = new JButton [30]; JPanel but = new JPanel(); JLabel textZeile = new JLabel(); Gallows gallows = new Gallows(); public Game() { for (int i=0; i<26; i++) { buttons[i] = new JButton(""+ (char)('A'+i)); } buttons[26] = new JButton("Ä"); buttons[27] = new JButton("Ö"); buttons[28] = new JButton("Ü"); buttons[29] = new JButton("ß"); for(int i=0; i<=29; i++){ but.add(buttons[i]); } but.setLayout(new GridLayout(2,15)); getContentPane().add(but,BorderLayout.SOUTH); getContentPane().add(gallows,BorderLayout.NORTH); getContentPane().add(textZeile,BorderLayout.CENTER); for(int i=0;i<=29;i++) { buttons[i].addActionListener(this); } SloganList sl = new SloganList( SloganList.FILENAME ); slogan = new Slogan(sl.randomSlogan()); textZeile.setText(slogan.getSlogan()); } public void actionPerformed(ActionEvent e){ JButton b = (JButton)(e.getSource()); char c = b.getText().toLowerCase().charAt(0); if (slogan.addLetter(c) == false) { gallows.addError(); } textZeile.setText(slogan.getSlogan()); repaint(); } public static void main (String args[]) { Game gewinnspiel = new Game(); gewinnspiel.pack(); gewinnspiel.setVisible(true); } }