Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.Timer;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author sused
- */
- public class RampaAutomaticka extends Rampa implements ActionListener{
- private Timer t;
- private boolean goUp;
- public RampaAutomaticka() {
- t = new Timer(100, this);
- goUp = true;
- }
- public void goUp() {
- goUp = true;
- t.start();
- }
- public void goDown() {
- goUp = false;
- t.start();
- }
- public void Stop() {
- t.stop();
- }
- @Override
- public void down() {
- if (y1 >= y2) t.stop();
- x1-=2;
- y1+=2;
- repaint();
- }
- @Override
- public void up() {
- if (x1 >= x2) t.stop();
- x1+=2;
- y1-=2;
- repaint();
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if (goUp)
- up();
- else
- down();
- }
- }
Add Comment
Please, Sign In to add comment