Good day, in other for me to get better and create more desired code. i would like to find out if the following situation is bad or acceptable.
I am creating an animation that gets triggered by two buttons. one on the left of a jpanel and the other on the right. depending on which button is pressed, the animation starts from the button position. Now it can be quite some work working out the different calculations with a lot of internal if and else statements(to know which button is clicked)on the Method that handles the animation(i have done so).
so am asking, if i clone the method and modify it to be suitable for one button (so each button calls a different method) which saves a lot of hassle, is that good or bad practise?
like this:
private void moveImage(){
if(xpos < imagewidth && ypos < imageheight) {
if(buttonA){
image.setX(image.getX() - xmove);
} else {
image.setX(image.getX() + xmove);
}
image.setY(image.getY() + ymove);
}
//other codes here
}
or i could do this for button A and the same for button B:
private void moveImageA(){
if(xpos < imagewidth && ypos < imageheight) {
image.setX(image.getX() - xmove);
image.setY(image.getY() + ymove);
}
//other codes here
}