Drag and drop, adn repaint to have the bachground cleaned

Hi, I am dragging and dropping JButtons, but when I do, it leaves it's mark (or shadow behind). How can I do to have a clean blackground?

Here's my code, I'm usig 2 classes. The first class is Appletprueba, and it calls a second class (applet que se draga), which contains the button that can be dragged..

Thnaks in advance.

package proyectoreal;

import java.awt.*;

//import java.awt.event.*;

//import java.applet.*;

//import com.borland.jbcl.layout.*;

import javax.swing.*;

import java.awt.event.*;

//import javax.swing.border.*;

class botonquesedragaextends JButton{

public botonquesedraga(){

try{

jbInit();

}

catch(Exception e){

e.printStackTrace();

}

}

privatevoid jbInit()throws Exception{

this.setBackground(Color.pink);

this.addMouseMotionListener(new botonquesedraga_this_mouseMotionAdapter(this));

}

void this_mouseDragged(MouseEvent e){

this.setLocation(this.getX()+e.getX(),this.getY()+e.getY());

this.repaint();

this.validate();

}

}

class botonquesedraga_this_mouseMotionAdapterextends java.awt.event.MouseMotionAdapter{

botonquesedraga adaptee;

botonquesedraga_this_mouseMotionAdapter(botonquesedraga adaptee){

this.adaptee = adaptee;

}

publicvoid mouseDragged(MouseEvent e){

adaptee.this_mouseDragged(e);

}

}

Here is the other class. Thanks

package proyectoreal;

import java.awt.*;

//import java.awt.event.*;

//import java.applet.*;

//import com.borland.jbcl.layout.*;

import javax.swing.*;

import java.awt.event.*;

//import javax.swing.border.*;

class botonquesedragaextends JButton{

public botonquesedraga(){

try{

jbInit();

}

catch(Exception e){

e.printStackTrace();

}

}

privatevoid jbInit()throws Exception{

this.setBackground(Color.pink);

this.addMouseMotionListener(new botonquesedraga_this_mouseMotionAdapter(this));

}

void this_mouseDragged(MouseEvent e){

this.setLocation(this.getX()+e.getX(),this.getY()+e.getY());

}

}

class botonquesedraga_this_mouseMotionAdapterextends java.awt.event.MouseMotionAdapter{

botonquesedraga adaptee;

botonquesedraga_this_mouseMotionAdapter(botonquesedraga adaptee){

this.adaptee = adaptee;

}

publicvoid mouseDragged(MouseEvent e){

adaptee.this_mouseDragged(e);

}

}

Thanks

[5138 byte] By [kandua] at [2007-11-27 8:40:20]
# 1

Your parent panel should be using a null layout manager. Then you just set the location of the button and it will repaint itself. No need to invoke repaint() or validate() manually.

If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",

see http://homepage1.nifty.com/algafield/sscce.html,

that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

camickra at 2007-7-12 20:38:44 > top of Java-index,Desktop,Core GUI APIs...
# 2

Hi camickr thanks for all your tips, I will just try them after I finish writing you

> I can't guess exactly what you are doing based on the information provided

I'm working on my thesis in order to graduate as an engineer, and what I'm trying to do is sometrhing very similar to what you will find in page:

http://jdsp.asu.edu/jdsp.html (you get to that page, and click start jdsp and follow instructions.It's very easy)

It's a signals and systems simulator. But mine will have some things different from the one on that page. But anyway, it will work prettymuch the same. I need to create boxes, which the user can drag and drop, and connect, and each of this bosex will represent either a signal (sine wave, etc) or an operator (adder, delayer, etc).

Now Im't trying to work on the graphic interface, and then I will program the functions for each box. I need to show this by two weeks, so I'm really in a hurry to finish this part...

Thanks for your help, I hope you undestood, and if you have any suggestions, I will be very happy and grateful to hear it.

kandua at 2007-7-12 20:38:44 > top of Java-index,Desktop,Core GUI APIs...
# 3
camickr,I tried setting the null layout for the pane and commenting the validate and repaint I had written, but then the button doesn't create any others when I click on it... So I can't see if it's actually doing what it's supposed to....
kandua at 2007-7-12 20:38:44 > top of Java-index,Desktop,Core GUI APIs...