1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| package td5;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JApplet;
// gestion du son @ faire
public class Exercice2 extends JApplet implements Runnable,KeyListener
{
private static final long serialVersionUID = 1L;
private Thread thread;
private Concombre cucumber;
public void init()
{
this.getContentPane().setBackground(Color.YELLOW);
cucumber = new Concombre(400,300,50);
thread = new Thread(this);
thread.start(); // dmarre la mthode run
}
public void start()
{
}
public void paint(Graphics g)
{
super.paintComponents(g);
cucumber.dessiner(g);
}
public void run()
{
/*while(thread!=null)
{
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
cucumber.bouger(3);
this.repaint();
}*/
}
public void destroy()
{
}
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_UP)
{
cucumber.monter();
repaint();
}
else if(e.getKeyCode()==KeyEvent.VK_DOWN)
{
cucumber.descendre();
repaint();
}
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
} |
Partager