Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Few questions to organize my game(How to create RTS?)  (Read 4154 times)
0 Members and 1 Guest are viewing this topic.
Offline hug0x

Senior Newbie





« Posted 2009-11-09 19:21:12 »

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 Smiley


Main class:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public class Main {

   
   public static void main(String[] args) {

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

}


Menu class:

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  
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:

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  
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 ---->


Offline hug0x

Senior Newbie





« Reply #1 - Posted 2009-11-09 19:21:32 »

Options class:

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  
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:

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  
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

Offline Karmington

Senior Devvie


Medals: 1
Projects: 1


Co-op Freak


« Reply #2 - Posted 2009-11-09 23:30:11 »

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.

2)
1  
2  
3  
4  
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]

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

4) 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.


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline hug0x

Senior Newbie





« Reply #3 - Posted 2009-11-12 19:32:18 »

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  Undecided

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

I hope u'll can help me!

thanks a lot
Offline Karmington

Senior Devvie


Medals: 1
Projects: 1


Co-op Freak


« Reply #4 - Posted 2009-11-13 14:08:57 »

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...

Offline hug0x

Senior Newbie





« Reply #5 - Posted 2009-11-13 16:49:07 »

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:
1  
2  
3  
4  
 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..
Offline broumbroum

Junior Devvie





« Reply #6 - Posted 2009-11-13 22:25:38 »

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.
 Cool

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline hug0x

Senior Newbie





« Reply #7 - Posted 2009-11-14 10:27:35 »

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.




Offline zoto

Senior Devvie


Medals: 4



« Reply #8 - Posted 2009-11-14 12:50:52 »

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 .
Offline hug0x

Senior Newbie





« Reply #9 - Posted 2009-11-16 17:35:54 »

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...

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  
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 ..
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline hug0x

Senior Newbie





« Reply #10 - Posted 2009-11-16 17:36:06 »

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  
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)
Offline zoto

Senior Devvie


Medals: 4



« Reply #11 - Posted 2009-11-16 18:43:05 »

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

Senior Newbie





« Reply #12 - Posted 2009-11-16 19:00:35 »

Ho yes ! persecutioncomplex

thanks a lot!

code:
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  
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...
Offline zoto

Senior Devvie


Medals: 4



« Reply #13 - Posted 2009-11-16 20:04:25 »

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.
 
Offline hug0x

Senior Newbie





« Reply #14 - Posted 2009-11-16 20:34:18 »

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...  Grin

I recognize you should be teacher because you don't offer answer but you make me discover it!  Thanks a lot  Smiley
Offline hug0x

Senior Newbie





« Reply #15 - Posted 2009-12-06 20:52:53 »

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..

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  
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);
         
         
Offline broumbroum

Junior Devvie





« Reply #16 - Posted 2009-12-07 22:26:52 »

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 :
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  
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();

 Cool

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline hug0x

Senior Newbie





« Reply #17 - Posted 2009-12-08 18:00:39 »

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..

 Undecided
Offline broumbroum

Junior Devvie





« Reply #18 - Posted 2009-12-09 13:45:00 »

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.

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline hug0x

Senior Newbie





« Reply #19 - Posted 2009-12-10 21:15:05 »

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 ?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
         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...
Offline broumbroum

Junior Devvie





« Reply #20 - Posted 2009-12-10 22:34:36 »

1  
contenu2.add(DoodeVert);

most mistakes in your samples are layout settings.
1. Adding a component when using other layouts than FlowLayout is done with a constraint : BorderLayout -> South, north... ; GridBagLayout * -> gridbagconstraints instance; etc.
2. And at least one of the component must set a preferredSize if no "fixed" component like JLabel or JprogressBar are present.
3. each modification sequence after setVisible(true) must be explicitely validated
4. when handling multiple threads, ensure you're in the EventDispatcherThread to make such layout modifications : SwingUtilities are therefore recommended tools.
Wink

* : GridBagLayout may generally render a better look and feel, but is tricky.

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (71 views)
2014-11-26 15:22:04

toopeicgaming1999 (60 views)
2014-11-26 15:20:36

toopeicgaming1999 (14 views)
2014-11-26 15:20:08

SHC (27 views)
2014-11-25 12:00:59

SHC (25 views)
2014-11-25 11:53:45

Norakomi (31 views)
2014-11-25 11:26:43

Gibbo3771 (25 views)
2014-11-24 19:59:16

trollwarrior1 (38 views)
2014-11-22 12:13:56

xFryIx (77 views)
2014-11-13 12:34:49

digdugdiggy (55 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!