Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is my revision to your code : </p> <p>first instead of using paint() method i used paintComponent() method</p> <p>well that solves my problem (" it keeps on showing grey bar even if its updated") Note* the board gets updated but you have to update it manually by calling update(Pokemon CurrentPokemon) method;</p> <pre><code> public class Board extends JPanel { private int health; private int maxHealth; public Board(Pokemon par1Poke) { this.health = par1Poke.getCurrentHealth(); this.maxHealth = par1Poke.getPokeStats().getPokeMaxHealth(); } @Override public void paintComponent(Graphics g) { super.paint(g); g.setColor(Color.GRAY); g.fillRect(2, 2, 200, 20); g.setColor(Color.GREEN); g.fillRect(2, 2, 200 *(health/maxHealth) , 20); } public void update(Pokemon Poke1) { health = Poke1.getCurrentHealth(); maxHealth = Poke1.getPokeStats().getPokeMaxHealth(); } </code></pre> <p>}</p> <p>Then in your Main</p> <pre><code> public class Start extends JFrame { static Pokemon poke1 = PokeDex.BULBASAUR; static Pokemon poke2 = PokeDex.CHARMANDER; static Pokemon poke3 = PokeDex.SQUIRTLE; public static Board board = new Board( poke1 ); public Start() { this.setSize( 500, 290 ); this.setDefaultCloseOperation( EXIT_ON_CLOSE ); this.setLocationRelativeTo( null ); this.add( board ); this.setVisible( true ); } public static void main ( String[] args ) { new Start(); BattleHandler battle = new BattleHandler(); battle.initiateBattle( poke1, poke2 ) ; board.update(poke1); } </code></pre> <p>}</p> <p>Well sure this is not the best solution , its all I can think</p> <p>I got your code and implemented mine, <a href="https://sites.google.com/site/dexclipseprogramming/course-materials/Pokemon-Battle-Simulator-master.rar?attredirects=0&amp;d=1" rel="nofollow">Download this and run.</a> This might be what you want</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload