Im new to all this and having a really hard time in this class. any help and explaination would be greatly appreciated,
what im trying to do is get the image to change depending on direction, i have the images ill send em if you need them, i know im doing something wrong i just cant seem to get what though. thanks in advance for any help!
If you want the JLabel to change in some way then you have to call one of its methods. Assigning a value to some other variable isn't going to change the JLabel.
Paul Clapham wrote:If you want the JLabel to change in some way then you have to call one of its methods. Assigning a value to some other variable isn't going to change the JLabel.
ohhhhhhhhhhhhhhhhhhhhhhhhh i get it now!!! thanks so much
tried this, and it doesnt initialize. What am i doing wrong?
imA = getImage(getCodeBase(),"aru.gif");
is there a way to change the text within the "" there?
You add an image to a JLabel by changing the Icon of the label. You create the label with a default Icon, but you never invoke label.setIcon(...) to change the Icon.
Also, you should NOT be reading the image every time you press a key. You should read all 4 images at the start of your program so the images are in memory.
Rob Camick wrote:You add an image to a JLabel by changing the Icon of the label. You create the label with a default Icon, but you never invoke label.setIcon(...) to change the Icon.
Also, you should NOT be reading the image every time you press a key. You should read all 4 images at the start of your program so the images are in memory.
ok so im reading the images at the top like this
now where would i put the label.setIcon? under every buttonpush?
As Rob Camick said a while back, if you want the JLabel's icon to change then you have to call the JLabel's setIcon() method with the image you want it to change to.