Ich bin neu in Java, und ich arbeite mit einem Schulprojekt.Wie verschiebe ich eine Matrix
In diesem Projekt muss ich eine Matrix mit einem KeyListener erstellen. Ich habe es etwa so:
if (!(e.getKeyChar()>='0' && e.getKeyChar()<='9' || e.getKeyChar()=='-' || e.getKeyCode()==10)) {
if(!(e.getKeyChar() == 'w' || e.getKeyChar() == 'b')){
JOptionPane.showMessageDialog(lince, "Not Allowed", "Fatal Error", JOptionPane.ERROR_MESSAGE);
}
}else{
if(e.getKeyCode()==10){
try{
MatrixI[i][j]=Integer.parseInt(Posicion);
j++;
Posicion = "";
if (j== 4){
i++;
j=0;
}if (i==5){
if (!(i >= 6)){
JOptionPane.showMessageDialog(lince, "You cannot add more numbers", "Not Allowed!!!", JOptionPane.ERROR_MESSAGE);
contar();
}
}
}catch(ArrayIndexOutOfBoundsException ex){
JOptionPane.showMessageDialog(lince, "You cannot add more numbers", "Not Allowed!!!", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
catch(NumberFormatException ex){
JOptionPane.showMessageDialog(lince, "Just write a number", "Not Allowed!!!", JOptionPane.ERROR_MESSAGE);
}
}else{
Posicion=Posicion+e.getKeyChar();
this.escribe(lince.getGraphics());
}
}
public void escribe(Graphics g){
g.setColor(Color.red);
g.setFont(new Font("Arial", Font.CENTER_BASELINE,12));
g.drawString(Posicion, 30+((1+j)*50),((1+i)*35));
}
Dieser Teil druckt die Matrix, aber es ist nicht in einer guten Position, und ich möchte es bewegen.
Hat jemand eine Idee?
Wie kann ich es bewegen?
'Grafik # drawString (String, int, int)' wo die 'int' Werte x/y sind ... versuche den' y' Wert zu ändern – MadProgrammer