The project stop when arriving at the red sector, can someone please help me how to solve the problem
a friend told me that i have another thread in another file in the project so how can i fix it.... HELP
if you need the main project i can send it to you....
package snake;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Fenetre.java
*
* Created on May 30, 2011, 6:27:25 PM
*/
/**
*
* @author Hp
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.KeyStroke;
public class Fenetre extends JFrame implements Runnable {
private Carré Objectif=new Carré(0,0,20);
private Serpent Snake=new Serpent('X');
private PlateauJeu PlateauJeu1;
private JLabel LabelScore=new JLabel("SCORE: 0");
private JMenuBar MenuPrincipale=new JMenuBar();
private JMenu MenuFichier=new JMenu("Fichier"),
MenuAide=new JMenu("Aide"),
Vitesse=new JMenu("Vitesse");// , encore Jmenu
private JMenuItem NouveauJeu=new JMenuItem("Nouveau Jeu"),
Pause=new JMenuItem("Pause"),
Quiter=new JMenuItem("Quiter"),
Control=new JMenuItem("Controle"),
Apropos=new JMenuItem("À propos?");
private JOptionPane Information=new JOptionPane();
private JRadioButtonMenuItem TLent=new JRadioButtonMenuItem("Trés lente"),
Lent=new JRadioButtonMenuItem("Lente"),
Moyenne=new JRadioButtonMenuItem("Moyenne"),
Rapide=new JRadioButtonMenuItem("Rapide"),
TRapide=new JRadioButtonMenuItem("Trés rapide");
private int vitesse=200,Score=0;
private boolean pause=false; // true or false
char direction;
public Fenetre(){
this.setTitle("Snake");
this.setLocation(200,30);
this.setSize(630,700);
this.setResizable(false);
this.setVisible(true);
Menu();//
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
RandObjectif();//?
PlateauJeu1=new PlateauJeu(Snake,Objectif);
this.add(PlateauJeu1,BorderLayout.CENTER);
LabelScore.setBorder(BorderFactory.createBevelBord er(1));
LabelScore.setFont(new Font("Arial",Font.BOLD,20));
LabelScore.setForeground(Color.PINK);
this.add(LabelScore,BorderLayout.SOUTH);
this.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
public void keyPressed(KeyEvent arg0) {
// TODO Auto-generated method stub
if(Snake.getDirection()!='x')
{if(arg0.getKeyCode()==38&&Snake.getDirection()!=' B')
{Snake.setDirection('H');Jouer(0);}
if(arg0.getKeyCode()==40&&Snake.getDirection()!='H ')
{Snake.setDirection('B');Jouer(0);}
if(arg0.getKeyCode()==39&&Snake.getDirection()!='G ')
{Snake.setDirection('D');Jouer(0);}
if(arg0.getKeyCode()==37&&Snake.getDirection()!='D '&&Snake.getDirection()!='X')
{Snake.setDirection('G');Jouer(0);}
}
}
});
//throw new UnsupportedOperationException("Not supported yet.");
Start();
}
public void RandObjectif(){
Random Rand=new Random();
int IndexX=Rand.nextInt(28);
int IndexY=Rand.nextInt(28);
Objectif.setX(IndexX*20);
Objectif.setY(IndexY*20);
for(Carré T:Snake.getSuit())
if(IndexX*20==T.getX()&&IndexY*20==T.getY()){
this.RandObjectif();
}
if(IndexX*20==Snake.getTete().getX()&&IndexY*20==S nake.getTete().getY()){
this.RandObjectif();
}
}
public void Start(){
while(true){
Jouer(5);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@SuppressWarnings("static-access")
public void Jouer(int a){
if((Snake.getTete().getX()==Objectif.getX())&&(Sna ke.getTete().getY()==Objectif.getY()))
{Snake.AjouterCarré();RandObjectif();Score+=10;
LabelScore.setText("SCORE: "+Score);
}
else if(a!=0)Snake.AvancerSerpent();
for(Carré T:Snake.getSuit())
if(Snake.getTete().getX()==T.getX()&&Snake.getTete ().getY()==T.getY()){
System.out.println("GAME OVER");
Information.showMessageDialog(null,"Game Over\nCliquez sur OK pour recommencer","Information",JOptionPane.INFORMATION _MESSAGE);
Snake.Réinitialiser();Score=0;LabelScore.setText(" SCORE: 0");break;
}//eza fetit be hala
if(Snake.getTete().getX()<0||Snake.getTete().getX( )>20*30-40||Snake.getTete().getY()<0||Snake.getTete().getY ()>20*30-40)
{System.out.println("GAME OVER");
Information.showMessageDialog(null,"Game Over\nCliquez sur OK pour recommencer","Information",JOptionPane.INFORMATION _MESSAGE);
Snake.Réinitialiser();Score=0;LabelScore.setText(" SCORE: 0");}
//eza fetit bel het
PlateauJeu1.repaint();
}
public void Menu(){
MenuPrincipale.add(MenuFichier);
MenuPrincipale.add(MenuAide);
MenuFichier.add(NouveauJeu);
MenuFichier.add(Pause);
Pause.setAccelerator(KeyStroke.getKeyStroke('p'));
MenuFichier.add(Vitesse);
MenuFichier.addSeparator();
MenuFichier.add(Quiter);
MenuAide.add(Control);
MenuAide.add(Apropos);
this.setJMenuBar(MenuPrincipale);
ButtonGroup BG=new ButtonGroup();
BG.add(TLent);BG.add(Lent);BG.add(Moyenne);BG.add( Rapide);
BG.add(TRapide);
Moyenne.setSelected(true);
//ba3mil add lal button l khala2toun fo2
Vitesse.add(TLent);Vitesse.add(Lent);Vitesse.add(M oyenne);
Vitesse.add(Rapide);Vitesse.add(TRapide);
TLent.addActionListener(new VitesseListener());
Lent.addActionListener(new VitesseListener());
Moyenne.addActionListener(new VitesseListener());
Rapide.addActionListener(new VitesseListener());
TRapide.addActionListener(new VitesseListener());
NouveauJeu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
Score=0;LabelScore.setText("SCORE: 0");
Snake.Réinitialiser();
}
});
Quiter.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
System.exit(0);
}
});
Control.addActionListener(new ActionListener() {
@SuppressWarnings("static-access")
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
Information.showMessageDialog(null,"Haut -> déplacez en haut\nBas -> déplacez en Bas\nDroite -> déplacez à droite\nGauche -> déplacez à gauche\n p -> Pause","Information",JOptionPane.INFORMATION_MESSA GE);
}
});
Apropos.addActionListener(new ActionListener() {
@SuppressWarnings("static-access")
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
Information.showMessageDialog(null,"Réaliser par:\n Rowana Bejjani \n INF101606","Information",JOptionPane.INFORMATION_M ESSAGE);
}
});
Pause.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
if(pause){Snake.setDirection(direction);pause=fals e;}
else{direction=Snake.getDirection();Snake.setDirec tion('x');pause=true;}
}
});
}
public void run() {
throw new UnsupportedOperationException("Not supported yet.");
}
class VitesseListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
if(arg0.getSource()==TLent) vitesse=1000;
if(arg0.getSource()==Lent) vitesse=500;
if(arg0.getSource()==Moyenne) vitesse=200;
if(arg0.getSource()==Rapide) vitesse=100;
if(arg0.getSource()==TRapide) vitesse=20;
}
}
public static void main (String[] args) {
// TODO Auto-generated method stub
new Fenetre();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
setName("Form"); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify
// End of variables declaration
}
