Solved

take off blinking while dragging an image ??

Posted on 1998-07-06
6
198 Views
Last Modified: 2010-04-16
Hi experts, I'd like to know how to take off the blinking while dragging an image? (for JDK 1.0.2)

 Thank you.
0
Comment
Question by:Deladier
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:imladris
ID: 1224900
How is the dragging being done?

0
 

Author Comment

by:Deladier
ID: 1224901
Sorry. Dragging way is:

    public boolean mouseDrag(Event ev, int x, int y) {
      if(over == 1) { //over an image
         x = x - 8; //center image
         y = y - 6; //center image
          ima.setElementAt((new Integer(x)), (which+6));
          ima.setElementAt((new Integer(y)), (which+7));
        repaint();
      }

        for(int z=0; z<=((ima.size())-8); z=z+8) { //for1
         dy = Integer.valueOf(ima.elementAt(z+7).toString()).intValue();
         if(y>=dy & y<=(dy+12) & y!=dy & (ima.elementAt(z+2).toString()) != "I") {
          which2 = z;
          moveOver = 1;
         }
        } //for1
     
     
     return true;
    }

In 'if' loop I know that I already pressed over an image (over = 1 from mouseDown) and not over nothing.
'ima' is a Vector with images and the respective coordinates.
Do you think 'for' loop is the problem?. This 'for' loop is used in order to recognize over what image is dragging the image
0
 
LVL 16

Expert Comment

by:imladris
ID: 1224902
No, I don't think so. I'm more concerned with the paint method. Could you post that as well? Have you overridden the update method (which clears the screen before paint is called (which will cause a flicker)?

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Deladier
ID: 1224903
You're right, I haven't used update method, where do I put it?.
Here's the paint method:

  public void paint(Graphics g) {
    g.drawImage(getImage(getDocumentBase(), "menutree/w_raiz.gif"), 12, 0, this);
    Font raizfuen = new Font("Courier", Font.PLAIN, 10);
    g.setFont(raizfuen);
    g.setColor(Color.blue);
    g.drawString("Root", 30, 11);
   
    g.drawImage(getImage(getDocumentBase(), "menutree/w_raiz.gif"), 65, 0, this);
    Font borrafuen = new Font("Courier", Font.PLAIN, 10);
    g.setFont(borrafuen);
    g.setColor(Color.red);
    g.drawString("Erase Element", 83, 11);
       
   for(int u=0; u<=((ima.size())-8); u=u+8) { //forqw
    if((ima.elementAt(u).toString()) == "F" &
       (ima.elementAt(u+1).toString()) == "C" &
       (ima.elementAt(u+2).toString()) == "V") { //iffc
      String nomfold = ima.elementAt(u+5).toString();
      g.drawImage(getImage(getDocumentBase(), "menutree/wcf.gif"),
      (Integer.valueOf(ima.elementAt(u + 6).toString()).intValue()),
      (Integer.valueOf(ima.elementAt(u + 7).toString()).intValue()), this);  
       Font fuente = new Font("Helvetica", Font.PLAIN, 10);
       g.setFont(fuente);      
       g.drawString(nomfold,
       ((Integer.valueOf(ima.elementAt(u + 6).toString()).intValue()) + 22),
       ((Integer.valueOf(ima.elementAt(u + 7).toString()).intValue()) + 10));    
    } //iffc

    if((ima.elementAt(u).toString()) == "F" &
       (ima.elementAt(u+1).toString()) == "A" &
       (ima.elementAt(u+2).toString()) == "V") { //iffa
      String nomfold = ima.elementAt(u+5).toString();
      g.drawImage(getImage(getDocumentBase(), "menutree/wof.gif"),
      (Integer.valueOf(ima.elementAt(u + 6).toString()).intValue()),
      (Integer.valueOf(ima.elementAt(u + 7).toString()).intValue()), this);  
       Font fuente = new Font("Helvetica", Font.PLAIN, 10);
       g.setFont(fuente);      
       g.drawString(nomfold,
       ((Integer.valueOf(ima.elementAt(u + 6).toString()).intValue()) + 22),
       ((Integer.valueOf(ima.elementAt(u + 7).toString()).intValue()) + 10));    
    } //iffa    
   
    if((ima.elementAt(u).toString()) == "B" &
       (ima.elementAt(u+2).toString()) == "V") { //aq
      String nomdoc = ima.elementAt(u+5).toString();
      g.drawImage(getImage(getDocumentBase(), "menutree/wdoc.gif"),
      (Integer.valueOf(ima.elementAt(u + 6).toString()).intValue()),
      (Integer.valueOf(ima.elementAt(u + 7).toString()).intValue()), this);  
       Font fuente = new Font("Helvetica", Font.PLAIN, 10);
       g.setFont(fuente);      
       g.drawString(nomdoc,
       ((Integer.valueOf(ima.elementAt(u + 6).toString()).intValue()) + 22),
       ((Integer.valueOf(ima.elementAt(u + 7).toString()).intValue()) + 10));
    } //aq
   
   } //forqw

    if(moveOver == 1 & (ima.elementAt(which2).toString()) == "B" &
       (ima.elementAt(which2+2).toString()) != "I") { //zx
      String nomdoc = ima.elementAt(which2+5).toString();
      g.drawImage(getImage(getDocumentBase(), "menutree/ddoc.gif"),
      (Integer.valueOf(ima.elementAt(which2 + 6).toString()).intValue()),
      (Integer.valueOf(ima.elementAt(which2 + 7).toString()).intValue()), this);  
       Font fuente = new Font("Helvetica", Font.PLAIN, 10);
       g.setFont(fuente);      
       g.drawString(nomdoc,
       ((Integer.valueOf(ima.elementAt(which2 + 6).toString()).intValue()) + 22),
       ((Integer.valueOf(ima.elementAt(which2 + 7).toString()).intValue()) + 10));
    } //zx

    if(moveOver == 1 & (ima.elementAt(which2).toString()) == "F" &
       (ima.elementAt(which2+1).toString()) == "C") { //zx1
      String nomdoc = ima.elementAt(which2+5).toString();
      g.drawImage(getImage(getDocumentBase(), "menutree/dcf.gif"),
      (Integer.valueOf(ima.elementAt(which2 + 6).toString()).intValue()),
      (Integer.valueOf(ima.elementAt(which2 + 7).toString()).intValue()), this);  
       Font fuente = new Font("Helvetica", Font.PLAIN, 10);
       g.setFont(fuente);      
       g.drawString(nomdoc,
       ((Integer.valueOf(ima.elementAt(which2 + 6).toString()).intValue()) + 22),
       ((Integer.valueOf(ima.elementAt(which2 + 7).toString()).intValue()) + 10));
    } //zx1

    if(moveOver == 1 & (ima.elementAt(which2).toString()) == "F" & 
       (ima.elementAt(which2+1).toString()) == "A") { //zx2
      String nomdoc = ima.elementAt(which2+5).toString();
      g.drawImage(getImage(getDocumentBase(), "menutree/dof.gif"),
      (Integer.valueOf(ima.elementAt(which2 + 6).toString()).intValue()),
      (Integer.valueOf(ima.elementAt(which2 + 7).toString()).intValue()), this);  
       Font fuente = new Font("Helvetica", Font.PLAIN, 10);
       g.setFont(fuente);      
       g.drawString(nomdoc,
       ((Integer.valueOf(ima.elementAt(which2 + 6).toString()).intValue()) + 22),
       ((Integer.valueOf(ima.elementAt(which2 + 7).toString()).intValue()) + 10));
    } //zx2
  }



0
 
LVL 16

Accepted Solution

by:
imladris earned 30 total points
ID: 1224904
Each component has an update method. The code is:

    public void update(Graphics g) {
      g.setColor(getBackground());
      g.fillRect(0, 0, width, height);
      g.setColor(getForeground());
      paint(g);
    }

As you can see, this method "blanks" the screen (with a fillRect set to use the background colour) and then calls paint. The advantage of this is that when your paint method is called, you start "drawing" on a clean slate. The disadvantage is the flicker. You should override the update method to be:

    public void update(Graphics g) {
      paint(g);
    }

This will remove the flicker. On the other hand, YOU are now responsible for removing old/unwanted display items. One standard way of dealing with this is to use an animation technique labelled double buffering. An offscreen display buffer is created, the current state of the display "drawn" into this buffer, then it is displayed in a single call. The following will accomplish this:

public void update(Graphics g)
{   Image bufimg;

    //create an Image the size of your display
    bufimg=createImage(width,height);
    //get graphics context for it
    Graphics bg=bufimg.getGraphics();
    //draw into it
    paint(bg);
    //put it on the screen
    g.drawImage(bufimg,0,0,null);
    //free operating system resources taken up
    bg.dispose();
    return;
}


In this scenario you are, of course, always double buffering. If that's not desirable, this mechanism can be employed in a suitable location in the code when needed. For instance, what is now the paint logic could go in a seperate method (named showScreen (for example), which takes a Graphics object as argument), and paint could call showScreen, as well as the place that required the double buffering (which would create the Graphics context from some image).

0
 

Author Comment

by:Deladier
ID: 1224905
Thanks.   :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert String matching to regex in java 4 48
tomcat administrtor 12 58
runtime exception 2 41
hashmap order 17 36
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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

809 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