java - Changing the colour of energy bars depending on their values? -
i created method check value in progress bar. works expected when decreasing, i.e. turns red, yellow , orange. when increase value colour doesn't update. when it's below 25 , turns red, remains colour when increase value of energy bar. doing wrong here? in advance.
public void checkenergybar(jprogressbar energybar){ if(energybar.getvalue()<25){ energybar.setforeground(color.red); }else if(energybar.getvalue()<51){ energybar.setforeground(color.yellow); }else if(energybar.getvalue()<76){ energybar.setforeground(color.orange); }else if(energybar.getvalue()<101){ energybar.setforeground(color.green); } energybar.repaint(); } i made these changes, , still no joy.
public void checkenergybar(jprogressbar energybar){ if(getenergy()<26 ){ energybar.setforeground(color.red); }else if(getenergy()<51 || getenergy()>26){ energybar.setforeground(color.yellow); }else if(getenergy()<76 || getenergy()>51){ energybar.setforeground(color.orange); }else if(getenergy()<101 || getenergy()>76){ energybar.setforeground(color.green); } energybar.repaint(); }
personally, think jprogressbar bugged. have own, more customizable way of making progress bar.
instead of using pre-made jprogressbar, use original way of displaying graphics: canvas
create subclass of canvas, override paint method, add variables represent color , value, , add setvalue method. in paint method, set color based on value, setforeground(color), use graphics argument paint rectangle(0,0,value,getheight()).
that how make progress bar. has advantage of:
a) add border & background color canvas, progress bar
b) use graphics.paintimage , scale/crop image correct size
hopefully helped progress bar :)
Comments
Post a Comment