ciao a tutti!!!!
con questo cod:
faccio animare l'immagine dal basso verso l'alto....codice:import java.awt.*; import java.awt.event.ActionEvent; import java.awt.image.ImageObserver; import javax.swing.*; public class GifAnimata extends JFrame { Image animation; Immagine currentAnimation = new Immagine(); JFrame frame = new JFrame("prova Animazione"); public GifAnimata() { prova(); } public void prova() { ImageIcon ball_IMG_ICON = new ImageIcon("c://immagine.jpg"); animation = ball_IMG_ICON.getImage(); prepareImage(animation, this); currentAnimation.setX(10); currentAnimation.setY(+100); new Timer(100, paintTimer).start(); frame.setTitle("Gif Animata"); frame.setSize(1100, 720); frame.add(panel); frame.setLocationRelativeTo( null ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setVisible( true ); } JPanel panel = new JPanel() { public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g.setColor(Color.WHITE); g.fillRect(0, 0, 1100, 720); g2d.drawImage(animation, currentAnimation.getX(), currentAnimation.getY(), this); Toolkit.getDefaultToolkit().sync(); g.dispose(); } }; // in quale direzione inviare l'immagine Action paintTimer = new AbstractAction() { public void actionPerformed(ActionEvent e) { //currentBall.setX(currentBall.getX() + 5); currentAnimation.setY(currentAnimation.getY() - 1); frame.repaint(); } }; public static void main(String[] args) { GifAnimata ga = new GifAnimata(); } } class Immagine { /* * Simple Object class to store the ball's co-ordinates. */ private int x; private int y; Immagine() { ; } public int getX() { return x; } public void setX(int x2) { x = x2; } public int getY() { return y; } public void setY(int y2) { y = y2; } }
ora vorrei aggiungere 2 JButton con pause stoppa l'animazione con play riprende l'animazione...
al pause ho scritto:
new Timer(100, paintTimer).stop();
ma non si ferma...
HELP!!!!

Rispondi quotando
