IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Interfaces Graphiques en Java Discussion :

Runnable, pourquoi cela ne marche pas?


Sujet :

Interfaces Graphiques en Java

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 11
    Points : 6
    Points
    6
    Par défaut Runnable, pourquoi cela ne marche pas?
    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...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    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();          
    }

    erreurs:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    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)

  2. #2
    Débutant Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Points : 162
    Points
    162
    Par défaut
    j'ai pas trop cherché mais vu l'erreur ton code java n'est pas java :p

    tu utilises un IDE ? enfin sinon il te manques des accolades et peut être d'autre élément de syntaxe.

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 11
    Points : 6
    Points
    6
    Par défaut merci lol
    Merci

    Non, en fait ma méthode était dans mon constructeur, et la ça bloque...

    J'ai refait le truc, et je sais pas pourquoi, mais mon JPanel "nombreDeDoodeVert ne s'affiche pas..

    code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
     
     
    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();      
    	}}}

  4. #4
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 867
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 867
    Points : 22 924
    Points
    22 924
    Billets dans le blog
    52
    Par défaut
    Oh le bel appel recursif infini !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    public void go(){
      BarreVert.setText(""+nombreDeDoodeVert);
      go();
    }
     
    @Override
    public void run() {
      go();   
    }
    Ce n'est pas comme cela qu'on fait des animations.

    1. Pas d'appel recursif ! C'est le coup a bouffer toute la memoire de l'ordi. On fait des boucles iteratives.
    2. Il faut laisser le temps a l'ordi de faire autre chose et donc se menager des pauses.


    Un truc du genre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    public void go(){
      // Mise a jour du composant dans l'EDT.
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
           BarreVert.setText(""+nombreDeDoodeVert);
         }
      }
    }
     
    @Override
    public void run() {
      try {
        while (true) {
          go();
          Thread.sleep(500);
        }
      }
      catch (InterruptedException ie) {
      }
    }
    Mais ca c'est si jamais ton Runnable PlayAnimation est a lancer dans une autre Thread. Sinon il est aussi possible de le lancer dans l'EDT en utilisant un Timer Swing (javax.swing.Timer) qui dispose de ce qu'il faut pour etre re-appeler a intervalles reguliers.

Discussions similaires

  1. Réponses: 2
    Dernier message: 07/04/2015, 20h51
  2. pourquoi cela ne marche pas
    Par UDSP50 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 22/02/2014, 17h33
  3. Pourquoi cela ne marche pas?
    Par shaytan dans le forum Débuter
    Réponses: 3
    Dernier message: 20/09/2008, 22h37
  4. Pourquoi ce code marche pas sous FF?
    Par Death83 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 09/09/2005, 10h04
  5. [W3C] Pourquoi ça ne marche pas sous IE
    Par polo-j dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 16/02/2005, 16h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo