Hallo,
habe ein merkwürdiges Problem, dessen Lösung ich einfach nicht finde, so daß ich hoffe, hier kann mir jemand helfen.
Und zwar wird folgender Code anstandslos compiliert (beide Versionen), doch bei dem Teil mit der for-Schleife wird im Fenster nichts angezeigt.
public void paint(Graphics g) {
int i = 2;
g.drawRect(10, (8+i*25), 60, 20);
g.drawString("Thread "+i, 15, (22+i*25));
}
public void paint(Graphics g) {
for (int i = 0; i < this.threads; i++){
g.drawRect(10, (8+i*25), 60, 20);
g.drawString("Thread "+i, 15, (22+i*25));
}
}
threads ist eine int Variable, die der Klasse übergeben wird, in Zukunft soll mal ein array übergeben werden
der Konstruktor sieht so aus:
public class Monitor extends Canvas {
// Deklarationen
private Image image;
private int height;
private int width;
private int threads;
public Graphics g;
public Monitor(int threads){
this.threads = threads;
width = (int)EinfachesGUI.anzeige.getBounds().getWidth();
height = (int)EinfachesGUI.anzeige.getBounds().getHeight();
setSize( width, height );
}
Wahrscheinlich ist es ein Anfängerfehler, trotzdem würde ich mich über Hilfe sehr freuen.
Armalyte
habe ein merkwürdiges Problem, dessen Lösung ich einfach nicht finde, so daß ich hoffe, hier kann mir jemand helfen.
Und zwar wird folgender Code anstandslos compiliert (beide Versionen), doch bei dem Teil mit der for-Schleife wird im Fenster nichts angezeigt.
public void paint(Graphics g) {
int i = 2;
g.drawRect(10, (8+i*25), 60, 20);
g.drawString("Thread "+i, 15, (22+i*25));
}
public void paint(Graphics g) {
for (int i = 0; i < this.threads; i++){
g.drawRect(10, (8+i*25), 60, 20);
g.drawString("Thread "+i, 15, (22+i*25));
}
}
threads ist eine int Variable, die der Klasse übergeben wird, in Zukunft soll mal ein array übergeben werden
der Konstruktor sieht so aus:
public class Monitor extends Canvas {
// Deklarationen
private Image image;
private int height;
private int width;
private int threads;
public Graphics g;
public Monitor(int threads){
this.threads = threads;
width = (int)EinfachesGUI.anzeige.getBounds().getWidth();
height = (int)EinfachesGUI.anzeige.getBounds().getHeight();
setSize( width, height );
}
Wahrscheinlich ist es ein Anfängerfehler, trotzdem würde ich mich über Hilfe sehr freuen.
Armalyte