Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Dimension;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.Timer;
- public class RectangleMover implements ActionListener
- {
- public static RectangleComponent component;
- public static void main(String[] args)
- {
- JFrame frame = new JFrame();
- frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
- frame.setTitle("A moving rectangle");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel panel = new JPanel();
- component = new RectangleComponent();
- component.setPreferredSize(new Dimension(COMPONENT_WIDTH, COMPONENT_HEIGHT));
- panel.add(component);
- JButton button = new JButton("Move");
- panel.add(button);
- frame.add(panel);
- frame.setVisible(true);
- }
- public void actionPerformed(ActionEvent e)
- {
- component.moveBy(10, 10);
- }
- private static final int FRAME_WIDTH = 300;
- private static final int FRAME_HEIGHT = 400;
- private static final int COMPONENT_WIDTH = 200;
- private static final int COMPONENT_HEIGHT = 400;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement