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

