import [Link].
*;
public class Rect {
private int X,Y,a,b;
private Color color;
public Rect(int x, int y, int w, int z, Color c{
X=x;
Y=y;
a=w;
b=z;
color = c;
}
public void draw (Graphics g){
Color oldColor = [Link]();
[Link](color);
[Link](X, Y, a, b);
[Link](oldColor);
}
public boolean containsPoint(int x, int y){
return (x>X && x<X+a && y>Y && y<Y+b);
}
public void move(int xAmount , int yAmount){
X+= xAmount;
Y+= yAmount;
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class ColorPanel extends JPanel{
private Rect selected;
private Rect s1;
private int x,y;
public ColorPanel(Color backColor){
setBackground (backColor);
s1 = new Rect(50,50,50,50, [Link]);
selected = null;
addMouseListener(new PanelListener());
}
public void paintComponent(Graphics g){
[Link](g);
[Link](g);
}
private class PanelListener extends MouseAdapter{
public void mousePressed(MouseEvent e){
if(selected == null){
if ([Link]([Link](), [Link]())){
selected = s1;}
x=[Link]();
y=[Link]();}
else{
int newX= [Link]();
int newY = [Link]();
int dx = newX-x;
int dy = newY-y;
[Link](dx, dy);
repaint();
selected = null;
x=newX;
y=newY;
}
}
}
}
import [Link].*;
import [Link].*;
public class GUI {
public static void main(String[] args) {
JFrame jf = new JFrame();
[Link](500,500);
[Link]("Hi");
[Link](JFrame.EXIT_ON_CLOSE);
ColorPanel panel = new ColorPanel([Link]);
Container pane = [Link]();
[Link](panel);
[Link](true);
}
}