i want to write a code for the Tanks Game and I have a problem setting a tank.jpg on an existing ImageIcon , casue i want the both images to be visible and showed to the user , it’s like :
JButton block = new JButton () ;
block.setIcon(new ImageIcon("ground.png")) ;// sets the first image
block.setIcon(new ImageIcon("tank.png")) ;// sets the second image
but if i write the code like this , the second setIcon will replace the first one , which is what i dont want , any Ideas how to have 2 icons on a JButton at once ? thanks
The easiest way is to combine the two icons into one. You can do this either manually (if you have only few combinations) or write an
Iconimplementation on your own.You can e.g. align the two icons side-by-side with the following implementation: