Bonjour à tous,

Voilà, je suis vraiment débutant avec les JInternalFrame et je n'arrive absolument pas à faire ce que je veux.

J'ai une JFrame appelé Game pour mon jeu et dedans il y a un JPanel pour afficher la map est autorisé l'utilisateur à déplacer son personnage. J'aimerai que quand il appuie sur échap, une JInternalFrame apparaisse pour afficher les différentes options possible.

Je ne sais absolument pas ce que devrais être mon container (JLayeredPane ou JDesktopPane) et je ne sais pas quoi ajouté dans quoi.

Je suis arrivé au bout de code si dessous qui fonctionne à moitié, c'est à dire qu'il n'affiche ma JInternalFrame qui si le JPanel n'est pas affiché, je n'arrive pas à dessiner la JInternalFrame par dessus le JPanel.

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
package com.game;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
 
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
 
import com.game.fight.FightPanel;
import com.map.Map;
import com.map.celladd.MonsterTile;
import com.personnage.hero.Hero;
import com.personnage.monster.Monster;
 
final public class Game extends JFrame implements Serializable, Runnable{
 
	private static final long serialVersionUID = 1L;
	private JDesktopPane container = new JDesktopPane();
 
	private static Hero perso;
 
	private Map map;
 
	private MapPanel mapPanel;
 
	private boolean north = false;
	private boolean south = false;
	private boolean east = false;
	private boolean west = false;
 
	private Thread main = new Thread(this);
 
	private final void windowConfiguration(){
		this.setUndecorated(true);
		this.setExtendedState(Game.MAXIMIZED_BOTH);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setBackground(Color.BLACK);
		this.setContentPane(container);
		this.setLayout(new BorderLayout(0, 0));
 
		this.setVisible(true);
 
		support.File supportFile = new support.File();
		supportFile.setIcon("/media/logo.png", this);
 
		container.setPreferredSize(this.getSize());
	}
 
	private final void index(){		
		perso.inFight = false;
		this.map = new Map("main");
 
		mapPanel = new MapPanel(this.map, perso, getSize().width, getSize().height);
		this.addKeyListener(new GameListener());
 
		Thread map = new Thread(mapPanel);
		map.start();
 
		container.setPreferredSize(new Dimension(getSize().width, getSize().height));
		container.setBackground(Color.BLACK);
		container.add(mapPanel);
 
		main.start();
	}
 
	public Game(Hero hero){
		hero.addLife((int)(Math.round(-0.7 * hero.getAllMaxLife())));
		hero.addMana((int)(Math.round(-0.7 * hero.getAllMaxMana())));
		Game.perso = hero;
 
		windowConfiguration();
 
		index();
	}
 
	public Game(Hero hero, String str){
		Game.perso = hero;
 
		windowConfiguration();
 
		index();
	}
 
	/**
         * Save the game with serialize
         */
	private final void save(){
		File folder = new File("saves/" + perso.getName().toLowerCase());
		if(!folder.exists()){
			folder.mkdirs();
		}
		ObjectOutputStream oos;
		File hero = new File(folder.getPath() + "/hero.txt");
		//File world = new File(folder.getPath() + "/world.txt");
		try{
			oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(hero)));
			oos.writeObject(perso);
			oos.close();
			//oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(world)));
			//oos.writeObject(map);
			//oos.close();
		}catch(FileNotFoundException e){
			e.printStackTrace();
		}catch(IOException e){
			e.printStackTrace();
		}
	}
 
	/**
         * Check if the Hero is close to a monster and starts a fight
         */
	private final void checkFight(){
		for(int x = -3; x <= 3; x++){
			for(int y = -3; y < 3; y++){if(Math.abs(x) + Math.abs(y) <= 3 && map.getCellAdd(perso.x + x, perso.y + y) instanceof MonsterTile){
				MonsterTile mt = (MonsterTile)map.getCellAdd(perso.x + x, perso.y + y);
				fight(mt.getMonster(), perso.x + x, perso.y + y);
				return;
			}}
		}
 
	}
 
	/**
         * Starts the fight
         */
	@SuppressWarnings("deprecation")
	private final void fight(Monster monster, int x, int y){
		north = south = east = west = false;
		perso.inFight = true;
		container.remove(mapPanel);
		mapPanel.setFocusable(false);
		mapPanel.stopMusic();
		FightPanel gamePanel = new FightPanel(perso, monster, map, getSize().width, getSize().height, mapPanel.xView, mapPanel.yView);
		gamePanel.setBounds(0, 0, getSize().width, getSize().height);
 
		Thread game = new Thread(gamePanel);
		game.start();
 
		container.add(gamePanel);
		gamePanel.requestFocus();
		container.repaint();
 
		while(perso.alive() && monster.alive()) try{Thread.sleep(33);}catch(InterruptedException e){e.printStackTrace();}
		try{ Thread.sleep(500); }catch(InterruptedException e){ e.printStackTrace(); }
		game.stop();
		perso.inFight = false;
		container.remove(gamePanel);
		gamePanel.setFocusable(false);
 
		if(perso.alive()){
			double goldGained = (monster.getGold() * 0.9) + (Math.random() * (monster.getGold() * 1.1 -  monster.getGold() * 0.9 + 1));
			goldGained = Math.round(goldGained * 100);
			goldGained /= 100;
			perso.addXp(monster.getXp());
			perso.addGold(goldGained);
			map.removeCellAdd(x, y);
		}else{
			perso.x = 253;
			perso.y = 425;
			perso.revive();
		}
 
		mapPanel.setHero(perso);
		container.add(mapPanel);
		mapPanel.setFocusable(true);
		mapPanel.startMusic();
		mapPanel.requestFocus();
		mapPanel.build(0, 0);
		container.repaint();
	}
 
	private class GameListener implements KeyListener{
 
		@Override
		public void keyPressed(KeyEvent e){
			if(e.getKeyCode() == 27){
				JInternalFrame jif = new JInternalFrame("Options", false, true, false);
				jif.setSize(new Dimension(400, 600));
				jif.setMaximumSize(new Dimension(400, 600));
				jif.setMinimumSize(new Dimension(400, 600));
				jif.setPreferredSize(new Dimension(400, 600));
				jif.setLocation(200, 200);
				jif.setVisible(true);
				jif.show();
				container.add(jif);
				jif.show();
				container.repaint();
				repaint();
				//System.exit(0);
			}
 
			else if(e.getKeyCode() == 32) save();
			else if(e.getKeyCode() == Options.moveFoward && !south && !west && !east) north = true;
			else if(e.getKeyCode() == Options.moveRight && !west && !south && !north) east = true;
			else if(e.getKeyCode() == Options.moveLeft && !east && !south && !north) west = true;
			else if(e.getKeyCode() == Options.moveBackward && !north && !west && !east) south = true;
		}
 
		@Override
		public void keyReleased(KeyEvent e){
			if(e.getKeyCode() == Options.moveFoward)		north = false;
			else if(e.getKeyCode() == Options.moveRight)	east = false;
			else if(e.getKeyCode() == Options.moveLeft)		west = false;
			else if(e.getKeyCode() == Options.moveBackward)	south = false;
		}
 
		@Override
		public void keyTyped(KeyEvent e){}		
 
	}
 
 
	@Override
	public void run(){
		long time = System.nanoTime();
		for(;;){
			if(!perso.inFight){
				if(System.nanoTime() - time > 1e9){
					perso.regen();
					time = System.nanoTime();
				}
				checkFight();
				mapPanel.state();
				if(north && perso.y > 0) mapPanel.build(0, -1);
				else if(south && perso.y < mapPanel.nbTileY - 1) mapPanel.build(0, 1);
				else if(west && perso.x > 0) mapPanel.build(-1, 0);
				else if(east && perso.x < mapPanel.nbTileX - 1) mapPanel.build(1, 0);
				else try{Thread.sleep(10);}catch(InterruptedException e){}
			}
		}
	}
 
}
Merci d'avance pour votre aide, si vous avez besoin de détails au niveau de mon code n'hésiter pas à me demander.
Si vous avez des suggestions à propos de monde code sur quelques choses qui sont pour vous mal faite faisans en part s'il vous plait cela m'aidera

Merci d'avance.