IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

Images & url = null ?


Sujet :

avec Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2006
    Messages
    111
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2006
    Messages : 111
    Par défaut Images & url = null ?
    Principe du programme , refaire un jeux que j'ai fait en javascript.
    Il fonctionne sur http://deusgame.com c'est la partie jdr.

    Mini Descriptif des classes :
    Une page de connection
    Une page d'affichage
    Dans la page d'affichage on as une zone ou j'affiche le champ de vision .
    Se champ de vision demande a chaque case une image
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    package jdr;
     
    public abstract class Case {
    	public abstract javax.swing.ImageIcon getImg();
    	/*
    	 * -1 = Inconnu
    	 * 0 = N'est pas un obstacle
    	 * 1 = Dois Savoir nager ( Eau )
    	 * 2 = Est un joueur actif
    	 * 3 = Est un pnj
    	 * 4 = Est un Mur
    	 * 5 = Est une ressources
    	 */
    	public abstract int getObstacle();
    }
    Pour cela elle demande a carte la case :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    	// Liste des Personnes
    	private HashMap<Integer , Personne> listePersonne = new HashMap<Integer , Personne>(size_x*size_y);
    	// Carte
    	private Case[][] terrain ;
     
    ............
     
    public Case getCase(int x , int y){ 
    		synchronized (listePersonne){
    			// Prerequis
    			if ( ( x >= size_x ) || ( x < 0 ) ) return null;
    			if ( ( y >= size_y ) || ( y < 0 ) ) return null;
    			// On regarde le hashcode via la position de la personne,
    			// cette derniere etant unique, elle nous sert de repaire.
    			Personne p = listePersonne.get( codePosi(x,y) ) ;
    			if ( p != null ) return p;
    			// Si la case ne contient pas une personne, 
    			// alors on renvoye le terrain.
    			return terrain[x][y];
    		}
    	}
    Le terrains fonctionne bien : ( image local --> jar )
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    package jdr;
    /*
     * @Autor Ungar Didier
     * @Autor Desplanque Valentin
     * 
     * @version 1.0.0.0
     */
    import javax.swing.ImageIcon;
     
     
    public class Terrain extends Case{
    	private static ImageIcon imgNone = null;
    	private static ImageIcon img_a = null;
    	private static ImageIcon img_c = null;
    	private static ImageIcon img_C = null;
    	private static ImageIcon img_d = null;
    	private static ImageIcon img_e = null;
    	private static ImageIcon img_f = null;
    	private static ImageIcon img_F = null;
    	private static ImageIcon img_h = null;
    	private static ImageIcon img_g = null;
    	private static ImageIcon img_m = null;
    	private static ImageIcon img_n = null;
    	private static ImageIcon img_o = null;
    	private static ImageIcon img_p = null;
    	private static ImageIcon img_P = null;
    	private static ImageIcon img_r = null;
    	private static ImageIcon img_R = null;
    	private static ImageIcon img_s = null;
    	private static ImageIcon img_t = null;
    	private static ImageIcon img_T = null;
    	private static ImageIcon img_v = null;
    	private static ImageIcon img_vide = null;
     
    	/*
    	 * Constructeur :
    	 */
    	public Terrain(char c){
    		switch (c) {
    		case 'a' :// Arbre
    			if ( img_a==null )
    				img_a = new ImageIcon(getClass().getResource("img/arbre.gif"));
    			img = img_a;
    			obstacle=4;
    			break;
    		case 'c' :// Carpe
    			if ( img_c==null )
    				img_c = new ImageIcon(getClass().getResource("img/carp.gif"));
    			img = img_c;
    			obstacle=5;
    			break;
    		case 'C' :// Rascasse
    			if ( img_C==null )
    				img_C = new ImageIcon(getClass().getResource("img/rascasse.gif"));
    			img = img_C;
    			obstacle=5;
    			break;
    		case 'd' :// Deut
    			if ( img_d==null )
    				img_d = new ImageIcon(getClass().getResource("img/deut.jpg"));
    			img = img_d;
    			obstacle=5;
    			break;
    		case 'e' :// Eau
    			if ( img_e==null )
    				img_e = new ImageIcon(getClass().getResource("img/eau.gif"));
    			img = img_e;
    			obstacle=1;
    			break;
    		case 'f' :// Fleur
    			if ( img_f==null )
    				img_f = new ImageIcon(getClass().getResource("img/fleur.gif"));
    			img = img_f;
    			break;
    		case 'F' :// Fer
    			if ( img_F==null )
    				img_F = new ImageIcon(getClass().getResource("img/fer.jpg"));
    			img = img_F;
    			obstacle=5;
    		break;
    		case 'h' :// Herbe
    			if ( img_h==null )
    				img_h = new ImageIcon(getClass().getResource("img/herbe.jpg"));
    			img = img_h;
    			break;
    		case 'g' :// Fruit
    			if ( img_g==null )
    				img_g = new ImageIcon(getClass().getResource("img/fruit.gif"));
    			img = img_g;
    			obstacle=5;
    			break;
    		case 'm' :// Montagne
    			if ( img_m==null )
    				img_m = new ImageIcon(getClass().getResource("img/montagne.png"));
    			img = img_m;
    			break;
    		case 'n' :// Neige
    			if ( img_n==null )
    				img_n = new ImageIcon(getClass().getResource("img/neige.jpg"));
    			img = img_n;
    			obstacle=4;
    			break;
    		case 'o' :// Mines d'or
    			if ( img_o==null )
    				img_o = new ImageIcon(getClass().getResource("img/or.jpg"));
    			img = img_o;
    			obstacle=5;
    			break;
    		case 'p' :// Pont
    			if ( img_p==null )
    				img_p = new ImageIcon(getClass().getResource("img/pont.jpg"));
    			img = img_p;
    			break;
    		case 'P' :// Petrol
    			if ( img_P==null )
    				img_P = new ImageIcon(getClass().getResource("img/petrol.gif"));
    			img = img_P;
    			obstacle=5;
    			break;
    		case 'r' :// RouteH
    			if ( img_r==null )
    				img_r = new ImageIcon(getClass().getResource("img/routeH.gif"));
    			img = img_r;
    			break;
    		case 'R' :// RouteV
    			if ( img_R==null )
    				img_R = new ImageIcon(getClass().getResource("img/routeV.gif"));
    			img = img_R;
    			break;
    		case 's' :// Mines d'or
    			if ( img_s==null )
    				img_s = new ImageIcon(getClass().getResource("img/sable.jpg"));
    			img = img_s;
    			break;
    		case 't' :// Terre
    			if ( img_t==null )
    				img_t = new ImageIcon(getClass().getResource("img/terre.jpg"));
    			img = img_t;
    			break;
    		case 'T' :// Mines d'or
    			if ( img_T==null )
    				img_T = new ImageIcon(getClass().getResource("img/totem.gif"));
    			img = img_T;
    			obstacle=5;
    			break;
    		case 'v' :// Ville
    			if ( img_v==null )
    				img_v = new ImageIcon(getClass().getResource("img/ville.gif"));
    			img = img_v;
    			obstacle=5;
    			break;
    		case '*' :// Vide
    			if ( img_vide==null )
    				img_vide = new ImageIcon(getClass().getResource("img/vide.jpg"));
    			img = img_vide;
    			break;
    		default:
    			if ( imgNone==null )
    				imgNone = new ImageIcon(getClass().getResource("img/NoImg.jpg"));
    		img = imgNone;
    		break;
     
    		}
    	}
    	/*
    	 * Variables :
    	 */
    	private int obstacle=0;
    	public int getObstacle(){return obstacle;}
    	private ImageIcon img = null;
    	public ImageIcon getImg(){	return img;	}
    }
    Sur le même principe j'ai crée Monstre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    package jdr;
     
    import javax.swing.ImageIcon;
     
    public class Monstre extends Personne{
    	/*
    	 * Le serveur répond sous la forme :
    	 * type posi_x posi_y id_type pv_act
    	 * Exemple :
    	 * m1 3 10 5
    	 * Monstre en (1,3) de type 10 avec 5 pv
    	 * On as a analyser :
    	 * 1 3 10 5, car le 'm' as été analyser par carte
    	 */
    	public Monstre(String datas,Carte carte){
    		datas.trim();
    		String[] valeurs = datas.split(" ");
    		x = 7+(Integer.valueOf(valeurs[0])-carte.getPosiX());
    		y = 7-(Integer.valueOf(valeurs[1])-carte.getPosiY());
    		id_type = Integer.valueOf(valeurs[2]);
    		pv_act = Integer.valueOf(valeurs[3]);
    		// As-t-on les informations sur se monstre ?
    		if ( img_E[id_type]==null ) getInfo();
    	}
    	private void getInfo(){
    		String reponce =new Http().post(Param.getServeur()+"jdr.php?act=info&type=m&id="+id_type, Param.getSession());
    		reponce = reponce.trim();
    		String[] datas = reponce.split("[|]");
    		nom[id_type] = datas[0];
    		pv_max[id_type] = Integer.valueOf(datas[1]);
    		datas[2]=datas[2].trim();
    		if ( datas[2].indexOf("http://") >=0 )
    			img_E[id_type] = new ImageIcon(datas[2]);
    		else if ( datas[2].length() > 0 ){
    			datas[2] = "http://s193648367.onlinehome.fr/Deus/Skin/img/E/"+datas[2];
    			img_E[id_type] = new ImageIcon(datas[2]);
    		}
    		if ( img_E[id_type]==null )
    			img_E[id_type] = new ImageIcon("img/NoImg.jpg");
    	}
    	private int x;
    	public  int getX(){return x;}
    	private int y;
    	public  int getY(){return y;}
    	public  int getObstacle(){return 3;}
    	private int id_type;
    	private String nom[] = new String[250];;
    	private int pv_act;
    	private int pv_max[] = new int[250];
    	public String getTitle(){return nom[id_type]+" ("+pv_act+"/"+pv_max[id_type]+")";}
    	private static ImageIcon img_E[] = new ImageIcon[250];
    	public  ImageIcon getImg(){ return img_E[id_type]; }
    }
    Remarque Personne est une case ( il en découle, PJ et PNJ )
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    package jdr;
     
    public abstract class Personne extends Case{
    	public abstract int getX();
    	public abstract int getY();
    }
    Mon bug :
    Lorsque je voit un monstre sont image ne se charge pas.
    Je suppose que le thread de swing n'as pas raffrechi l'écrant une fois l'image charger.

    Comment corriger l'erreur.

  2. #2
    Membre Expert
    Avatar de gifffftane
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 354
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire (Rhône Alpes)

    Informations forums :
    Inscription : Février 2007
    Messages : 2 354
    Par défaut
    Pour t'assurer si le bug vient de là, je te suggère de remplacer ton image par quelque chose dont tu es sûr ; par exemple un carré bleu, que tu auras fabriqué dans ton code.

    Si tu vois ton carré bleu, c'est que cela confirme ton opinion ; sinon, c'est que ça vient d'autre chose.

    Bonne recherche.

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2006
    Messages
    111
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2006
    Messages : 111
    Par défaut
    j'ai remplacer :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    if ( datas[2].indexOf("http://") >=0 )
    			img_E[id_type] = new ImageIcon(datas[2]);
    		else if ( datas[2].length() > 0 ){
    			datas[2] = "http://s193648367.onlinehome.fr/Deus/Skin/img/E/"+datas[2];
    			img_E[id_type] = new ImageIcon(datas[2]);
    		}
    		if ( img_E[id_type]==null )
    			img_E[id_type] = new ImageIcon("img/NoImg.jpg");
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    if ( img_E[id_type]==null )
    			img_E[id_type] = new ImageIcon("img/NoImg.jpg");
    Donc je devrai toujours avoir la NoImg, mais non.

    D'ou ca peut venir alors ?

  4. #4
    Membre confirmé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2006
    Messages
    111
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2006
    Messages : 111
    Par défaut
    Aprés une longue batterie de test :
    - L'image existe en t'en qu'objet java
    - L'image ne s'affiche pas pour tout les Monstres.
    - L'image fonctionne pour l'avatar qui vient lui aussi de la liste

  5. #5
    Membre Expert
    Avatar de gifffftane
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 354
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire (Rhône Alpes)

    Informations forums :
    Inscription : Février 2007
    Messages : 2 354
    Par défaut
    Mais comment est-ce que tu affiches cette image ? ...je n'ai pas retrouvé le code d'affichage dans ce que tu nous montres.

  6. #6
    Membre confirmé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2006
    Messages
    111
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2006
    Messages : 111
    Par défaut
    Desoler je pensai l'avoir mis : ( extrait de l'affichage / actualisation )
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    /*
    	 * Calcul/Recalcul le tableaux de la carte
    	 */
    	private void affCentre(){
    		panelCenter.setLayout(new GridLayout(carte.getSizeY(),carte.getSizeX()));
    		for (int y=0 ; y < carte.getSizeY() ; y++ ){
    			for (int x=0 ; x < carte.getSizeX() ; x++ ){
    				if ( carte.getCase(x, y) != null ){
    					if ( carte.getCase(x, y).getImg() != null )
    						monde[x][y].setIcon( carte.getCase(x, y).getImg() );
    					else{
    						monde[x][y].setIcon( null );
    						monde[x][y].setText( new Integer(carte.getCase(x, y).getObstacle()).toString() );
    					}
    				}else{
    					monde[x][y].setIcon( null );
    					monde[x][y].setText("?");
    				}
    				monde[x][y]
    				         .setToolTipText("Position : ("
    				        		 +(carte.getPosiX()-7+x)+","
    				        		 +(carte.getPosiY()+7-y)+")");
    			}
    		}
    		//panelCenter.repaint();
    		//fenaitre.repaint();
    	}
    ( complet )
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    package jdr;
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.Frame;
    import java.awt.GridLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
     
    import javax.swing.*;
     
    import java.awt.event.*;
     
     
     
    public class FrameJDR extends AbstractAction implements KeyListener,EcouteurMiseAJour{
    	/** Définition **/
    //	private final static String Fr_Attaque = "";
     
    	/** Variables **/
     
    	/** Interface **/
    	private volatile JTextField txtTchat = new JTextField( "" , 30 );
    	private volatile JLabel lbTchat;
    	private Tchat trdTchat;
    	private JButton monde[][] ;// a initialise
    	private JPanel panelCenter = new JPanel();
     
    	/** Outils **/
    	private Var var = new Var("Pref");
    	private JFrame fenaitre;
    	private Carte carte = new Carte();
     
    	/** Constructeur **/
    	public FrameJDR(){
    		/*  Fenaitre */
    		super();
    		/* Délcaration de l'interface */
    		carte.addEcouteurMiseAJour(this);
    		/* Interface */
    		fenaitre = new JFrame();
    		/* Aspect */
    		fenaitre.setTitle("JDR");
    //		fl.setSize(800,600);
    		fenaitre.setBounds(java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
     
    		fenaitre.setVisible(true);
     
    		fenaitre.setIconImage(new ImageIcon(getClass().getResource("img/favicon.gif")).getImage());
    		fenaitre.setLocationRelativeTo(null); //On centre la fentre sur l'écran
    		fenaitre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		/* Zone de positionnement */
    		JPanel panel = new JPanel();
    		BorderLayout struct = new BorderLayout();
    		fenaitre.setContentPane(panel);
    		panel.setLayout(struct);
    		if (var.isVar("bg")){// Couleur de fond
    			panel.setBackground(new Color(new Integer(var.getVar("bg"))));
    		}else{
    			panel.setBackground(Color.BLACK);
    		}
    		/* Site : ( North ) */
    		JPanel panelNorth = new JPanel();
    		/***
                     * Menu :
                     ***/
    		JMenuBar menu = new JMenuBar();
    		JMenu mnAbout = new JMenu("?");
    		menu.add(mnAbout);
    		JMenuItem mnThinksTo = new JMenuItem("Remerciement");
    		mnAbout.add(mnThinksTo);
    		mnThinksTo.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {
    				JOptionPane.showMessageDialog(new Frame(),
    						"Chef de projet :\n"+
    						"Ungar Didier\n"+
    						"Programmeurs :\n"+
    						"Ungar Didier\n"+
    						"Desplanque Valentin"+
    						"Relectrice :\n"+
    						"Le Tiec Alexandra\n"+
    				"Mais aussi les testeurs...");
    			}
    		});
    		panelNorth.add(menu);
     
    		panel.add(panelNorth,BorderLayout.NORTH);
    		panelNorth.setBackground(panel.getBackground());
    		/* Quit : ( South ) */
    		JPanel panelSouth = new JPanel();
    		//	Vie
    		JProgressBar barVie;
    		barVie = new JProgressBar(0, 100);
    		barVie.setValue(20);
    		barVie.setStringPainted(true);
    		barVie.setBackground(Color.WHITE);
    		barVie.setForeground(Color.RED);
    		panelSouth.add(barVie);
    		// Action
    		JComboBox lstAct = new JComboBox();
    		lstAct.addItem("Attaque Corp à Corp");
    		lstAct.addItem("Attaque Distance");
    		lstAct.addItem("Sort de soin léger");
    		lstAct.addItem("Sort de soin lourd");
    		lstAct.addItem("Sort de boule de feu");
    		lstAct.addItem("Sort d'aura foudroyante");
    		panelSouth.add(lstAct);
    		// Bouton
    		JButton bt_Sac = new JButton("Sac");
    		bt_Sac.addActionListener(this);
    		panelSouth.add(bt_Sac);
    		// Mana
     
    		//	Vie
    		JProgressBar barMana;
    		barMana = new JProgressBar(0, 100);
    		barMana.setValue(20);
    		barMana.setStringPainted(true);
    		barMana.setBackground(Color.WHITE);
    		barMana.setForeground(Color.BLUE);
    		panelSouth.add(barMana);
    		// Général
    		panel.add(panelSouth,BorderLayout.SOUTH);
    		panelSouth.setBackground(panel.getBackground());
    		/* Resultat : ( Center ) */
    		panelCenter.setLayout(new GridLayout(carte.getSizeX(),carte.getSizeY()));
     
     
     
    		monde = new JButton[carte.getSizeX()][carte.getSizeY()];
    		for (int y=0 ; y<carte.getSizeY() ; y++){
    			for (int x=0 ; x<carte.getSizeX() ; x++){
    				monde[x][y] = new JButton("");// On crée la case
    				panelCenter.add(monde[x][y]);// On place la case
    				monde[x][y].addActionListener(new ActCase(x,y));// On rend interactif
    			}
    		}// Affichage du monde
    		affCentre();
     
    		panel.add(panelCenter,BorderLayout.CENTER);
    		panelCenter.setBackground(panel.getBackground());
     
    		/* Menu : ( West ) */
    		JPanel panelWest = new JPanel();
    		panelWest.setLayout(new BoxLayout(panelWest,BoxLayout.Y_AXIS));
    		panel.add(panelWest,BorderLayout.WEST);
    		panelWest.setBackground(panel.getBackground());
     
    		/* Options : ( East ) */
    		JPanel panelEast = new JPanel();
    		panelEast.setLayout(new BoxLayout(panelEast,BoxLayout.Y_AXIS));
    		panelEast.add(txtTchat);
    		JButton bt_Dire = new JButton("Dire");
    		bt_Dire.addActionListener(this);
    		panelEast.add(bt_Dire);
    		lbTchat = new JLabel();
    		trdTchat = new Tchat(lbTchat);
    		trdTchat.start();
    		panelEast.add(lbTchat);
    		panel.add(panelEast,BorderLayout.EAST);
    		panelEast.setBackground(panel.getBackground());
     
    		// Relation
    		txtTchat.addKeyListener(this);
    		// Affichage
    		fenaitre.setVisible(true);
    	}
    	/** Affichages **/
    	/*
    	 * Calcul/Recalcul le tableaux de la carte
    	 */
    	private void affCentre(){
    		panelCenter.setLayout(new GridLayout(carte.getSizeY(),carte.getSizeX()));
    		for (int y=0 ; y < carte.getSizeY() ; y++ ){
    			for (int x=0 ; x < carte.getSizeX() ; x++ ){
    				if ( carte.getCase(x, y) != null ){
    					if ( carte.getCase(x, y).getImg() != null )
    						monde[x][y].setIcon( carte.getCase(x, y).getImg() );
    					else{
    						monde[x][y].setIcon( null );
    						monde[x][y].setText( new Integer(carte.getCase(x, y).getObstacle()).toString() );
    					}
    				}else{
    					monde[x][y].setIcon( null );
    					monde[x][y].setText("?");
    				}
    				monde[x][y]
    				         .setToolTipText("Position : ("
    				        		 +(carte.getPosiX()-7+x)+","
    				        		 +(carte.getPosiY()+7-y)+")");
    			}
    		}
    		//panelCenter.repaint();
    		//fenaitre.repaint();
    	}
    	public synchronized void miseAJour(){
    		affCentre();
    	}
    	/** Interface **/
    	public void actionPerformed(ActionEvent e) {
    		if ( e.getActionCommand()=="Dire" ){
    			trdTchat.dire(txtTchat.getText());
    			txtTchat.setText("");
    		}else
    			System.err.println(e.getActionCommand());
    	}
    	public void keyTyped(KeyEvent e) {
    	}
     
    	public void keyReleased(KeyEvent e) {
    	}
    	public void keyPressed(KeyEvent e) {
    		if (e.getKeyCode() == KeyEvent.VK_ENTER ){
    			trdTchat.dire(txtTchat.getText());
    			txtTchat.setText("");
    		}
    	}
     
    	/* Classe interne pour la gestion des cliques sur la carte */
    	class ActCase extends AbstractAction{
    		private int x;
    		private int y;
    		public ActCase(int x,int y){
    			this.x=x;
    			this.y=y;
    		}
    		/* Gestion des cliques sur la carte : */
    		public void actionPerformed(ActionEvent e){
    			if ( carte.getCase(x,y) == null )
    				return;
    			if ( carte.getCase(x,y).getObstacle() <= 1)// Déplacement
    				carte.mov(x-7, -y+7);
    			else if ( carte.getCase(x,y).getObstacle() == 3)// Monstre
    				monde[x][y].setIcon( new ImageIcon("img/attaque.gif") );
    		}
    	}
    	/** Accesseur **/
     
     
     
    	/** Testeur **/
    	public static void main(String[] args){
    		new FrameJDR( );
    	}
    }

Discussions similaires

  1. [Tableaux] Récupéré un image via url
    Par Blo0d4x3 dans le forum Langage
    Réponses: 1
    Dernier message: 11/06/2006, 21h27
  2. Réponses: 10
    Dernier message: 20/03/2006, 16h11
  3. Afficher une image sans URL dans un forum
    Par Vanesse dans le forum Mode d'emploi & aide aux nouveaux
    Réponses: 2
    Dernier message: 01/03/2006, 17h55
  4. Réponses: 1
    Dernier message: 31/10/2005, 09h33
  5. Réponses: 4
    Dernier message: 07/10/2004, 15h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo