You are on page 1of 2

import import import import import import import import import import public

java.applet.Applet; java.applet.AudioClip; java.awt.Graphics; java.awt.Image; java.awt.Toolkit; java.awt.event.ActionEvent; java.awt.event.ActionListener; javax.swing.ImageIcon; javax.swing.JButton; javax.swing.JPanel; class Pelicula extends JPanel{ ImageIcon actual; Image act; JButton bt1=new JButton(">"); JButton bt2=new JButton(" "); Gif a=new Gif();; int valor=0; AudioClip sonido =Applet.newAudioClip( getClass().getResource("video.wav

") ); public Pelicula (){ setLayout(null); bt1.setBounds(0, 503, 80, 30); bt2.setBounds(100, 503, 80, 30); bt1.addActionListener(new Evento()); bt2.addActionListener(new Evento()); actual=new ImageIcon(getClass().getResource("1/video1.jpg")); add(bt1); add(bt2); this.setSize(550,510); } public void paint (Graphics g) { super.paint(g); g.drawImage(actual.getImage(),0, 0,null); } public class Evento implements ActionListener{ String tex=""; public void actionPerformed(ActionEvent e){ JButton b=(JButton)e.getSource(); tex=b.getText(); if(tex.equals(">")){ a.play(); sonido.play(); } else if(tex.equals(" ")){ a.stoop(); sonido.stop(); } } } private class Gif extends Thread { private boolean alto=true; int valor=1; public void run(){ actual=null; while(alto){ actual=new ImageIcon(getClass().getResource("1/video"+(valor)+". jpg")); pausa(12); valor++; repaint();

} } public void pausa(int p){ try{ sleep(p); } catch(InterruptedException e){} } private boolean r=false; private boolean s=false; public void play(){ if(!r){ start(); r=true; } else if(s){ resume(); s=false; } else{ suspend(); s=true; } } public void stoop(){ valor=1; suspend(); s=true; } public void pausad(){ if(r){ suspend(); r=true; } else resume(); s=true; } } }

You might also like