-1
int club_num = 0;
private int angle = 90;
private int startX = 72;
private int startY = 329;
private double endX = startX + clublength * Math.sin(Math.toRadians(angle));
private double endY = startY + clublength * Math.cos(Math.toRadians(angle));
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.BLACK);
g.drawLine(startX, startY, (int)endX, (int)endY); //this is what i want to change
}
public class Keys extends KeyAdapter {
@Override
public void keyPressed(KeyEvent e){
if (e.getKeyCode() == KeyEvent.VK_LEFT){
club_num--; //ultimately changes endX and endY
if (club_num < 0)
club_num = club[0].length-1; //ultimately changes endX and endY
repaint();
}
else if (e.getKeyCode() == KeyEvent.VK_RIGHT){
club_num++; //ultimately changes endX and endY
if (club_num > club[0].length-1)
club_num = 0; //ultimately changes endX and endY
repaint();
}
}
}
, I 업데이트 된 변수 패러미터에 따라 변화하는 선 [g.drawLine(startX, startY, (int)endX, (int)endY)]
원하는의 paintComponent에서 변경된 변수를 칠하는 방법을 알아낼 수 없다 [endX and endY]
.I은 버튼을 누를 때 및 가변 값이 변경된 후에 <code>repaint()</code> 메소드가 호출