Aide eclipse bouton
Fermé
shedir
Messages postés
3
Date d'inscription
samedi 28 mai 2016
Statut
Membre
Dernière intervention
29 mai 2016
-
Modifié par KX le 28/05/2016 à 18:44
KX Messages postés 16755 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 12 février 2025 - 29 mai 2016 à 14:36
KX Messages postés 16755 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 12 février 2025 - 29 mai 2016 à 14:36
A voir également:
- Aide eclipse bouton
- Eclipse download - Télécharger - Langages
- Bouton reinitialisation pc - Guide
- Réinitialiser chromecast sans bouton - Guide
- Bouton on/off comment savoir ✓ - Forum Matériel & Système
- Comment débloquer un bouton enfoncé - Forum Samsung
3 réponses
KX
Messages postés
16755
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
12 février 2025
3 020
28 mai 2016 à 18:47
28 mai 2016 à 18:47
Bonjour,
Pour t'aider il nous faudrait le code complet pour tester chez nous.
Là il manque au moins les classes Fenetre, Affichage et Image.
Pour t'aider il nous faudrait le code complet pour tester chez nous.
Là il manque au moins les classes Fenetre, Affichage et Image.
shedir
Messages postés
3
Date d'inscription
samedi 28 mai 2016
Statut
Membre
Dernière intervention
29 mai 2016
29 mai 2016 à 12:01
29 mai 2016 à 12:01
Je te remercie, j'ai trouvé la solution à ce problème, maintenant j'ai un autre soucis, je dois crée une class qui mélange automatiquement le jeu taquin pour pouvoir lancer le jeu, sauf que je ne sais pas du tout par ou commencer. Je t'envoie les autres programmes si jamais tu as le temps :
Programme Fenetre :
Programme Image :
Programme affichage :
Programme Fenetre :
package BaseProjet;
import javax.swing.JFrame;
public class Fenetre extends JFrame {
private static final long serialVersionUID = 1L;
//----------------------------//
// CONSTRUCTEUR DE LA FENETRE //
//----------------------------//
public Fenetre(String titre,int l,int h,int t){
// TITRE DE LA FENETRE
this.setTitle(titre);
// LARGEUR DE FENETRE = NOMBRE DE CASE EN LARGEUR * TAILLE D'UNE CASE + BORDURE FENTRE DE 7 PIXELS
this.setSize(l*t, h*t);
// LA TAILLE DE LA FENETRE EST FIXE
this.setResizable(false);
// FENETRE AU MILIEU DE L'ECRAN
this.setLocationRelativeTo(null);
// ACTION DE LA "CROIX"
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//public paint(Graphics g){
// g.drawLine(0, 0, 100, 100);
}
}
Programme Image :
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class Image extends JPanel {
//------------------------------------------//
// ATTRIBUS //
//------------------------------------------//
/**
- */ private static final long serialVersionUID = 1L; private int l,h; //------------------------------------------// // CONSTRUCTEUR DE L'AFFICHAGE // //------------------------------------------// public Image(Fenetre UneFenetre, int largeur, int hauteur, int taille) { // INITIALISATION DES CARACTERISTIQUES DU JEU this.l=largeur*taille; this.h=hauteur*taille; // ASSOCIER CE PANNEAU A LA FENETRE UneFenetre.setContentPane(this); } public void paintComponent(Graphics g){ super.paintComponent(g); ImageIcon image; image = new ImageIcon ("00.jpg") ; g.drawImage (image.getImage(),0, 0,l,h,null); } }
Programme affichage :
package BaseProjet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.Random;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import java.awt.event.ActionEvent;
public class Affichage extends JPanel implements ActionListener,MouseMotionListener, MouseListener, KeyListener {
//------------------------------------------//
// ATTRIBUS //
//------------------------------------------//
/**
- */ private static final long serialVersionUID = 1L; private int l,h,t; // NOMBRE DE CASES EN LARGEUR ET HAUTEUR ET TAILLE private int x=2,y=2; // POSITION DU PERSONNAGE DANS LE TABLEAU private int[][] c; // TABLEAU private int xm; // ABSCISSE DU CLICK private int ym; // ORDONNEE DU CLICK private boolean click; // ETAT DU CLICK private Color LesCouleurs[]=new Color[10]; // 10 ELEMENTS //------------------------------------------// // CONSTRUCTEUR DE L'AFFICHAGE // //------------------------------------------// public Affichage(Fenetre UneFenetre, int largeur, int hauteur, int taille) { // INITIALISATION DES CARACTERISTIQUES DU JEU this.l=largeur; this.h=largeur; this.t=taille; this.c=new int[l][h]; // NUMEROTER LES CASES for (int j=0;j<this.h;j++) for (int i=0;i<this.h;i++) this.c[i][j]=3*j+i+1; //------------------------------------------// // COULEUR DES ELEMENTS DU JEU // //------------------------------------------// Random randomGenerator = new Random(); LesCouleurs[0]=new Color(0,0,0); for (int i=1;i<this.h*this.l;i++) LesCouleurs[i]=new Color(2*randomGenerator.nextInt(100), 2*randomGenerator.nextInt(100), 2*randomGenerator.nextInt(100)); // ASSOCIER CE PANNEAU A LA FENETRE UneFenetre.setContentPane(this); // ECOUTER LA SOURIS ET LA CLAVIER addMouseMotionListener(this); addMouseListener(this); setFocusable(true);} public void paintComponent(Graphics g){ super.paintComponent(g); //---------------------------------------------// // REALISER UN DEPLACEMENT SI CLICK // //---------------------------------------------// if (this.click) Deplacement(Gestion()); // CONSOLE POUR VERIFICATION System.out.println(); for (int j=0;j<this.h;j++){ for (int i=0;i<this.h;i++) System.out.print(this.c[i][j]+" "); System.out.println(); } //-----------------------------------------------// // AFFICHAGE DU JEU SUR CONSOLE ET SUR GRAPHIQUE // //-----------------------------------------------// //System.out.println(); //System.out.println("Affichage du tableau ci-dessous:"); //System.out.println(); /*for (int j=0;j<this.h;j++){ for (int i=0;i<this.h;i++){ g.setColor(LesCouleurs[this.c[i][j]]); g.fillRect(i*this.t, j*this.t, this.t, this.t); } }*/ ImageIcon image[] = new ImageIcon[10]; for (int i=0;i<10;i++) image[i] = new ImageIcon ("0"+i+".jpg") ; for (int j=0;j<this.h;j++) for (int i=0;i<this.h;i++) if (c[i][j]!=9) g.drawImage (image[c[i][j]].getImage(),i*this.t, j*this.t,this.t, this.t, null); } private int Gestion() { //-----------------------------------------// // COMPARER LES COORDONNEES DE LA SOURIS // // ET CELLE DU PERSONNAGE PUIS RETOURNER // // UNE COMMANDE CLAVIER EN CONSEQUENCE // //-----------------------------------------// int commande = 0; if (this.xm==this.x+1 && this.ym==this.y) commande = 39; // DROITE if (this.ym==this.y+1 && this.xm==this.x) commande = 40; // BAS if (this.xm==this.x-1 && this.ym==this.y) commande = 37; // GAUCHE if (this.ym==this.y-1 && this.xm==this.x) commande = 38; // HAUT return commande; // PAS DE DEPLACEMENT}private void Deplacement(int code) { // MEMORISER LES COORDONNEES DU PERSONNAGE int xold=this.x; int yold=this.y; // MODIFIER LES COORDONNEES DU PERSONNAGE SI CELA EST POSSIBLE if (code==37 && this.x!=0) this.x--; if (code==38 && this.y!=0) this.y--; if (code==39 && this.x!=l-1) this.x++; if (code==40 && this.y!=h-1) this.y++; System.out.println(c[xold][yold]+"<->"+c[this.x][this.y]); int mem = c[this.x][this.y]; c[this.x][this.y]=c[xold][yold]; c[xold][yold]=mem; }public static void temporisation(int tempo){ try { Thread.sleep( tempo ) ; } catch (InterruptedException e) { e.printStackTrace(); }}public void keyPressed(KeyEvent e) { // REPEINDRE LE JEU repaint(); }/*Action de MouseMotionListener */ public void mousePressed(MouseEvent e) {}public void mouseReleased(MouseEvent e) {}public void mouseEntered(MouseEvent e) {}public void mouseExited(MouseEvent e) {}public void mouseDragged( MouseEvent e ) {}public void mouseClicked(MouseEvent e) { //-----------------------------------------// // RECUPERER LES COORDONNEES DE LA SOURIS // //-----------------------------------------// xm=e.getX()/this.t; ym=e.getY()/this.t;; click = true; repaint();}public void mouseMoved(MouseEvent e){}@Overridepublic void keyReleased(KeyEvent e) { // TODO Auto-generated method stub }@Overridepublic void keyTyped(KeyEvent e) { // TODO Auto-generated method stub }@Overridepublic void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub }}
shedir
Messages postés
3
Date d'inscription
samedi 28 mai 2016
Statut
Membre
Dernière intervention
29 mai 2016
29 mai 2016 à 14:27
29 mai 2016 à 14:27
Sympa ici les gens, toujours près à aider à ce que je vois...
KX
Messages postés
16755
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
12 février 2025
3 020
29 mai 2016 à 14:36
29 mai 2016 à 14:36
Bien sûr qu'on est prêt à aider, mais on a une vie aussi à côté, faire les exercices des autres ce n'est clairement pas intéressant !
Après avoir galéré à remettre ton code en forme (parce que copier-coller ce que tu as mis tout à l'heure ça marche pas) et exécuter le programme, on a deux fenêtres qui s'affichent complètement vides, donc pas le début de quoi que ce soit...
Commence par faire un code qui ressemble à quelque chose mets le en forme correctement avec les balises <code java></code> et on en reparle...
Après avoir galéré à remettre ton code en forme (parce que copier-coller ce que tu as mis tout à l'heure ça marche pas) et exécuter le programme, on a deux fenêtres qui s'affichent complètement vides, donc pas le début de quoi que ce soit...
Commence par faire un code qui ressemble à quelque chose mets le en forme correctement avec les balises <code java></code> et on en reparle...