Few questions to organize my game(How to create RTS?)

Hi everyone !!

Im here because I started a game, called Doode, its a kind of RTS and I approve that I’m a little bit lost.

For now, I have a game main, where i can select play, options, forum (which open IE) and exit.

I also have a graphic interface of game, with variable showing etc etc…

So, I’ll post all my classes and you’ll be fine to say me where I have to change code…

And last but no least, I want to better organize my classes, but I totally dunno how.

Please criticize my work :slight_smile:

Main class:

public class Main {

	
	public static void main(String[] args) {

		
		Menu m = new Menu("Doode - Menu");
	}

}

Menu class:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

@SuppressWarnings("serial")
public class Menu extends JFrame implements ActionListener {

	JLabel label; 
    JButton jbPlay = new JButton("", new ImageIcon("jouer.gif"));
	JButton jbClose = new JButton("", new ImageIcon("exit.gif"));
	JButton jbOptions = new JButton("", new ImageIcon("poptions.jpg"));
	JButton jbForum = new JButton("", new ImageIcon("forum.jpg"));
	
	
	

	public Menu (String titre) {                 //création de la méthode constructeur
		setTitle (titre);
		Container contenu = getContentPane();		

		
		

		jbPlay.setFocusPainted(false);
		jbPlay.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
		jbPlay.setContentAreaFilled(false);
jbPlay.addActionListener(this); 


		jbClose.setFocusPainted(false);
		jbClose.setBorderPainted(false);               // ces trois lignes sont les meme que la haut :)
		jbClose.setContentAreaFilled(false);
 jbClose.addActionListener(this); 
 
 
	jbOptions.setFocusPainted(false);
	jbOptions.setBorderPainted(false);               // ces trois lignes sont les meme que la haut :)
	jbOptions.setContentAreaFilled(false);
jbOptions.addActionListener(this); 


jbForum.setFocusPainted(false);
jbForum.setBorderPainted(false);               // ces trois lignes sont les meme que la haut :)
jbForum.setContentAreaFilled(false);
jbForum.addActionListener(this);
 
 
		contenu.setLayout(null);
		JLabel label = new JLabel();
		Image image = Toolkit.getDefaultToolkit().createImage("background.gif");// nouveau JLabel backgound
		label.setIcon(new ImageIcon(image));
		

		contenu.add(jbPlay, 0);
		contenu.add(jbClose, 1);
		contenu.add(jbOptions,2);
		contenu.add(jbForum,3);
		contenu.add(label, 4);
		
		label.setBounds(0, 0, 900, 800);
		jbPlay.setBounds(50, 445, 850, 78);
		jbClose.setBounds(50, 640, 158, 50);
		jbOptions.setBounds(75,230,144,65);
		jbForum.setBounds(678,370,212,80);
		
		
		
	
		setSize(907,832);
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setVisible(true);
	
		
	}

	public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();

if (source == jbPlay){
	Jeu j = new Jeu("Doode");
	dispose();}
	
else if(source == jbClose){
		System.out.print("Sa marche aussi");
		dispose(); }
		
else if (source == jbOptions){
	Options o = new Options();
	dispose();}
	
else if (source == jbForum){
		Forum f = new Forum();
	}
}
	}

jeu class:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;


		
@SuppressWarnings("serial")
public class Jeu extends JFrame implements MouseListener {

 
	public JButton barre1 = new JButton("", new ImageIcon("barre1.gif"));
	public JButton barre2 = new JButton("", new ImageIcon("barre2.gif"));
	public JButton barre3 = new JButton("", new ImageIcon("barre3.gif"));
	public JButton barre4 = new JButton("", new ImageIcon("barre4.gif"));
	public JButton champ1 = new JButton("", new ImageIcon("champ.png"));
	public JButton champ2 = new JButton("", new ImageIcon("champ.png"));
	public JButton rive = new JButton("", new ImageIcon("riviere.bmp"));
	
	public JComboBox Menu1 = new JComboBox();
	
	
	
	
	
	
	    // déclaration variables
	
            public int ClickX = 0;
            public int ClickY =0;
			public byte nombreDeDoodeVert=7;	
			public byte nombreDeDoodeBleu=8;
			public byte nombreDeDoodeRouge=4;
			public byte nombreDeDoodeJaune=4;
			public byte nombreEnnemis=75;
			public int nombreDeDoode=nombreDeDoodeVert+nombreDeDoodeBleu+nombreDeDoodeRouge+nombreDeDoodeJaune;
			public short doowatt=500;
			public short nourriture=500; // chercher un autre nom
			public short geleeNoire; // autre nom
			public short nombreEnnemisTues=0;
			public String pseudo;
			public Container contenu2;
			public JLabel fond;
	
			
			// Jeu
			
			public Jeu (String titre) {                 //création de la méthode constructeur
			setTitle (titre);
			Container contenu2 = getContentPane();	
			contenu2.addMouseListener(this);
	

			
		    JLabel BarreVert = new JLabel();
		    JLabel BarreBleu = new JLabel();
		    JLabel BarreRouge = new JLabel();
		    JLabel BarreJaune = new JLabel();
		    
		    
		    
			JLabel fond = new JLabel();
			
			contenu2.setLayout(null);
			Image image = Toolkit.getDefaultToolkit().createImage("map5.jpg");// nouveau JLabel backgound
			fond.setIcon(new ImageIcon(image));
			
			

			contenu2.add(BarreVert);
			BarreVert.setText(""+nombreDeDoodeVert);
			BarreVert.setBounds(98,2,20,20);
			BarreVert.setForeground(Color.white); 
			


			
			contenu2.add(BarreBleu);
			BarreBleu.setText(""+nombreDeDoodeBleu);
			BarreBleu.setBounds(292,2,20,20);
			BarreBleu.setForeground(Color.white);
			
			
			contenu2.add(BarreRouge);
			BarreRouge.setText(""+nombreDeDoodeRouge);
			BarreRouge.setBounds(492,2,20,20);
			BarreRouge.setForeground(Color.white);
			
			
			contenu2.add(BarreJaune);
			BarreJaune.setText(""+nombreDeDoodeJaune);
			BarreJaune.setBounds(676,2,20,20);
			BarreJaune.setForeground(Color.white);
			
			
			
			
	
			
			
			contenu2.add(barre1);
		    barre1.setBounds(5,5,190,55);
			barre1.setFocusPainted(false);
			barre1.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			barre1.setContentAreaFilled(false);
	        barre1.addMouseListener(this); 
	        
	        
	        contenu2.add(barre2);
		    barre2.setBounds(187,5,190,55);
			barre2.setFocusPainted(false);
			barre2.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			barre2.setContentAreaFilled(false);
	        barre2.addMouseListener(this);
	        
	        
	        contenu2.add(barre3);
		    barre3.setBounds(372,5,190,55);
			barre3.setFocusPainted(false);
			barre3.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			barre3.setContentAreaFilled(false);
	        barre3.addMouseListener(this);
	        
	        
	        contenu2.add(barre4);
		    barre4.setBounds(557,5,190,55);
			barre4.setFocusPainted(false);
			barre4.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			barre4.setContentAreaFilled(false);
	        barre4.addMouseListener(this);
	        
	        contenu2.add(champ1);
	        champ1.setBounds(1000,500,190,55);
			champ1.setFocusPainted(false);
			champ1.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			champ1.setContentAreaFilled(false);
	        champ1.addMouseListener(this);
	        
	        contenu2.add(champ2);
	        champ2.setBounds(250,800,190,55);
			champ2.setFocusPainted(false);
			champ2.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			champ2.setContentAreaFilled(false);
	        champ2.addMouseListener(this);
	        
	        contenu2.add(rive);
	        rive.setBounds(0,0,190,55);
			rive.setFocusPainted(false);
			rive.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			rive.setContentAreaFilled(false);
	        rive.addMouseListener(this);
	        
	        
			

			 contenu2.add(fond);
				fond.setBounds(0, 0, 1280, 1024);
	       
			
		
			setSize(1280,1024);
			setResizable(false);
			setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			setVisible(true);
			
			
		
			
		}


	

	
	


		
			public void mouseClicked(MouseEvent e) {	
				Object source = e.getSource();	
				if (source != barre1){

				ClickX = e.getX();
				ClickY = e.getY();
				System.out.print("\nla variable est à:"+ClickX+" et à "+ClickY);
				

				contenu2.add(Menu1);
				Menu1.setBounds(ClickX, ClickY,100,100);
				}
				
					
					
					}
					
							
			
			
			
		

		
		public void mouseEntered(MouseEvent arg0) {
			
			
		}

		
		public void mouseExited(MouseEvent arg0) {
		
			
		}

		
		public void mousePressed(MouseEvent Pressevt) {
		
				
			}
			
		

		
		public void mouseReleased(MouseEvent arg0) {

			
		}
	}


next one ---->

Options class:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;


@SuppressWarnings("serial")
public class Options extends JFrame implements ActionListener {

	JLabel label; 
    JButton jbMenu = new JButton("", new ImageIcon("menu.png"));
	
	

	public Options () {                 //création de la méthode constructeur
		setTitle ("Options");
		Container contenu3 = getContentPane();		

 
 
 
		contenu3.setLayout(null);
		JLabel label = new JLabel();
		Image image = Toolkit.getDefaultToolkit().createImage("fond.jpg");// nouveau JLabel backgound
		label.setIcon(new ImageIcon(image));
		
		
		jbMenu.setFocusPainted(false);
		jbMenu.setBorderPainted(false);               // ces trois lignes sont les meme que la haut :)
		jbMenu.setContentAreaFilled(false);
		jbMenu.addActionListener(this); 

		
		contenu3.add(jbMenu,0);
		contenu3.add(label, 1);
		
		
		label.setBounds(0, 0, 1027, 504);
		jbMenu.setBounds(315,385,180,100);
		
		
		setSize(500,500);
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setVisible(true);
}




	public void actionPerformed(ActionEvent evt) {
		Object source = evt.getSource();
		if (source == jbMenu){
			Menu m = new Menu("Doode - Menu");
			dispose();
		}
		
	}}

Forum class:

import java.io.IOException;
import java.util.Properties;


public class Forum {
	
	
	
	public Forum (){
		
	}
	Properties sys = System.getProperties();
	String os = sys.getProperty("os.name");
	Runtime r = Runtime.getRuntime();{
	try
	{
	if (os.endsWith("NT")||os.endsWith("2000")||os.endsWith("XP"))
	r.exec("cmd /c start http://doode.xooit.fr");
	else
	r.exec("start http://doode.xooit.fr");
	}
	catch (IOException ex)
	{
	ex.printStackTrace();
	}

}}

here it is… I know it bit long, but please, say me what’s wrong…

Thanks for all

The classes seems ok to me so far.
Issues:

  1. aiming for 1280x1024 resolution ? (setSize(1280,1024) in jeu class; right off the bat sounds risky, lots of users will not have monitor supporting that resolution ( e.g. laptops etc. ) If you are making applet, i suggest looking at gamesites to see suggested sizes, e.g. Kongregate has 700×500 limit fro flash games. Now this is not important if you are aiming for downloadable, but in any case you want the user to be able to play on any monitor. A lot of applets break this rule, and lose a lot of players that way.
    It’s good to think about this from the start, and though it may be some work i recommend either setting a smaller size that everybody will be able to play or making it resizable to fit different monitors. For our game we are now pushing it with 1000x600 startup size… this is particularly to fit laptops and netbooks.


public byte nombreDeDoodeVert=7;	
			public byte nombreDeDoodeBleu=8;
			public byte nombreDeDoodeRouge=4;
			public byte nombreDeDoodeJaune=4;

Is this the number of Doodes of a certain color ?

I might prefer something like an enum
http://java.sun.com/docs/books/tutorial/java/javaOO/enum.html
or byte[][], [color][numDoodes]

  1. Indenting code, if you are using Eclipse : Select All, CTRL+I does an automatic cleanup, makes everything nice and readable.

  2. As you make more actual game code, you will want to put pieces into other classes, and try to keep the Game class just as the controller of the engine state, with Players, Logic, Map or whatever separated.

Thanks a lot man !

Second one: How to do if I want that every time I change number of doode colors, my JPanel changes too.

Because, when I change my variables in the code, or add “nombreDeDoodeRouge++;” when I click on panel, it dont change my jpanel, It’s bad for a game if we have to have exactly the same numbers of guys everytime :-\

And can u coucil me a library? Is JGame good?

I hope u’ll can help me!

thanks a lot

hmm… I’m really not very good with Swing. somebody else will have to help out on that.
I’ve mostly just rolled my own games, not really used any engines like JGame, but they could be useful…
Also I haven’t made any games which just sit still waiting for input,
always having a Runnable, which continuously paints everything I want on the screen…

One more thing, you may want to make a Doode class, which has nombreDoodes vaariable inside it…

Hum, can you precise… Im french and i dont understand runnable… I found some ansmwers in google but im not sure… Does have I to use juva.lang.Runnable ?

Or only a little:

 for(i=1){
//my program
repaint();
}

Hum, and for the class “Doode” with the variables NombreDeDoode…, Its not better to do an interface?
I dont understand why it be useful…

A few advices :

  1. You are targeting to a RTS (is that real time shooter ?), Swing is rather passive (indirect) rendering wised, so it be more understandable to use an accelerated rendering strategy like opengl.
  2. A game should be as compact as possible in terms of objects concurrently loaded, as you said a game needs to react pretty fast. Then I’d use one JFrame and several JPanel’s for menu, options and maybe a canvas to make real-time rendering.
  3. following those advices makes you plently open to further implementations of third party libraries like LWJGL, JOGL, etc. As of 2. you will have your object amount increased by 10 in a later time and your code will stay “open” to high-end API’s.

Game design is not a fair work, you may spend more time on coding basic rendering aspects, where you may not have enough time to define a robust Threading concept, multi-player interface or AI simulation…
Last but not least, books are not the best tutorials, but school curses (yes, school is teaching game design) or using a library designed for games (google it, but I know about Slick, JME, or even mine JIGAXtended API) make the approach easier to begginners.
8)

Hum, RTS mean real time strategy, so it will be in 2D or isometric 3D.

For the second point, you want that I make a Menu which just repaint itself?

I don’t understand all… But ok, I’ll try to change that. anyway I don’t understand how I’ll do that.

Hum, for a real time rendering, canvas is the better choice? because when i google it, I see Its only a draw class…

Can I use a loop?

for(i=1){
//my program
repaint();
}

I’ll work with LWJGL I think.

Hum, but, please, explain me how to have a real time rendering, not a stupid game who wait for input.

It sounds like what you are looking for is active rendering. Trying doing a search for java active rendering and/or check out this link http://fivedots.coe.psu.ac.th/~ad/jg/ch1/index.html .

Hey men ! Thanks a lot, I worked on it and I made it… But the compilo make me crazy, it say me a lot a errors…

code of class:

Bonjour,

Voici mon problème… J’ai fait ce code pour avoir un affichage de JLabels “runnable” et cela me sort plein, plein, plein d’erreurs…

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;



@SuppressWarnings("serial")
public class Jeu extends JFrame implements MouseListener {


	public JButton barre1 = new JButton("", new ImageIcon("barre1.gif"));
	public JButton barre2 = new JButton("", new ImageIcon("barre2.gif"));
	public JButton barre3 = new JButton("", new ImageIcon("barre3.gif"));
	public JButton barre4 = new JButton("", new ImageIcon("barre4.gif"));
	public JButton champ1 = new JButton("", new ImageIcon("champ.png"));
	public JButton champ2 = new JButton("", new ImageIcon("champ.png"));
	public JButton rive = new JButton("", new ImageIcon("riviere.bmp"));

	public JComboBox Menu1 = new JComboBox();






	// déclaration variables

	public int ClickX = 0;
	public int ClickY =0;
	public byte nombreDeDoodeVert=7;	
	public byte nombreDeDoodeBleu=8;
	public byte nombreDeDoodeRouge=4;
	public byte nombreDeDoodeJaune=4;
	public byte nombreEnnemis=75;
	public int nombreDeDoode=nombreDeDoodeVert+nombreDeDoodeBleu+nombreDeDoodeRouge+nombreDeDoodeJaune;
	public short doowatt=500;
	public short nourriture=500; // chercher un autre nom
	public short geleeNoire; // autre nom
	public short nombreEnnemisTues=0;
	public String pseudo;
	public Container contenu2;
	public JLabel fond;


	// Jeu

	public Jeu (String titre) {                 //création de la méthode constructeur
		setTitle (titre);
		Container contenu2 = getContentPane();	
		contenu2.addMouseListener(this);



		public JLabel BarreVert = new JLabel();
		public JLabel BarreBleu = new JLabel();
		public JLabel BarreRouge = new JLabel();
		public JLabel BarreJaune = new JLabel();



		public JLabel fond = new JLabel();

		contenu2.setLayout(null);
		Image image = Toolkit.getDefaultToolkit().createImage("map5.jpg");// nouveau JLabel backgound
		fond.setIcon(new ImageIcon(image));



		public void go(){
		contenu2.add(BarreVert);
		BarreVert.setText(""+nombreDeDoodeVert);
		BarreVert.setBounds(98,2,20,20);
		BarreVert.setForeground(Color.white); 




		contenu2.add(BarreBleu);
		BarreBleu.setText(""+nombreDeDoodeBleu);
		BarreBleu.setBounds(292,2,20,20);
		BarreBleu.setForeground(Color.white);


		contenu2.add(BarreRouge);
		BarreRouge.setText(""+nombreDeDoodeRouge);
		BarreRouge.setBounds(492,2,20,20);
		BarreRouge.setForeground(Color.white);


		contenu2.add(BarreJaune);
		BarreJaune.setText(""+nombreDeDoodeJaune);
		BarreJaune.setBounds(676,2,20,20);
		BarreJaune.setForeground(Color.white);
}






		contenu2.add(barre1);
		barre1.setBounds(5,5,190,55);
		barre1.setFocusPainted(false);
		barre1.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
		barre1.setContentAreaFilled(false);
		barre1.addMouseListener(this); 


		contenu2.add(barre2);
		barre2.setBounds(187,5,190,55);
		barre2.setFocusPainted(false);
		barre2.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
		barre2.setContentAreaFilled(false);
		barre2.addMouseListener(this);


		contenu2.add(barre3);
		barre3.setBounds(372,5,190,55);
		barre3.setFocusPainted(false);
		barre3.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
		barre3.setContentAreaFilled(false);
		barre3.addMouseListener(this);


		contenu2.add(barre4);
		barre4.setBounds(557,5,190,55);
		barre4.setFocusPainted(false);
		barre4.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
		barre4.setContentAreaFilled(false);
		barre4.addMouseListener(this);

		contenu2.add(champ1);
		champ1.setBounds(1000,500,190,55);
		champ1.setFocusPainted(false);
		champ1.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
		champ1.setContentAreaFilled(false);
		champ1.addMouseListener(this);

		contenu2.add(champ2);
		champ2.setBounds(250,800,190,55);
		champ2.setFocusPainted(false);
		champ2.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
		champ2.setContentAreaFilled(false);
		champ2.addMouseListener(this);

		contenu2.add(rive);
		rive.setBounds(0,0,190,55);
		rive.setFocusPainted(false);
		rive.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
		rive.setContentAreaFilled(false);
		rive.addMouseListener(this);




		contenu2.add(fond);
		fond.setBounds(0, 0, 1280, 1024);



		setSize(1280,1024);
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setVisible(true);




	}









	public void mouseClicked(MouseEvent e) {	
		Object source = e.getSource();	
		if (source != barre1){

			ClickX = e.getX();
			ClickY = e.getY();
			System.out.print("\nla variable est à:"+ClickX+" et à "+ClickY);
			nombreDeDoodeRouge++;


		}



	}








	public void mouseEntered(MouseEvent arg0) {


	}


	public void mouseExited(MouseEvent arg0) {


	}


	public void mousePressed(MouseEvent Pressevt) {


	}




	public void mouseReleased(MouseEvent arg0) {


	}
	class PlayAnimation implements Runnable{
		 
        @Override
        public void run() {
                go();          
}

Please help me!!! Errors are down …

Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems: 
	Duplicate field Jeu.fond
	Syntax error, insert "}" to complete MethodBody
	Duplicate field Jeu.fond
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "null", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "setIcon", = expected after this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "barre1", VariableDeclaratorId expected after this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on tokens, delete these tokens
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "this", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "barre2", VariableDeclaratorId expected after this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on tokens, delete these tokens
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "this", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "barre3", VariableDeclaratorId expected after this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on tokens, delete these tokens
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "this", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "barre4", VariableDeclaratorId expected after this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on tokens, delete these tokens
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "this", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "champ1", VariableDeclaratorId expected after this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on tokens, delete these tokens
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "this", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "champ2", VariableDeclaratorId expected after this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on tokens, delete these tokens
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "this", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "rive", VariableDeclaratorId expected after this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on tokens, delete these tokens
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "false", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "this", delete this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on token "fond", VariableDeclaratorId expected after this token
	Syntax error on token(s), misplaced construct(s)
	Syntax error on tokens, delete these tokens
	Syntax error on token(s), misplaced construct(s)
	Syntax error on tokens, AnnotationName expected instead
	Syntax error on token ";", @ expected
	Syntax error on token ";", @ expected
	Syntax error on token "}", delete this token

	at Jeu.<init>(Jeu.java:46)
	at Menu.actionPerformed(Menu.java:83)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

It would appear that your go function is in the jeu constructor.

Ho yes ! :persecutioncomplex:

thanks a lot!

code:



import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;


		
@SuppressWarnings({ "serial", "unused" })
public class Jeu extends JFrame implements MouseListener {

 
	public JButton barre1 = new JButton("", new ImageIcon("barre1.gif"));
	public JButton barre2 = new JButton("", new ImageIcon("barre2.gif"));
	public JButton barre3 = new JButton("", new ImageIcon("barre3.gif"));
	public JButton barre4 = new JButton("", new ImageIcon("barre4.gif"));
	public JButton champ1 = new JButton("", new ImageIcon("champ.png"));
	public JButton champ2 = new JButton("", new ImageIcon("champ.png"));
	public JButton rive = new JButton("", new ImageIcon("riviere.bmp"));
	public JLabel BarreVert = new JLabel();
    public JLabel BarreBleu = new JLabel();
    public JLabel BarreRouge = new JLabel();
    public JLabel BarreJaune = new JLabel();
	
	public JComboBox Menu1 = new JComboBox();
	
	
	
	
	
	
	    // déclaration variables
	
            public int ClickX = 0;
            public int ClickY =0;
			public byte nombreDeDoodeVert=7;	
			public byte nombreDeDoodeBleu=8;
			public byte nombreDeDoodeRouge=4;
			public byte nombreDeDoodeJaune=4;
			public byte nombreEnnemis=75;
			public int nombreDeDoode=nombreDeDoodeVert+nombreDeDoodeBleu+nombreDeDoodeRouge+nombreDeDoodeJaune;
			public short doowatt=500;
			public short nourriture=500; // chercher un autre nom
			public short geleeNoire; // autre nom
			public short nombreEnnemisTues=0;
			public String pseudo;
			public Container contenu2;
			public JLabel fond;
	
			
			// Jeu
			
			public Jeu (String titre) {                 //création de la méthode constructeur
			setTitle (titre);
			Container contenu2 = getContentPane();	
			contenu2.addMouseListener(this);
	

			
		    
		    
		    
		    
			JLabel fond = new JLabel();
			
			contenu2.setLayout(null);
			Image image = Toolkit.getDefaultToolkit().createImage("map5.jpg");// nouveau JLabel backgound
			fond.setIcon(new ImageIcon(image));
			
			

			contenu2.add(BarreVert);
			
			BarreVert.setBounds(98,2,20,20);
			BarreVert.setForeground(Color.white); 
			


			
			contenu2.add(BarreBleu);
			BarreBleu.setText(""+nombreDeDoodeBleu);
			BarreBleu.setBounds(292,2,20,20);
			BarreBleu.setForeground(Color.white);
			
			
			contenu2.add(BarreRouge);
			BarreRouge.setText(""+nombreDeDoodeRouge);
			BarreRouge.setBounds(492,2,20,20);
			BarreRouge.setForeground(Color.white);
			
			
			contenu2.add(BarreJaune);
			BarreJaune.setText(""+nombreDeDoodeJaune);
			BarreJaune.setBounds(676,2,20,20);
			BarreJaune.setForeground(Color.white);
			
			
			
			
	
			
			
			contenu2.add(barre1);
		    barre1.setBounds(5,5,190,55);
			barre1.setFocusPainted(false);
			barre1.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			barre1.setContentAreaFilled(false);
	        barre1.addMouseListener(this); 
	        
	        
	        contenu2.add(barre2);
		    barre2.setBounds(187,5,190,55);
			barre2.setFocusPainted(false);
			barre2.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			barre2.setContentAreaFilled(false);
	        barre2.addMouseListener(this);
	        
	        
	        contenu2.add(barre3);
		    barre3.setBounds(372,5,190,55);
			barre3.setFocusPainted(false);
			barre3.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			barre3.setContentAreaFilled(false);
	        barre3.addMouseListener(this);
	        
	        
	        contenu2.add(barre4);
		    barre4.setBounds(557,5,190,55);
			barre4.setFocusPainted(false);
			barre4.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			barre4.setContentAreaFilled(false);
	        barre4.addMouseListener(this);
	        
	        contenu2.add(champ1);
	        champ1.setBounds(1000,500,190,55);
			champ1.setFocusPainted(false);
			champ1.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			champ1.setContentAreaFilled(false);
	        champ1.addMouseListener(this);
	        
	        contenu2.add(champ2);
	        champ2.setBounds(250,800,190,55);
			champ2.setFocusPainted(false);
			champ2.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			champ2.setContentAreaFilled(false);
	        champ2.addMouseListener(this);
	        
	        contenu2.add(rive);
	        rive.setBounds(0,0,190,55);
			rive.setFocusPainted(false);
			rive.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
			rive.setContentAreaFilled(false);
	        rive.addMouseListener(this);
	        
	        
			

			 contenu2.add(fond);
				fond.setBounds(0, 0, 1280, 1024);
	       
			
		
			setSize(1280,1024);
			setResizable(false);
			setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			setVisible(true);
			
			
		
			
		}


	

	
	


		
			public void mouseClicked(MouseEvent e) {	
				Object source = e.getSource();	
				if (source != barre1){

				ClickX = e.getX();
				ClickY = e.getY();
				System.out.print("\nla variable est à:"+ClickX+" et à "+ClickY);
		
				nombreDeDoodeVert++;
				}
				
					
					
					}
					
							
			
			
			
		

		
		public void mouseEntered(MouseEvent arg0) {
			
			
		}

		
		public void mouseExited(MouseEvent arg0) {
		
			
		}

		
		public void mousePressed(MouseEvent Pressevt) {
		
				
			}
			
		

		
		public void mouseReleased(MouseEvent arg0) {

			
		}
		class PlayAnimation implements Runnable{
			 
			
			
			public void go(){
				BarreVert.setText(""+nombreDeDoodeVert);
				go();
				
			}
	        @Override
	        public void run() {
	                go();      
	}}}

It seems clearer but i dont see JPanel “nombreDeDoodeVert” when I click…

Your not making a call to PlayAnimation.go() so the text is never set. If you did call PlayAnimation.go() you will be stuck in an infinite loop because go() is calling itself with no break condition.

It would probably help if you made a new project that only deals with the problem code, this always helps me learn new things.

Omg, where was your magic stick ? It worked fine because the code was so clearer !!! So I understood what was wrong and now all is working… ;D

I recognize you should be teacher because you don’t offer answer but you make me discover it! Thanks a lot :slight_smile:

Hum, I have some questions… I want to make a JScrollbar for explore my map…

          Is it possible? How can we attach JScrollbar to the JLabel I use to my background?

Please help me, here is my code who didn’t work…

public Container contenu2;
			JLabel fond = new JLabel();
			
	
			
			// Jeu
			
			public Jeu (String titre) {                 //création de la méthode constructeur
			setTitle (titre);
			Container contenu2 = getContentPane();	
			contenu2.addMouseListener(this);
	

			
		    
		    
		    
		    
		
			
			contenu2.setLayout(null);
			Image image = Toolkit.getDefaultToolkit().createImage("map5.jpg");// nouveau JLabel backgound
			fond.setIcon(new ImageIcon(image));
			
		    JScrollPane scrollpane = new JScrollPane();
			JPanel panel = new JPanel(new BorderLayout());
		    panel.add(fond, BorderLayout.CENTER);
			scrollpane.add(panel);
			scrollpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			add(scrollpane, BorderLayout.NORTH);
			fond.setHorizontalAlignment(JLabel.CENTER);
			
			
			contenu2.add(scrollpane);
			contenu2.add(panel);
			
			

assuming your container is a contentpane from applet or frame, you load an image map5.jpg and want to scroll over it. This is quite simple :


Container contenu = getContentPane();
contenu.setLayout(new BorderLayout());
final Image map = ImageIO.read(new File("map5.jpg"));
final  MediaTracker myTracker = new MediaTracker(this);
myTracker.addImage(map, 1); 
JPanel myPanelMap = new JPanel(true) {   
   protected void paintComponent(Graphics g) {           
           try{myTracker.waitForId(1);} catch(InterruptedException e) {}             
           Graphics2D g2 = (Graphics2D)g;
             // clear the background if your image has transparency
           Color c = g2.getColor();
           g2.setColor(getBackground());
            g2.fillRect(0,0,getWidth(), getHeight());
            AffineTransform tx = new AffineTransform();
           // tx may be modified with custom transform such as scaling
           // or rotating matrixes, that the image will be applied on rendering
           g2.drawImage(map, tx, this);  
           g2.setColor(c);         
    } 
};
/* this line is needed*/
myPanelMap.setPreferredSize(new  Dimension(map.getWidth(), map.getHeight()));
JScrollPane sp = new JScrollPane(myPanelMap);
// this makes the panel more reactive
sp.getHorizontalScrollBar().setBlockIncrement(30);
sp.getVerticalScrollBar().setBlockIncrement(30);
contenu.add(sp, BorderLayout.CENTER);
contenu.validate();
contenu.repaint();

Thanks !!! Ill try to understand it before test it… :persecutioncomplex:

thanks a lot

hoho, im losin… Code dont work, I dont see any new thing and I understand 3/4 of text…

:-\

I made it with Netbeans, look at the map.Main source code it works for a map5.jpg located in the current working folder (see properties of project in NB).
You can run the code with the provided executables.

So, now, my frame is ok…

I want to create a “void” wich create an object everytime I click on a button…

Is that good ?

			private void DoodeVert(){
				
				JButton DoodeVert = new JButton("",new ImageIcon("vert.gif"));
				DoodeVert.setBounds(100,100,90,90);
			    DoodeVert.setFocusPainted(false);
				DoodeVert.setBorderPainted(false);                  // ces trois lignes enelvent la bordure du boutton
				DoodeVert.setContentAreaFilled(false);
				DoodeVert.addMouseListener(this); 
				contenu2.add(DoodeVert);
		        DoodeVert.setVisible(true);

				
			
			}

DoodeVert();

			
			

thanks for all you made for me…