i followed exactly the code you suggested to me earlier
this is the complete code of my bar
sorry for the half of the code is in the language of my country.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Bidang pesawat sederhana tuas.
*
* @author (Sapta Hadi Kesuma)
*/
public class BidangTuas extends Actor
{
GreenfootImage baseImage;
private ChangeButton panjangInfo;
private ChangeButton lenganBebanInfo;
private ChangeButton lenganKuasaInfo;
private double panjang_tuas;
private double lengan_beban;
private double lengan_kuasa;
// private Beban beban;
private TitikTumpu fulkrum;
private int centerX,fulcrumX;
// boolean
/**
* Act - do whatever the BidangTuas wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
this.setAllValues();
//this.balance();
if(fulcrumX != fulkrum.getX()){
this.updateImage();
}
// turn(1);
}
public BidangTuas(ChangeButton panjangInfo,ChangeButton lenganBebanInfo, ChangeButton lenganKuasaInfo,TitikTumpu fulkrum){
this.panjangInfo = panjangInfo;
this.lenganBebanInfo = lenganBebanInfo;
this.lenganKuasaInfo = lenganKuasaInfo;
this.fulkrum = fulkrum;
// this.beban = beban;
}
public void addedToWorld(World w){
setImage("bidang.png");
// setImage(new GreenfootImage(1,1));//transparent image
this.fulcrumX = this.fulkrum.getX();
this.centerX = this.fulcrumX;
this.baseImage = this.getImage();
}
public void updateImage(){
//this.resetPosition();
int xOffset = centerX-fulkrum.getX();
GreenfootImage img = new GreenfootImage(baseImage.getWidth()+2*(int)Math.abs(xOffset),baseImage.getHeight());
img.drawImage(baseImage,(img.getWidth()-baseImage.getWidth())/2+xOffset,0);
this.setImage(img);
this.setLocation(fulkrum.getX(),this.getY());
}
public void setAllValues(){
this.panjang_tuas = this.panjangInfo.getNilai();
this.lengan_beban = this.lenganBebanInfo.getNilai();
this.lengan_kuasa = this.lenganKuasaInfo.getNilai();
}
public double getPanjangTuas(){
return this.panjang_tuas;
}
public double getLenganBeban(){
return this.lengan_beban;
}
public double getLenganKuasa(){
return this.lengan_kuasa;
}
}
