Eingabe tätigen bevor Graphics g Fenster öffnet

Hallo1234

Bekanntes Mitglied
Hallo noch mal, ein neues Problem ist aufgetaucht. Der vom Nutzer eingegebene Barcode soll mit Graphics g gezeichnet werden. Jetzt ist es aber so, dass sich die Zeichenfläche schon vor der Nutzereingabe öffnet und deswegen nichts gezeichnet werden kann. Wie kann ich das beheben?
Hier sind alle Klassen dazu:
[CODE lang="java" title="Barcode"]import java.awt.*;
import java.util.Scanner;
public class Barcode {

public void zeichneBarcode(Graphics g) {
Scanner s = new Scanner(System.in);

System.out.println("Geben Sie einen 12-stelligen Code ein: ");
String barcode = s.next();

for(int i=0; i<=6; i++) {
if(barcode.charAt(i)==0) {

g.setColor(Color.white);
for(int j=1; j<=3; j++) {
g.drawLine(50*j,50*j,50*j,200*j);
}

g.setColor(Color.black);
for(int j=1; j<=2; j++) {

}

}else if(barcode.charAt(i)==1) {
g.setColor(Color.white);
}
//das ist noch nicht fertig, deshalb einfach nicht beachten.
}
}
}
[/CODE]
[CODE lang="java" title="Painting"]import javax.swing.JPanel;
import java.awt.*;

public class Painting extends JPanel{

//ATTRIBUTE

private Barcode barcode;
public Painting(Frame f){
this.barcode = new Barcode();
}

public void paintComponent(Graphics g) {

super.paintComponent(g);
this.barcode.zeichneBarcode(g);

}


}
[/CODE]
[CODE lang="java" title="BarcodeMasterPro"]public class BarcodeMasterPro {

public static void main(String[] args) {
new GUI();
}
}[/CODE]
[CODE lang="java" title="GUI"]public class GUI {

private Frame f;
private Painting painting;

public GUI() {
this.f = new Frame("BarcodeMasterPro", -1, -1, 1000, 800);
this.painting = new Painting(this.f);
this.f.getContentPane().add(this.painting);
this.f.setupFrame();
}
}[/CODE]
[CODE lang="java" title="Frame"]import javax.swing.JFrame;

public class Frame extends JFrame{

private String title;
private int x;
private int y;
private int width;
private int height;

public Frame(String title, int x, int y, int width, int height){
this.title = title;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public void setupFrame() {
setTitle(this.title);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(this.width, this.height);
if(this.x==-1 && this.y == -1) {
setLocationRelativeTo(null); //centers the jFrame on the screen
}else {
setLocation(this.x, this.y);
}
setVisible(true);
}

public String getTitle() {
return title;
}

public int getX() {
return x;
}

public int getY() {
return y;
}

public int getWidth() {
return width;
}

public int getHeight() {
return height;
}

}
[/CODE]
Vielen Dank
 
[CODE lang="java" title="Barcode"]public class Barcode {
private String barCode;
public Barcode( String barcode ) throws IllegalArgumentException{
if( !checkBarcode( barcode ) )
throw new IllegalArgumentException("Invalid Barcode!");
this.barcode = barcode;
}
private boolean checkBarcode( String barcode){
//TODO
}

public void draw(Graphics g) {
//TODO
}
}[/CODE]
 
[CODE lang="java" title="Eingabe"]import java.awt.*;
import java.util.Scanner;
public class Eingabe {

public void eingabeBarcode() {
Scanner s = new Scanner(System.in);

System.out.println("Geben Sie einen 12-stelligen Code ein: ");
String barcode = s.next();
}
}
[/CODE]
[CODE lang="java" title="Barcode"]import java.awt.*;

public class Barcode {

public void zeichneBarcode(Graphics g) {

Eingabe e = new Eingabe();
e.eingabeBarcode();
for(int i=0; i<=6; i++) {
if(barcode.charAt(i)==0) { // barcode wird nicht mehr erkannt

g.setColor(Color.white);
for(int j=1; j<=3; j++) {
g.drawLine(50*j,50*j,50*j,200*j);
}

g.setColor(Color.black);
for(int j=1; j<=2; j++) {

}

}else if(barcode.charAt(i)==1) {
g.setColor(Color.white);
}
//das ist noch nicht fertig, deshalb einfach nicht beachten.
}
}
}
[/CODE]

Jetzt wird barcode in der Klasse Barcode nicht mehr erkannt : (
 

Zurück
Oben