Hallo! Ich programmiere momentan beim JavaEditor das Sieb des Erasosthenes. Das Programm läuft soweit, doch jetzt möchte ich noch am unteren Fensterrand stehen haben was gerade passiert. Also wenn gerade die 2 durchläuft, soll unten stehen: "Alle durch 2 teilbaren Zahlen werden rot markiert."
Das habe ich bisher:
import java.awt.; import java.awt.event.;
public class TestGL extends Frame { private Label[] cell = new Label[101]; private int primzahl;
public static void main(String[] args) { TestGL window = new TestGL("Test"); window.setVisible(true); }
public TestGL(String title) { super(title); addWindowListener(new WindowListener()); setSize(400, 400); setResizable(false);
setLayout(new GridLayout(10, 10, 0, 0));
for (int zahl = 1; zahl <= 100; zahl++) {
cell[zahl] = new Label("" + zahl);
if ((zahl % 2) == 0) {
cell[zahl].setBackground(Color.red);
} else {
cell[zahl].setBackground(Color.yellow);
}
add(cell[zahl]);
}
setVisible(true);
repaint();
cell[1].setBackground(Color.red);
repaint();
primzahl = 2;
cell[primzahl].setBackground(Color.green);
repaint();
try {
Thread.sleep(3000);
} catch(InterruptedException e) {
} // end of try
for (int zahl = primzahl * primzahl; zahl <= 100; zahl = zahl + primzahl) {
cell[zahl].setBackground(Color.red);
} // end of for
primzahl = 3;
while (primzahl <= 10) {
if (cell[primzahl].getBackground() == Color.yellow) {
repaint();
try {
Thread.sleep(3000);
} catch(InterruptedException e) {
} // end of try
cell[primzahl].setBackground(Color.green);
for (int zahl = primzahl * primzahl; zahl <= 100;
zahl = zahl + primzahl) {
cell[zahl].setBackground(Color.blue);
repaint();
try {
Thread.sleep(300);
} catch(InterruptedException e) {
} // end of try
cell[zahl].setBackground(Color.red);
} // end of for
}
primzahl = primzahl + 2;
} // end of while
Panel description = new Panel();
Panel description.setLayout(5,5);
} }
class WindowListener extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } }