implementing window dragging

hello, in order to beautify my window i set

Frame.setUndecorated(true);

and i draw my own title bar with minimize and maximize buttons.

now how can i implement the dragging the window around on the screen?
i tried to do

Frame.setLocation(Frame.getLocation().x+=deltaX, Frame.getLocation().y+=deltaY);

where delta is the difference of the mouseposition, but unfortunately this results in a flickering of the window back and forth a few pixels.

thanks!

private Rectangle bounds;
private int relx=0,rely=0;

public void mouseDragged(MouseEvent e){
	int nx=bounds.x-relx+e.getX();
	int ny=bounds.y-rely+e.getY();
	f.setLocation(nx,ny);
	bounds=f.getBounds();
}

public void mousePressed(MouseEvent e){
	bounds=f.getBounds();
	relx=e.getX();
	rely=e.getY();
}

thank you very much, that works perfectly!

now i also want the window to be resizable at the borders and corners. how would i do that?

thanks!

I guess like moving… you detect mouse pressed on edges and according to drag you set new size and position of Frame