Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Emergency!

Posted on 2004-11-16
5
Medium Priority
?
234 Views
Last Modified: 2010-03-31
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=Rejillas.gridheight=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()),Rejillas);
            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            
            
0
Comment
Question by:TheFred
  • 2
4 Comments
 
LVL 3

Expert Comment

by:RuadRauFlessa
ID: 12601218
Have you tried looking at overriding the paint method and manually painting your sprite since it will be much faster and smoother and you can incorporate alot more from there.

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().

0
 
LVL 92

Accepted Solution

by:
objects earned 750 total points
ID: 12601225
> how can I force my JFrame to show the changes in my Jpanel

pane.revalidate();

> 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 ??

Use an inner class
0
 

Author Comment

by:TheFred
ID: 12609132
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?
0
 
LVL 92

Expert Comment

by:objects
ID: 12609207
you need to add your keylistener to whatever component has focus at the time you are interested.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question