Hallo Leute,
Für den Informatikunterricht soll ich einen Spielautomaten bauen.
Dafür benutzt dieser einen Zufallsgenerator, wenn nun 2 Zahlen bzw. 3 Zahlen in dem Textfeldern übereinstimmen, soll ein Gewinn zum Guthaben hinzugefügt werden, bzw. bei 1 gleichen Feld etwas abgezogen. Jetzt hatte ich geplannt wenn ich start drücke werden die Textfelder verdeckt. Wenn man jetzt auf die stopp buttons klickt wird das Feld wieder aufgedeckt. Wenn alle Felder sichtbar sind soll der Computer überprüfen, ob es mehrere gleiche gibt. Wenn ja soll die Methode auswertung() eingesetzt werden und das Guthaben entsprechend verändert werden. Hier mein Quelltext und bitte nicht zuviel Fachsprache bin im ersten Halbjahr Informatik in der 10 Klasse :
import java.applet.Applet;
import java.awt.*;
import java.util.Random;
import java.awt.event.*;
public class Bandit extends Applet
{
// ===== Attribute =====
int zufall;
Label info;
TextField txt,txt1,txt2,txt3;
Button stopp1,stopp2,stopp3,start;
static Random zufallsgenerator = new Random();
// ===== Methoden =====//Buttons bzw. Oberfläche
public void init()
{
setLayout(null);
setBackground(Color.LIGHT_GRAY);
info = new Label("Guthaben");
info.setBounds(40,20,120,40);
add(info);
txt = new TextField();
txt.setText("2000"+'€');
String t = txt.getText();
int zahl = Integer.parseInt(t);
txt.setBounds(160,20,60,40);
txt.setEditable(false);
add(txt);
info.setFont(new Font("TimesRoman", Font.BOLD, 1

);
info.setBackground(Color.DARK_GRAY);
info.setForeground(Color.RED);
txt1 = new TextField();
txt1.setBounds(40,100,60,60);
txt1.setFont(new Font("TimesRoman", Font.BOLD, 4

);
txt1.setBackground(new Color(16762880));
txt1.setEditable(false);
txt1.setText("*");
String s = txt1.getText();
add(txt1);
txt2 = new TextField();
txt2.setBounds(140,100,60,60);
txt2.setFont(new Font("TimesRoman", Font.BOLD, 4

);
txt2.setBackground(new Color(16762880));
txt2.setEditable(false);
txt2.setText("*");
add(txt2);
txt3 = new TextField();
txt3.setBounds(240,100,60,60);
txt3.setFont(new Font("TimesRoman", Font.BOLD, 4

);
txt3.setBackground(new Color(16762880));
txt3.setEditable(false);
txt3.setText("*");
add(txt3);
stopp1 = new Button("Stopp");
stopp1.setBounds(40,160,60,60);
add(stopp1);
stopp1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int zufall = 1+zufallsgenerator.nextInt(9);
txt1.setText(zufall+"");
txt1.setVisible(true);
if (txt1.isVisible()==true && txt2.isVisible()==true && txt3.isVisible()==true)
auswertung();
}
});
stopp2 = new Button("Stopp");
stopp2.setBounds(140,160,60,60);
add(stopp2);
stopp2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int zufall = 1+zufallsgenerator.nextInt(9);
txt2.setText(zufall+"");
txt2.setVisible(true);
if (txt1.isVisible()==true && txt2.isVisible()==true && txt3.isVisible()==true)
auswertung();
}
});
stopp3 = new Button("Stopp");
stopp3.setBounds(240,160,60,60);
add(stopp3);
stopp3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int zufall = 1+zufallsgenerator.nextInt(9);
txt3.setText(zufall+"");
txt3.setVisible(true);
if (txt1.isVisible()==true && txt2.isVisible()==true && txt3.isVisible()==true)
auswertung();
}
});
start = new Button("START");
start.setBounds(140,240,60,60);
add(start);
start.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (txt1.isVisible()==true)
txt1.setVisible(false);
if (txt2.isVisible()==true)
txt2.setVisible(false);
if (txt3.isVisible()==true)
txt3.setVisible(false);
}
});
}
public void auswertung()
{
}
//Attribute initalisieren
public void start()
{
}
public void update(Graphics g)
{
paint(g);
}
//Zeichenaktionen
public void paint(Graphics g)
{
}
}
Danke schonmal