Merci de votre temps..
voici mon probleme...
Dans le menu AIDE, les joueurs peuvent à tout moment afficher les règles du jeu ainsi que les informations concernant l'application Sudoku.
Je dois afficher les messages d'intro et de bienvenue a partir d'un fichier .jpeg
voici le code qui marche lorsque je l'appel de mon interface
voici interface
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 public class window extends JWindow { ImageIcon imRegles = new ImageIcon("images\\regle.jpg"); ImageIcon imIntro = new ImageIcon("images\\intro.jpg"); static Thread t = new Thread(); static int thread = 0; static JButton bouton; int X; int Y; /* Parametres du constructeur : X, Y: taille de la fenetre :) type: 1-> Intro, 2->regles */ public window(int X,int Y,int type) { //super(); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); setSize(X,Y); setLocation( (dim.width - X)/2 , (dim.height - Y)/2); setVisible(true); Container fen = getContentPane(); show(); /* Si c'est une fenetre d'intro,on ne l'affiche que 6 secondes */ if( type == 1 ) { setSize(275,150); bouton = new JButton(imIntro); fen.add( bouton); bouton.setVisible( true ); show(); try { t.sleep(4000); thread = 1; } catch( java.lang.InterruptedException ex ) { JOptionPane.showMessageDialog(null, "erreur"); } dispose(); } /* fenetre de regles,on ne la ferme que quand l'utilisateur clique */ else { setSize(900,650); JOptionPane.showMessageDialog(fen,(bouton = new JButton(new ImageIcon("images\\regle.jpg"))),"Les regles du sudoku", JOptionPane.INFORMATION_MESSAGE); setVisible(true); } } }
voici le menu ou le probleme d'affichage du menu aide soit m541 et m542
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 import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import javax.swing.*; public class Interface extends JFrame { // Variables declaration JPanel contentPanel; Sudoku sudoku; Fond supanel; //Ecouteur et Presse-Papier Ecouteur ecouteur; ModifPressPap mpp; FileLogger file; Menu menu; //Tableaux pour les chiffres Image[] nbplaces=new Image[9]; Image[] nbdispo=new Image[9]; //IMAGE JPANEL Image map=new ImageIcon("images/sudoku.png").getImage(); Image digi=new ImageIcon("images/digits.gif").getImage(); BufferedImage mapmodifiable= toBufferedImage(map); BufferedImage digits= toBufferedImage(digi); int carre=30; public Interface() { super(); this.setVisible(false); file=new FileLogger(this, "sudoku.txt"); file.repertoire(); //LANCEMENT DE SUDOKU ET MISE EN DAEMON this.sudoku=new Sudoku(9); sudoku.setPriority(Thread.MAX_PRIORITY); sudoku.start(); initializeComponent(); creationdigits(); this.setVisible(true); } public void creationdigits(){ int indice=0; for(int i=0;i<=digits.getHeight()-(carre-1);i+=(carre-1)){ nbplaces[indice]=digits.getSubimage(29, i, carre-1, carre-1); nbdispo[indice]=digits.getSubimage(0, i, carre-1, carre-1); indice++; } } private void initializeComponent() { //CONTENTPANEL contentPanel = (JPanel)this.getContentPane(); contentPanel.setLayout(new GridBagLayout()); //SUDOKUPANEL supanel=new Fond(map, this); //MENU menu=new Menu(this); this.setJMenuBar(menu); //ECOUTEUR ET PRESSEPAPIER ecouteur=new Ecouteur(this); mpp = new ModifPressPap(); GridBagConstraints c=new GridBagConstraints(); c.gridx = 0; c.gridy = 1; c.gridwidth=1; c.gridheight=1; c.weightx=100; c.weighty=100; c.fill=GridBagConstraints.NONE; c.ipadx=0; c.ipady=0; contentPanel.add(supanel,c); this.setFocusable(true); this.addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent e) { int caract = e.getKeyCode(); switch (caract) { case KeyEvent.VK_1 : ecouteur.chiffre(1); break; case KeyEvent.VK_2 : ecouteur.chiffre(2); break; case KeyEvent.VK_3 : ecouteur.chiffre(3); break; case KeyEvent.VK_4 : ecouteur.chiffre(4); break; case KeyEvent.VK_5 : ecouteur.chiffre(5); break; case KeyEvent.VK_6 : ecouteur.chiffre(6); break; case KeyEvent.VK_7 : ecouteur.chiffre(7); break; case KeyEvent.VK_8 : ecouteur.chiffre(8); break; case KeyEvent.VK_9 : ecouteur.chiffre(9); break; case KeyEvent.VK_DELETE : ecouteur.chiffre(0); break; } } }); this.setContentPane(contentPanel); this.setLocation(new Point(350,350)); this.setTitle("Sudoku Bienvenu à l'école Saint Pruneau"); this.setResizable(false); this.setSize(new Dimension(540, 405)); } public BufferedImage toBufferedImage(Image image) { /** On test si l'image n'est pas déja une instance de BufferedImage */ if( image instanceof BufferedImage ) { /** cool, rien à faire */ return( (BufferedImage)image ); } else { /** On s'assure que l'image est complètement chargée */ image = new ImageIcon(image).getImage(); /** On crée la nouvelle image */ BufferedImage bufferedImage = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB ); Graphics g = bufferedImage.createGraphics(); g.drawImage(image,0,0,null); g.dispose(); return( bufferedImage ); } } public static void main(String[] args) { window fenetreintro = new window(500,550,1); //INTERFACE GRAPHIQUE Interface graphique=new Interface(); graphique.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0);} }); } public Fond getSupanel() { return supanel; } public Image getNbdispo(int i) { return nbdispo[i]; } public Image getNbplaces(int i) { return nbplaces[i]; } public Sudoku getSudoku() { return sudoku; } public void setSudoku(Sudoku sudoku) { this.sudoku = sudoku; } public ModifPressPap getMpp() { return mpp; } /** * @return Renvoie contentPanel. */ public JPanel getContentPanel() { return contentPanel; } /** * @param contentPanel contentPanel à définir. */ public void setContentPanel(JPanel contentPanel) { this.contentPanel = contentPanel; } }
merci de votre temps
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 public class Menu extends JMenuBar implements ActionListener{ Interface map; JMenu m1; JMenu m2; JMenu m3; JMenu m4; JMenu m5; JMenuItem m12; JMenuItem m121; JMenuItem m122; JMenuItem m123; JMenuItem m222; JMenuItem m331; JMenuItem m332; JMenuItem m441; JMenuItem m442; JMenuItem m541; JMenuItem m542; public Menu(Interface map){ super(); this.map=map; m1 = new JMenu("Nouvelle grille"); m2 = new JMenu("Solutionner Grille"); m3 = new JMenu("Générer une grille"); m4 = new JMenu("Fonctions supplémentaires"); m5 = new JMenu("Aide"); m121 = new JMenuItem("Niveau fort"); m122 = new JMenuItem("Niveau moyen"); m123 = new JMenuItem("Niveau faible"); m12 = new JMenuItem("Sélectionner dans une liste"); m121.addActionListener(this); m122.addActionListener(this); m123.addActionListener(this); m12.addActionListener(this); m222 = new JMenuItem("Vider la Grille"); m222.addActionListener(this); m1.add(m222); m331 = new JMenuItem("Afficher la solution"); m331.addActionListener(this); m2.add(m331); m332 = new JMenuItem("Cacher la solution"); m332.addActionListener(this); m2.add(m332); m332.setEnabled(false); m441 = new JMenuItem("Copier grille dans le presse-papier"); m441.addActionListener(this); m4.add(m441); m442 = new JMenuItem("Imprimer Grille+Solution"); m442.addActionListener(this); m4.add(m442); m541 = new JMenuItem("intro"); m541.addActionListener(this); m5.add(m541); m542 = new JMenuItem("Affiche les regles"); m542.addActionListener(this); m5.add(m542); m3.add(m121); m3.add(m122); m3.add(m123); m3.addSeparator(); m3.add(m12); m5.add(m541); m5.add(m542); // m5.addSeparator(); this.add(m1); this.add(m2); this.add(m3); this.add(m4); this.add(m5); //PERMET DE DESACTIVER CERTAINS ELEMENTS PAR DEFAUT } public void actionPerformed(ActionEvent evt){ //PERMET D'eviter une ecriture de chiffre par erreur map.ecouteur.carre=null; if(evt.getSource()==m121){ map.supanel.testersinouvellegrille(); map.supanel.selection(3); } if(evt.getSource()==m122){ map.supanel.testersinouvellegrille(); map.supanel.selection(2); } if(evt.getSource()==m123){ map.supanel.testersinouvellegrille(); map.supanel.selection(1); } if(evt.getSource()==m222){ map.supanel.vidergrille(); map.supanel.cherchernouvellesgrilles(); } if(evt.getSource()==m331){ if(map.supanel.solutionnergrille()){ m331.setEnabled(false); m332.setEnabled(true); } if(evt.getSource()==m332){ map.supanel.cachersolution(); m331.setEnabled(true); m332.setEnabled(false); } if(evt.getSource()==m541){ window imIntro = new window(500,550,1); Interface graphique=new Interface(); graphique.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) {System.exit(0);}}); //map.supanel.window(); } if(evt.getSource()==m542){ window imRegles = new window(500,550,2); //INTERFACE GRAPHIQUE Interface graphique=new Interface(); graphique.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) {System.exit(0);}}); // map.supanel.window(500,550,2); } if(evt.getSource()==m441){ if(map.getSudoku().getTableaufinal()!=null){ ecriturepressepapier(map.getSudoku().getTableaufinal()); } else if(evt.getSource()==m442){ ecriturepressepapier(map.getSudoku().getGrille()); } } //IMPRESSION if(evt.getSource()==m442){ JFrame frame=new JFrame("Aperçu avant Impression"); frame.setSize(new Dimension(400,400)); Fond supanelreponse1=new Fond(map.map,map); Fond supanelreponse2=new Fond(map.map,map); supanelreponse1.impressionapartirdetableau(map.sudoku.grille); if(map.supanel.solutionnergrille()){ System.out.println("GRILLE"); map.sudoku.afficher(map.sudoku.grille); System.out.println("REPONSE"); map.sudoku.afficher(map.sudoku.tableaufinal); supanelreponse2.impressionapartirdetableau(map.sudoku.tableaufinal); //CONTENTPANEL JPanel contentPanel = (JPanel)frame.getContentPane(); contentPanel.setLayout(null); supanelreponse1.setBounds(0,0,600,600); contentPanel.add(supanelreponse1); supanelreponse2.setBounds(0,601,600,600); contentPanel.add(supanelreponse2); frame.setContentPane(contentPanel); frame.setVisible(true); MPanelPrinter mp=new MPanelPrinter(contentPanel); mp.print(); map.supanel.cachersolution(); frame.dispose(); map.requestFocus(); }}}} public void ecriturepressepapier(int[][] tableau){ String temp=""; for(int i=0;i<tableau.length+2;i++){ temp+="#"; } temp+="\n"; for(int i=0;i<tableau.length;i++){ temp+="#"; for(int e=0;e<tableau[i].length;e++){ if(tableau[i][e]!=0){ temp+=Integer.toString(tableau[i][e]); } else{ temp+=" "; } } temp+="#\n"; } for(int i=0;i<tableau.length+2;i++){ temp+="#"; } map.getMpp().setClipboardContents(temp); }}
Partager