私はJavaを初めて使いました。私は学校のプロジェクトに取り組んでいます。マトリックスの移動方法
このプロジェクトでは、KeyListenerを使用して行列を作成する必要があります。
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));
}
この部分は行列を出力しますが、それは良い位置にないと私はそれを移動したい: 私はそうのようにそれを作りました。
誰もが任意のアイデアを持っていますか?
どうすれば移動できますか?あなたは、このコード行を変更する必要があります
'グラフィックス#drawString(String、int、int)' int値はx/yです... y値を変更してみてください – MadProgrammer