TheFred
asked on
Emergency!
Hi folks, i'm in a hurry
I'm writting kind of a game in java , my first. Everything went ok with the swing components (Y), but here is my problem, my consists on a robot who moves inside of an array. i do have a JPanel working with a GridBagLayout Manager to represent the array, then I use this panel as a component of a bigger panel together with some other components, that big panel is going to be the container of my JFrame.
That's working good, but know y listen to the keyboard and receive a movement, (ok) i make the changes inside of the array (ok) but when i call to my paintarray method that first created the pane it seems to work ok , but I keep looking at the same thing , it does not refresh, i tried using container.repaint() panel.repaint() but doesn't work the code i use to PaintArray looks like :
public void Dibujar (JPanel pane, CCasilla[][] ma){
int i, j;
pane.removeAll();
GridBagConstraints Rejillas = new GridBagConstraints();
Rejillas.gridwidth=Rejilla s.gridheig ht=1;
for (i = 0 ; i < _fi; i ++){
for ( j = 0 ; j <_co;j++){
Rejillas.gridx = j;
Rejillas.gridy = i;
if (ma[j][i] == null){
pane.add(new JLabel(cas),Rejillas);
}
else{
pane.add(new JLabel(ma[j][i].getImagen( )),Rejilla s);
if ((ma[j][i] instanceof CBeeper)||(ma[j][i] instanceof CRobot)){
pane.add(new JLabel(cas),Rejillas);
}
}
}
}
Need help !! how can I force my JFrame to show the changes in my Jpanel . And another question Im Using public class CGame extends JFrame implements KeyListener as the clase in which i listen the keyboard, i don't want to use the word implements ..... any other way ?? . ANYWAY the first question is the BIG ONE please HELP
I'm writting kind of a game in java , my first. Everything went ok with the swing components (Y), but here is my problem, my consists on a robot who moves inside of an array. i do have a JPanel working with a GridBagLayout Manager to represent the array, then I use this panel as a component of a bigger panel together with some other components, that big panel is going to be the container of my JFrame.
That's working good, but know y listen to the keyboard and receive a movement, (ok) i make the changes inside of the array (ok) but when i call to my paintarray method that first created the pane it seems to work ok , but I keep looking at the same thing , it does not refresh, i tried using container.repaint() panel.repaint() but doesn't work the code i use to PaintArray looks like :
public void Dibujar (JPanel pane, CCasilla[][] ma){
int i, j;
pane.removeAll();
GridBagConstraints Rejillas = new GridBagConstraints();
Rejillas.gridwidth=Rejilla
for (i = 0 ; i < _fi; i ++){
for ( j = 0 ; j <_co;j++){
Rejillas.gridx = j;
Rejillas.gridy = i;
if (ma[j][i] == null){
pane.add(new JLabel(cas),Rejillas);
}
else{
pane.add(new JLabel(ma[j][i].getImagen(
if ((ma[j][i] instanceof CBeeper)||(ma[j][i] instanceof CRobot)){
pane.add(new JLabel(cas),Rejillas);
}
}
}
}
Need help !! how can I force my JFrame to show the changes in my Jpanel . And another question Im Using public class CGame extends JFrame implements KeyListener as the clase in which i listen the keyboard, i don't want to use the word implements ..... any other way ?? . ANYWAY the first question is the BIG ONE please HELP
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
objects, first one... worked fine thx, second one... how can i do that? When I compile this class "public class CGame extends JFrame implements KeyListener" works fine when using sdk 1.3 but not as good when using 1.4 , the second one captures no keystroke. I think it's a problem of focus maybe to the frame ... how can i fix that?
you need to add your keylistener to whatever component has focus at the time you are interested.
If you still want to keep it like it is at the moment rather add a JLabel to every grid component and simply set and remove the icon's of the labels to ma[j][i].getImagen().