Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class GUI extends JFrame implements ActionListener
{
private JTextField betrag;
private JButton aufladen;
private JLabel guthaben;
private JButton spielen;
private JLabel hgrund;
private JLabel wliste;
private JLabel d1;
private JLabel d2;
private JLabel d3;
private JLabel e1;
private JLabel e2;
private JLabel e3;
private JLabel f1;
private JLabel f2;
private JLabel f3;
private JLabel g1;
private JLabel g2;
private JLabel g3;
private Automat automat;
public GUI()
{
super("Spongebob-Slot");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(1000, 850);
setLocation(10, 10);
setLayout(null);
automat = new Automat();
betrag = new JTextField("");
betrag.setBounds(260, 650, 100, 50);
betrag.addActionListener(this);
add(betrag);
aufladen = new JButton("Aufladen");
aufladen.setBounds(260, 710, 100, 50);
add(aufladen);
guthaben = new JLabel(automat.getGeldstand()+" E");
guthaben.setBounds(380, 650, 100, 50);
add(guthaben);
spielen = new JButton("Spielen");
spielen.setBounds(380, 710, 100, 50);
spielen.addActionListener(this);
add(spielen);
wliste = new JLabel(new ImageIcon("werteliste.jpg"));
wliste.setBounds(0, 0, 250, 700);
add(wliste);
d1 = new JLabel(new ImageIcon("Automat.a1.gif"));
d1.setBounds(302, 1, 200, 200);
add(d1);
d2 = new JLabel(new ImageIcon("Automat.a2.gif"));
d2.setBounds(302, 202, 200, 200);
add(d2);
d3 = new JLabel(new ImageIcon("Automat.a3.gif"));
d3.setBounds(302, 403, 200, 200);
add(d3);
e1 = new JLabel(new ImageIcon("Automat.b1.gif"));
e1.setBounds(503, 1, 200, 200);
add(e1);
e2 = new JLabel(new ImageIcon("Automat.b2.gif"));
e2.setBounds(503, 202, 200, 200);
add(e2);
e3 = new JLabel(new ImageIcon("Automat.b3.gif"));
e3.setBounds(503, 403, 200, 200);
add(e3);
f1 = new JLabel(new ImageIcon("automat.c1.gif"));
f1.setBounds(704, 1, 200, 200);
add(f1);
f2 = new JLabel(new ImageIcon("automat.c2.gif"));
f2.setBounds(704, 202, 200, 200);
add(f2);
f3 = new JLabel(new ImageIcon("Automat.c3.gif"));
f3.setBounds(704, 403, 200, 200);
add(f3);
hgrund = new JLabel(new ImageIcon("hgrund.gif"));
hgrund.setBounds(250, 0, 700, 610);
add(hgrund);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
Object objekt = e.getSource();
if (objekt == aufladen){
automat.spielen();
guthaben.setText(automat.getGeldstand()+ " E");
}
if (objekt == aufladen){
double geld = Double.parseDouble(betrag.getText());
automat.geldAufladen(geld);
guthaben.setText(automat.getGeldstand()+ " E");
}
}
}