import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;

public class MovingRectangleWithReset extends JPanel implements ActionListener {
    double x0 = 50, y0 = 50;
    double x, y;
    double dx = 3, dy = 2;
    double width = 100, height = 50;

    public MovingRectangleWithReset() {
	setBackground(Color.white);
	x = x0;  y = y0;
    }
    
    public void actionPerformed(ActionEvent event) {
	String actionCommand = event.getActionCommand();
	if (actionCommand.equals("Move")) {
	    x += dx;  y += dy;
	}
	else if (actionCommand.equals("Reset")) {
	    x = x0;  y = y0;
	}
	repaint();
    }

    public void paintComponent(Graphics gfx) {
	super.paintComponent(gfx);
	Graphics2D g = (Graphics2D) gfx;
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			   RenderingHints.VALUE_ANTIALIAS_ON);
	
	g.draw(new Rectangle2D.Double(x, y, width, height));
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("MovingRectangleWithReset");
	frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	MovingRectangleWithReset mr = new MovingRectangleWithReset();
        mr.setPreferredSize(new Dimension(300, 200));
	mr.setBackground(Color.white);
        frame.getContentPane().add(mr, BorderLayout.CENTER);

	JButton move = new JButton("Move");
	move.addActionListener(mr);
	JButton reset = new JButton("Reset");
	reset.addActionListener(mr);
	
	JPanel buttonPanel = new JPanel();
	buttonPanel.add(move);
	buttonPanel.add(reset);
	frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);

        frame.pack();
        frame.show();
    }
}


    
