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 76 77 78 79 80 81 82 83
|
import java.awt.*;
import java.awt.event.*;
import javax.naming.ldap.Control;
import javax.swing.*;
public class Fenetre2 extends JFrame implements ActionListener
{
static Game jeu;
JButton boutonNord,boutonSud,boutonEst,boutonOuest,prendre,deposer;
ImageIcon imgcoul,imgcel;
Image cellule;
JPanel panel;
static Joueur player;
JLabel label;
publicstaticvoid main(String[] args) {
jeu = new Game("thomas");
player = jeu.getPlayer();
Fenetre2 fenetre = new Fenetre2();
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.Fenetreinit();
fenetre.show();
jeu.play();
}
publicvoid Fenetreinit()
{
JPanel panel =new JPanel();
JLabel label = new JLabel();
getContentPane().add(panel);
getContentPane().setLayout(new FlowLayout());
this.setSize(500, 500);
boutonNord = new JButton("nord");
boutonNord.setBounds(120, 120, 50, 50);
panel.add(boutonNord);
boutonNord.addActionListener(this);
(...)
label.setBounds(120, 120, 50, 50);
ImageIcon imgcel =new ImageIcon("c:/cellule.JPG");
ImageIcon imgcoul =new ImageIcon("c:/couloir.JPG");
label.setIcon(imgcel);
panel.add(label);
}
publicvoid afficheimage(String piece)
{
ImageIcon imgcel =new ImageIcon("c:/cellule.JPG");
ImageIcon imgcoul =new ImageIcon("c:/couloir.JPG");
if (piece.equals("cellule"))
{
System.out.println("Affiche imagecel");
label.setText("Vous êtes dans la cellule");
}
publicvoid actionPerformed(ActionEvent e){
if (e.getSource()== boutonNord)
{
Command com = new Command("aller","Nord");
jeu.processCommand(com);
String piece = player.getCurrentroom().getDescription();
this.afficheimage(piece);
}
}
}
}
|
Partager