Hallo Leute,
bin neu hier im Forum weil ich mal ganz dringend eure Hilfe brauche.
Ich muss für die Schule einen Lottozahlen Generator schreiben, aber in einer Form Datei. Ich hab das Programm zum laufen gebracht per Konsole, jetzt will ichs halt in ne Form packen aber ich scheiter daran die generierte Zufallszahl per Button in das Text Label zu schreiben.
Hier einmal mein Quelltext:
Bei dem Rot markierten zeigt er mir immer einen Fehler an, keine Ahnung warum.
Wäre super nett wenn mir da jemand helfen könnte.
Hier nochmal mein Quellcode des Konsolenprogramms:
Schonmal Danke im vorraus
Mit freundlichen Grüßen
bin neu hier im Forum weil ich mal ganz dringend eure Hilfe brauche.
Ich muss für die Schule einen Lottozahlen Generator schreiben, aber in einer Form Datei. Ich hab das Programm zum laufen gebracht per Konsole, jetzt will ichs halt in ne Form packen aber ich scheiter daran die generierte Zufallszahl per Button in das Text Label zu schreiben.
Hier einmal mein Quelltext:
Code:
import java.awt.*;
import java.awt.event.*;
/**
*
* Beschreibung
*
* @version 1.0 vom 31.03.2011
* @author
*/
public class Lotto_frame_version extends Frame {
// Anfang Attribute
private Label label1 = new Label();
private Button button1 = new Button();
private Button button2 = new Button();
private Label label2 = new Label();
private TextField textField1 = new TextField();
int zz = 0;
int [] lz = new int[8];
int n = 0;
boolean doppelt = false;
// Ende Attribute
public Lotto_frame_version(String title) {
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) { dispose(); }
});
int frameWidth = 300;
int frameHeight = 300;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
Panel cp = new Panel(null);
add(cp);
// Anfang Komponenten
label1.setBounds(56, 8, 186, 24);
label1.setText("Lottozahlen-Generator");
label1.setFont(new Font("MS Sans Serif", Font.PLAIN, 18));
cp.add(label1);
button1.setBounds(16, 48, 75, 25);
button1.setLabel("Ziehung");
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button1_ActionPerformed(evt);
}
});
cp.add(button1);
button2.setBounds(16, 216, 75, 25);
button2.setLabel("Löschen");
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button2_ActionPerformed(evt);
}
});
cp.add(button2);
label2.setBounds(24, 88, 78, 20);
label2.setText("Zusatzzahl");
label2.setFont(new Font("MS Sans Serif", Font.PLAIN, 15));
cp.add(label2);
textField1.setBounds(112, 48, 161, 24);
textField1.setText("");
textField1.setEditable(false);
cp.add(textField1);
// Ende Komponenten
setResizable(false);
setVisible(true);
}
// Anfang Methoden
public void button1_ActionPerformed(ActionEvent evt) {
while (n <= 7) { // Zufallszahlen erzeugen
zz = (int)(Math.random() * 100);
if ((zz >= 1) && (zz <= 49)) {
doppelt = false;
for (int i = 0;i <= n;i++) {
if (lz[i] == zz) {
doppelt = true ;
}
}
if (doppelt == false) {
lz[n] = zz;
n ++;
}
} // Zufallszahlen erzeugen Ende
}
textField1.setText(zz);
}
public void button2_ActionPerformed(ActionEvent evt) {
// TODO hier Quelltext einfügen
}
// Ende Methoden
public static void main(String[] args) {
new Lotto_frame_version("Lotto_frame_version");
}
}
Bei dem Rot markierten zeigt er mir immer einen Fehler an, keine Ahnung warum.
Wäre super nett wenn mir da jemand helfen könnte.
Hier nochmal mein Quellcode des Konsolenprogramms:
Code:
public class lotto2 {
public static void main(String[] args) {
int zz = 0;
int [] lz = new int[8];
int n = 0;
boolean doppelt = false;
boolean tauschen = true;
int tmp = 0;
while (n <= 7) { // Zufallszahlen erzeugen
zz = (int)(Math.random() * 100);
if ((zz >= 1) && (zz <= 49)) {
doppelt = false;
for (int i = 0;i <= n;i++) {
if (lz[i] == zz) {
doppelt = true ;
}
}
if (doppelt == false) {
lz[n] = zz;
n ++;
}
} // Zufallszahlen erzeugen Ende
}
while (tauschen == true) { // Zufallszahlen sortieren; bis auf Zusatzzahl
tauschen = false;
for (int i = 0;i < 5 ;i++ ) {
if (lz[i] > lz[i+1]) {
tmp = lz[i + 1];
lz[i + 1] = lz[i];
lz[i] = tmp;
tauschen = true;
}
}
} // Zufallszahlen sortieren Ende
// Ausgabe der Zufallszahlen
for (int i = 0; i < 6; i++){
System.out.println(lz[i]);
}
System.out.println();
System.out.println(lz[6]);
}
}
Schonmal Danke im vorraus

Mit freundlichen Grüßen