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

 Java Discussion :

Afficher un background dans ma fenêtre


Sujet :

Java

  1. #61
    Membre du Club
    Homme Profil pro
    Artisant
    Inscrit en
    Avril 2018
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Corse (Corse)

    Informations professionnelles :
    Activité : Artisant
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2018
    Messages : 169
    Points : 60
    Points
    60
    Par défaut
    Bonjour,

    Comment puis je vous transmettre le zip?


    Fred

  2. #62
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    En pièce jointe à ton message, avec le bouton "trombone".
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  3. #63
    Membre du Club
    Homme Profil pro
    Artisant
    Inscrit en
    Avril 2018
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Corse (Corse)

    Informations professionnelles :
    Activité : Artisant
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2018
    Messages : 169
    Points : 60
    Points
    60
    Par défaut
    Voici les Fichiers sources


    Fred
    Fichiers attachés Fichiers attachés

  4. #64
    Membre du Club
    Homme Profil pro
    Artisant
    Inscrit en
    Avril 2018
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Corse (Corse)

    Informations professionnelles :
    Activité : Artisant
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2018
    Messages : 169
    Points : 60
    Points
    60
    Par défaut
    Bonjour,

    comment allez vous?

    J'ai essayé de rendre ma fenêtre ajustable mais ça me pose pas mal de soucis avec mouse listener et les bounds.

    je ne croit pas trop avoir compris le principe.

    Je me suis pris un livre sur la programmation en java pour essayé de mieux comprendre certain principe qui méchappe.


    Fred

  5. #65
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Salut,

    Bien. J'ai été pas mal occupé cette semaine et je n'ai pas eu le temps de regarder ton zip.

    Pour le redimensionnement de la fenêtre je t'ai implémenté le principe sur mon précédent exemple de fenêtre avec simulation de bordure :
    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
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    public class FrameBorder implements Border {
     
    	private String title;
    	public FrameBorder() {
    	}
    	public FrameBorder(String title) {
    		this.title=title;
    	}
     
    	public void registerFrame(JPanel panel, JFrame frame) {
    		MouseAdapter mouseAdapter = new MouseAdapter() {
    			private boolean drag;
    			private boolean resize;
    			private int cursor;
    			private Point location;
    			@Override
    			public void mouseClicked(MouseEvent e) {
    				if ( panel.getBorder()==FrameBorder.this && inButton(panel, e.getPoint())) {
    					frame.dispose();
    				}
    			}
    			@Override
    			public void mousePressed(MouseEvent e) {
    				cursor = getResizeCursor(frame, e.getPoint());
    				if ( cursor!=-1) {
    					resize=true;
    				}
    				else if ( panel.getBorder()==FrameBorder.this && inTitleBar(panel, e.getPoint())) {
    					drag=true;
    					location = e.getPoint();
    				}
    			}
     
    			@Override
    			public void mouseMoved(MouseEvent e) {
    				cursor = getResizeCursor(frame, e.getPoint());
    				panel.setCursor(cursor==-1?null:Cursor.getPredefinedCursor(cursor));
    				panel.repaint();
    			}
     
    			@Override
    			public void mouseDragged(MouseEvent e) {
    				if ( resize ) {
    					int dx, dy;
    					switch(cursor) {
    					case Cursor.NE_RESIZE_CURSOR:
    						dx = e.getX()-frame.getWidth();
    						dy = -e.getY();
    						if ( frame.getWidth()+dx>=64 && frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX(), 
    								  frame.getY()-dy,
    								  frame.getWidth()+dx,
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					case Cursor.E_RESIZE_CURSOR:
    						dx = e.getX()-frame.getWidth();
    						if ( frame.getWidth()+dx>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX(), 
    								  frame.getY(),
    								  frame.getWidth()+dx,
    								  frame.getHeight()
    								  );
    						}
    						break;
    					case Cursor.NW_RESIZE_CURSOR:
    						dx = -e.getX();
    						dy = -e.getY();
    						if ( frame.getWidth()+dx>=64 && frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX()-dx, 
    								  frame.getY()-dy,
    								  frame.getWidth()+dx,
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					case Cursor.N_RESIZE_CURSOR:
    						dy = -e.getY();
    						if ( frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX(), 
    								  frame.getY()-dy,
    								  frame.getWidth(),
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					case Cursor.SE_RESIZE_CURSOR:
    						dx = e.getX()-frame.getWidth();
    						dy = e.getY()-frame.getHeight();
    						if ( frame.getWidth()+dx>=64 && frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX(), 
    								  frame.getY(),
    								  frame.getWidth()+dx,
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					case Cursor.W_RESIZE_CURSOR:
    						dx = -e.getX();
    						if ( frame.getWidth()+dx>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX()-dx, 
    								  frame.getY(),
    								  frame.getWidth()+dx,
    								  frame.getHeight()
    								  );
    						}
    						break;
    					case Cursor.SW_RESIZE_CURSOR:
    						dx = -e.getX();
    						dy = e.getY()-frame.getHeight();
    						if ( frame.getWidth()+dx>=64 && frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX()-dx, 
    								  frame.getY(),
    								  frame.getWidth()+dx,
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					case Cursor.S_RESIZE_CURSOR:
    						dy = e.getY()-frame.getHeight();
    						if ( frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX(), 
    								  frame.getY(),
    								  frame.getWidth(),
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					}
    				}
    				else if ( drag ) {
    					if ( panel.getBorder()==FrameBorder.this ) {
    						//if ( inTitleBar(panel, e.getPoint()) ) {
    							frame.setLocation(frame.getX()+e.getX()-location.x, frame.getY()+e.getY()-location.y);
    						//}
    					}
    					else {
    						drag=false;
    					}
    				}
    			}
    			@Override
    			public void mouseReleased(MouseEvent e) {
    				drag=false;
    				resize=false;
    			}
    		};
    		panel.addMouseListener(mouseAdapter);
    		panel.addMouseMotionListener(mouseAdapter);
    	}
     
    	protected int getResizeCursor(JFrame frame, Point point) {
    		int cursor = -1;
    		if ( point.x<3 ) {
    			cursor=Cursor.W_RESIZE_CURSOR;
    		}
    		else if ( point.x>frame.getWidth()-3 ) {
    			cursor=Cursor.E_RESIZE_CURSOR;
    		}
    		if ( point.y<3 ) {
    			switch( cursor ) {
    			case Cursor.E_RESIZE_CURSOR:
    				cursor=Cursor.NE_RESIZE_CURSOR;
    				break;
    			case Cursor.W_RESIZE_CURSOR:
    				cursor=Cursor.NW_RESIZE_CURSOR;
    				break;
    			default:
    				cursor=Cursor.N_RESIZE_CURSOR;
    			}
    		}
    		else if ( point.y>frame.getHeight()-3 ) {
    			switch( cursor ) {
    			case Cursor.E_RESIZE_CURSOR:
    				cursor=Cursor.SE_RESIZE_CURSOR;
    				break;
    			case Cursor.W_RESIZE_CURSOR:
    				cursor=Cursor.SW_RESIZE_CURSOR;
    				break;
    			default:
    				cursor=Cursor.S_RESIZE_CURSOR;
    			}
    		}
    		return cursor;
    	}
    	public void setTitle(String title) {
    		this.title=title;
    	}
     
    	@Override
    	public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    		Graphics2D g2d = (Graphics2D) g.create(x, y, width, height);
    		Rectangle componentBounds = new Rectangle(x,y,width,height);
    		Insets insets = getBorderInsets(c);
    		Rectangle innerBounds = new Rectangle(x+insets.left,y+insets.top,width-insets.left-insets.right,height-insets.top-insets.bottom);
    		Area area = new Area(componentBounds);
    		area.subtract(new Area(innerBounds));
    		g2d.setClip(area);
    		g2d.setPaint(Color.CYAN);
    		g2d.fillRect(x, y, width-1, height-1);;
    		g2d.setPaint(Color.GRAY);
    		g2d.drawRect(x, y, width-1, height-1);
    		g2d.drawRect(innerBounds.x-1, innerBounds.y-1, innerBounds.width+1, innerBounds.height+1);
     
    		if ( title!=null ) {
    			g2d.setPaint(Color.BLACK);
    			g2d.setFont(new Font("Arial",Font.BOLD,12));
    			FontMetrics fm = g2d.getFontMetrics();
    			Rectangle2D stringBounds = fm.getStringBounds(title, g2d);
    			if ( stringBounds.getWidth()>width-80 ) {
    				stringBounds.setFrame(32, 15-stringBounds.getHeight()/2, width-80, stringBounds.getHeight()+4);
    				g2d.clip(stringBounds);
    			}
    			else {
    				stringBounds.setFrame(32, 15-stringBounds.getHeight()/2, stringBounds.getWidth()+4, stringBounds.getHeight()+4);
    			}
    			g2d.drawString(title, 34, 16+(fm.getAscent()-fm.getDescent())/2);
    			area.subtract(new Area(stringBounds));
    			g2d.setClip(area);
    		}
    		g2d.setPaint(Color.GRAY);
    		for(int i=5; i<28; i+=3) {
    			g2d.drawLine(3, i, width-6-32, i);
    		}
    		g2d.drawRect(width-32, 3, 25, 25);
     
    		Area cross = new Area(new Rectangle(width-22,5,5,21));
    		cross.add(new Area(new Rectangle(width-30,13,21,5)));
    		AffineTransform af=AffineTransform.getRotateInstance(Math.PI/4, width-19.5, 15.5);
    		af.translate(0.5, 0);
    		cross = cross.createTransformedArea(af);
    		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    		if ( c.getMousePosition()!=null && inButton(c,c.getMousePosition()) ) { 
    			g2d.fill(cross);
    		}
    		g2d.draw(cross);
     
    		g2d.dispose();
    	}
     
    	public boolean inTitleBar(Component c, Point p) {
    		if (p==null ) return false;
    		return new Rectangle(0,0,c.getWidth(),32).contains(p) && !inButton(c, p);
    	}
    	public boolean inButton(Component c, Point p) {
    		if (p==null ) return false;
    		return new Rectangle(c.getWidth()-32, 3, 25, 25).contains(p);
    	}
     
    	@Override
    	public Insets getBorderInsets(Component c) {
    		return new Insets(32,4,4,4);
    	}
     
    	@Override
    	public boolean isBorderOpaque() {
    		return true;
    	}
     
     
    	public static void main(String[] args) {
     
    		JFrame frame = new JFrame();
    		frame.setUndecorated(true);
     
    		FrameBorder frameBorder = new FrameBorder("Démo");
     
    		JPanel panel = new JPanel(new GridBagLayout());
    		panel.setBorder(frameBorder);
     
    		JButton button = new JButton("Supprimer dérocations");
    		button.addActionListener(e -> toggleDecorations(panel, button, frameBorder));
    		panel.add(button);
     
    		frame.add(panel);
     
    		frameBorder.registerFrame(panel, frame);
    		frame.setSize(300, 300);
    		frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
     
    	}
     
    	private static void toggleDecorations(JPanel panel, JButton button, Border border) {
    		Border currentBorder = panel.getBorder();
    		if (currentBorder==null) {
    			panel.setBorder(border);
    			button.setText("Supprimer décorations");
    		} else {
    			panel.setBorder(null);
    			button.setText("Afficher décorations");
    		}
    	}
     
    }
    Je te remets le code avec les parties concernées surlignées :

    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
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    public class FrameBorder implements Border {
    
    	private String title;
    	public FrameBorder() {
    	}
    	public FrameBorder(String title) {
    		this.title=title;
    	}
    	
    	public void registerFrame(JPanel panel, JFrame frame) {
    		MouseAdapter mouseAdapter = new MouseAdapter() {
    			private boolean drag;
    			private boolean resize; // cette variable sert à savoir qu'on est en train de redimensionner
    			private int cursor;// cette variable permet de savoir dans quelle direction on est en train de redimensionner
    			private Point location;
    			@Override
    			public void mouseClicked(MouseEvent e) {
    				if ( panel.getBorder()==FrameBorder.this && inButton(panel, e.getPoint())) {
    					frame.dispose();
    				}
    			}
    			@Override
    			public void mousePressed(MouseEvent e) {
                                    // lorsqu'on enfonce le bouton de la souris (je ne teste pas le bouton ici, donc on peut le faire avec n'importe quel bouton
    				cursor = getResizeCursor(frame, e.getPoint());
    				if ( cursor!=-1) { // si le cursor est -1, on n'est pas en train de redimensionner, sinon on passe en mode redimensionnement
    					resize=true;
    				}
    				else if ( panel.getBorder()==FrameBorder.this && inTitleBar(panel, e.getPoint())) {
    					drag=true;
    					location = e.getPoint();
    				}
    			}
    			
    			@Override
    			public void mouseMoved(MouseEvent e) {
                                    // lorsqu'on bouge la souris dans une zone qui sert au redimensionnement, et qu'aucun bouton n'est enfoncée, on affiche simplement le curseur adéquat
    				cursor = getResizeCursor(frame, e.getPoint());
    				panel.setCursor(cursor==-1?null:Cursor.getPredefinedCursor(cursor));
    				panel.repaint();
    			}
    			
    			@Override
    			public void mouseDragged(MouseEvent e) {
                                    //lorsqu'on bouge la souris avec un bouton enfoncé et qu'on est en mode redimensionnement
    				if ( resize ) {
    					int dx, dy;
    					switch(cursor) { // le type de curseur nous permet de savoir dans quelle direction on redimensionne (selon les cas, ou bouge le x, le y, le width et ou le height des bounds et on reframe
    					case Cursor.NE_RESIZE_CURSOR:
    						dx = e.getX()-frame.getWidth();
    						dy = -e.getY();
    						if ( frame.getWidth()+dx>=64 && frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX(), 
    								  frame.getY()-dy,
    								  frame.getWidth()+dx,
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					case Cursor.E_RESIZE_CURSOR:
    						dx = e.getX()-frame.getWidth();
    						if ( frame.getWidth()+dx>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX(), 
    								  frame.getY(),
    								  frame.getWidth()+dx,
    								  frame.getHeight()
    								  );
    						}
    						break;
    					case Cursor.NW_RESIZE_CURSOR:
    						dx = -e.getX();
    						dy = -e.getY();
    						if ( frame.getWidth()+dx>=64 && frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX()-dx, 
    								  frame.getY()-dy,
    								  frame.getWidth()+dx,
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					case Cursor.N_RESIZE_CURSOR:
    						dy = -e.getY();
    						if ( frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX(), 
    								  frame.getY()-dy,
    								  frame.getWidth(),
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					case Cursor.SE_RESIZE_CURSOR:
    						dx = e.getX()-frame.getWidth();
    						dy = e.getY()-frame.getHeight();
    						if ( frame.getWidth()+dx>=64 && frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX(), 
    								  frame.getY(),
    								  frame.getWidth()+dx,
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					case Cursor.W_RESIZE_CURSOR:
    						dx = -e.getX();
    						if ( frame.getWidth()+dx>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX()-dx, 
    								  frame.getY(),
    								  frame.getWidth()+dx,
    								  frame.getHeight()
    								  );
    						}
    						break;
    					case Cursor.SW_RESIZE_CURSOR:
    						dx = -e.getX();
    						dy = e.getY()-frame.getHeight();
    						if ( frame.getWidth()+dx>=64 && frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX()-dx, 
    								  frame.getY(),
    								  frame.getWidth()+dx,
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					case Cursor.S_RESIZE_CURSOR:
    						dy = e.getY()-frame.getHeight();
    						if ( frame.getHeight()+dy>=64 ) { // 64 taille mini
    							frame.setBounds(frame.getX(), 
    								  frame.getY(),
    								  frame.getWidth(),
    								  frame.getHeight()+dy
    								  );
    						}
    						break;
    					}
    				}
    				else if ( drag ) {
    					if ( panel.getBorder()==FrameBorder.this ) {
    						//if ( inTitleBar(panel, e.getPoint()) ) {
    							frame.setLocation(frame.getX()+e.getX()-location.x, frame.getY()+e.getY()-location.y);
    						//}
    					}
    					else {
    						drag=false;
    					}
    				}
    			}
    			@Override
    			public void mouseReleased(MouseEvent e) {
    				drag=false;
                                    // quand on relache la souris on sort du mode redimensionnement
    				resize=false;
    			}
    		};
    		panel.addMouseListener(mouseAdapter);
    		panel.addMouseMotionListener(mouseAdapter);
    	}
    
            // la méthode qui permet de déterminer dans quelle direction on redimensionnerait si on enfonçait le bouton de la souris, en fonction de la bordure qu'on survole	
            // j'ai pris une base de 3 pixels en bordure de frame
    	protected int getResizeCursor(JFrame frame, Point point) {
    		int cursor = -1;
    		if ( point.x<3 ) {
    			cursor=Cursor.W_RESIZE_CURSOR;
    		}
    		else if ( point.x>frame.getWidth()-3 ) {
    			cursor=Cursor.E_RESIZE_CURSOR;
    		}
    		if ( point.y<3 ) {
    			switch( cursor ) {
    			case Cursor.E_RESIZE_CURSOR:
    				cursor=Cursor.NE_RESIZE_CURSOR;
    				break;
    			case Cursor.W_RESIZE_CURSOR:
    				cursor=Cursor.NW_RESIZE_CURSOR;
    				break;
    			default:
    				cursor=Cursor.N_RESIZE_CURSOR;
    			}
    		}
    		else if ( point.y>frame.getHeight()-3 ) {
    			switch( cursor ) {
    			case Cursor.E_RESIZE_CURSOR:
    				cursor=Cursor.SE_RESIZE_CURSOR;
    				break;
    			case Cursor.W_RESIZE_CURSOR:
    				cursor=Cursor.SW_RESIZE_CURSOR;
    				break;
    			default:
    				cursor=Cursor.S_RESIZE_CURSOR;
    			}
    		}
    		return cursor;
    	}
    	public void setTitle(String title) {
    		this.title=title;
    	}
    	
    	@Override
    	public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    		Graphics2D g2d = (Graphics2D) g.create(x, y, width, height);
    		Rectangle componentBounds = new Rectangle(x,y,width,height);
    		Insets insets = getBorderInsets(c);
    		Rectangle innerBounds = new Rectangle(x+insets.left,y+insets.top,width-insets.left-insets.right,height-insets.top-insets.bottom);
    		Area area = new Area(componentBounds);
    		area.subtract(new Area(innerBounds));
    		g2d.setClip(area);
    		g2d.setPaint(Color.CYAN);
    		g2d.fillRect(x, y, width-1, height-1);;
    		g2d.setPaint(Color.GRAY);
    		g2d.drawRect(x, y, width-1, height-1);
    		g2d.drawRect(innerBounds.x-1, innerBounds.y-1, innerBounds.width+1, innerBounds.height+1);
    
    		if ( title!=null ) {
    			g2d.setPaint(Color.BLACK);
    			g2d.setFont(new Font("Arial",Font.BOLD,12));
    			FontMetrics fm = g2d.getFontMetrics();
    			Rectangle2D stringBounds = fm.getStringBounds(title, g2d);
    			if ( stringBounds.getWidth()>width-80 ) {
    				stringBounds.setFrame(32, 15-stringBounds.getHeight()/2, width-80, stringBounds.getHeight()+4);
    				g2d.clip(stringBounds);
    			}
    			else {
    				stringBounds.setFrame(32, 15-stringBounds.getHeight()/2, stringBounds.getWidth()+4, stringBounds.getHeight()+4);
    			}
    			g2d.drawString(title, 34, 16+(fm.getAscent()-fm.getDescent())/2);
    			area.subtract(new Area(stringBounds));
    			g2d.setClip(area);
    		}
    		g2d.setPaint(Color.GRAY);
    		for(int i=5; i<28; i+=3) {
    			g2d.drawLine(3, i, width-6-32, i);
    		}
    		g2d.drawRect(width-32, 3, 25, 25);
    
    		Area cross = new Area(new Rectangle(width-22,5,5,21));
    		cross.add(new Area(new Rectangle(width-30,13,21,5)));
    		AffineTransform af=AffineTransform.getRotateInstance(Math.PI/4, width-19.5, 15.5);
    		af.translate(0.5, 0);
    		cross = cross.createTransformedArea(af);
    		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    		if ( c.getMousePosition()!=null && inButton(c,c.getMousePosition()) ) { 
    			g2d.fill(cross);
    		}
    		g2d.draw(cross);
    		
    		g2d.dispose();
    	}
    	
    	public boolean inTitleBar(Component c, Point p) {
    		if (p==null ) return false;
    		return new Rectangle(0,0,c.getWidth(),32).contains(p) && !inButton(c, p);
    	}
    	public boolean inButton(Component c, Point p) {
    		if (p==null ) return false;
    		return new Rectangle(c.getWidth()-32, 3, 25, 25).contains(p);
    	}
    
    	@Override
    	public Insets getBorderInsets(Component c) {
    		return new Insets(32,4,4,4);
    	}
    
    	@Override
    	public boolean isBorderOpaque() {
    		return true;
    	}
    
    	
    	public static void main(String[] args) {
    
    		JFrame frame = new JFrame();
    		frame.setUndecorated(true);
    		
    		FrameBorder frameBorder = new FrameBorder("Démo");
    		
    		JPanel panel = new JPanel(new GridBagLayout());
    		panel.setBorder(frameBorder);
    
    		JButton button = new JButton("Supprimer dérocations");
    		button.addActionListener(e -> toggleDecorations(panel, button, frameBorder));
    		panel.add(button);
    
    		frame.add(panel);
    
    		frameBorder.registerFrame(panel, frame);
    		frame.setSize(300, 300);
    		frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
    
    	}
    
    	private static void toggleDecorations(JPanel panel, JButton button, Border border) {
    		Border currentBorder = panel.getBorder();
    		if (currentBorder==null) {
    			panel.setBorder(border);
    			button.setText("Supprimer décorations");
    		} else {
    			panel.setBorder(null);
    			button.setText("Afficher décorations");
    		}
    	}
    	
    }
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  6. #66
    Membre du Club
    Homme Profil pro
    Artisant
    Inscrit en
    Avril 2018
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Corse (Corse)

    Informations professionnelles :
    Activité : Artisant
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2018
    Messages : 169
    Points : 60
    Points
    60
    Par défaut
    Merci,

    je vais regarde ceci et essayé de l'implante.

    bonne soirée

    Fred

  7. #67
    Membre du Club
    Homme Profil pro
    Artisant
    Inscrit en
    Avril 2018
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Corse (Corse)

    Informations professionnelles :
    Activité : Artisant
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2018
    Messages : 169
    Points : 60
    Points
    60
    Par défaut
    Bonjour,

    Je cherche la "formule" pour integré différente table dans mon programme.

    je cherche a faire en sorte que le déplacement automatique de la souris accelére plus on reste appuyé.

    A l'heure actuel je n'es qu'une valeur selon le mode normale, X2, X4:

    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
    String name = "Default";
     
        int correctionX = 0;
        int correctionY = 0;
        int beforeShotSleep = 1;
        int afterShotSleep = 1;
     
        int correctionZoomX = 0;
        int correctionZoomY = 0;
        int beforeShotSleepZoom = 1;
        int afterShotSleepZoom = 1;
     
        int correctionRightClickX = 0;
        int correctionRightClickY = 0; // c'est ici que je cherche a créer une table du style : 0,3,5,8,15.....; mais cela ne marche pas 
     
        int beforeShotSleepRightClick = 1;
        int afterShotSleepRightClick = 1;
     
        int correctionX2RightClickX = 0;
        int correctionX2RightClickY = 0;   // c'est ici que je cherche a créer une table du style : 0,3,5,8,15.....; mais cela ne marche pas 
     
        int correctionX4RightClickX = 0;
        int correctionX4RightClickY = 0;   // c'est ici que je cherche a créer une table du style : 0,3,5,8,15.....; mais cela ne marche pas 
     
        int beforeShotSleepRightClickZoom = 1;
        int afterShotSleepRightClickZoom = 1;

    Je pense que je formule mal le code.

    Merci

    Bonne journée

    Fred

  8. #68
    Membre du Club
    Homme Profil pro
    Artisant
    Inscrit en
    Avril 2018
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Corse (Corse)

    Informations professionnelles :
    Activité : Artisant
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2018
    Messages : 169
    Points : 60
    Points
    60
    Par défaut
    J'ai tente de le faire avec les tableau; int[],

    j'arrive a faire quelqe truc mais je coince sur un probleme.

    java me dit que je ne peu pas, message d'erreur : Operator '+' cannot be applied to 'int', 'int[] ligne 103

    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
    package r1bellu2b.norecoil;
     
    import java.awt.*;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import org.jnativehook.mouse.NativeMouseEvent;
    import org.jnativehook.mouse.NativeMouseInputListener;
     
    public class MouseListener implements NativeMouseInputListener {
     
      static ExecutorService executorService = Executors.newFixedThreadPool(4);
     
     
      public void nativeMouseClicked(NativeMouseEvent e) {
      }
     
      public void nativeMousePressed(NativeMouseEvent e) {
     
     
        if (e.getButton() == 2) {
          Main.rightClick = true;
        }
      if (e.getButton() != 1) {
     
     
        return;
     
     }
     
        Main.shooting = true;
        Config currentConfig = ConfigManager1.getInstance1().getCurrentConfig();
     
        executorService.submit(() -> {
          try {
            Robot robot = new Robot();
            robot.setAutoDelay(0);
     
            Point point ;
     
            int correctionX = 0;
            int[] correctionY = {0};
            int beforeSleep = 0;
            int afterSleep = 0;
     
     
     
            while (Main.enabled && Main.shooting) {
     
              switch(Main.choix) {
     
     
                case CHOIX1:
     
                  if (Main.rightClick) {
     
                    correctionX = currentConfig.correctionRightClickX;
                    correctionY = currentConfig.correctionRightClickY;
                    beforeSleep = currentConfig.beforeShotSleepRightClick;
                    afterSleep = currentConfig.afterShotSleepRightClick;
     
                  } else {
                    correctionX = currentConfig.correctionX;
                    correctionY = currentConfig.correctionY;
                    beforeSleep = currentConfig.beforeShotSleep;
                    afterSleep = currentConfig.afterShotSleep;
     
                }
     
                break;
                case CHOIX2:
                  if (Main.rightClick) {
     
                    correctionX = currentConfig.correctionX2RightClickX;
                    correctionY = currentConfig.correctionX2RightClickY;
                    beforeSleep = currentConfig.beforeShotSleepRightClickZoom;
                    afterSleep = currentConfig.afterShotSleepRightClickZoom;
                  } else {
                    correctionX = currentConfig.correctionZoomX;
                    correctionY = currentConfig.correctionZoomY;
                    beforeSleep = currentConfig.beforeShotSleepZoom;
                    afterSleep = currentConfig.afterShotSleepZoom;
                  }
     
                  break;
                case CHOIX3:
                  if (Main.rightClick) {
     
                    correctionX = currentConfig.correctionX4RightClickX;
                    correctionY = currentConfig.correctionX4RightClickY;
                    beforeSleep = currentConfig.beforeShotSleepRightClickZoom;
                    afterSleep = currentConfig.afterShotSleepRightClickZoom;
                  } else {
                    correctionX = currentConfig.correctionZoomX;
                    correctionY = currentConfig.correctionZoomY;
                    beforeSleep = currentConfig.beforeShotSleepZoom;
                    afterSleep = currentConfig.afterShotSleepZoom;
                  }
     
              }
              Thread.sleep(beforeSleep);
              point = MouseInfo.getPointerInfo().getLocation();
              robot.mouseMove(point.x , point.y);
              robot.mouseMove(point.x + correctionX, point.y + correctionY);   //ERREUR ICI
     
              Thread.sleep(afterSleep);
            }
          } catch (Exception e1) {
            e1.printStackTrace();
          }
        });
      }
     
      public void nativeMouseReleased(NativeMouseEvent e) {
        if (e.getButton() == 2) {
          Main.rightClick = false;
        }
        if (e.getButton() == 1) {
          Main.shooting = false;
        }
      }
      public void nativeMouseMoved(NativeMouseEvent e) {
      }
      public void nativeMouseDragged(NativeMouseEvent e) {
      }
     }
    J'ai compris que c'est a cause que robot.mouseMove est en int et que correctionY est en int[].

    Mais je ne vois pas comment faire autrement pour entre des variable a mon mouvement de souris.


    MERCI


    Fred

Discussions similaires

  1. Réponses: 5
    Dernier message: 19/05/2008, 20h58
  2. [PB 10.5] Afficher une image dans une fenêtre
    Par cagoule dans le forum Powerbuilder
    Réponses: 2
    Dernier message: 27/02/2007, 22h22
  3. Réponses: 4
    Dernier message: 26/01/2007, 07h39
  4. Afficher un shell dans une fenêtre wxWidget
    Par BlueCat dans le forum wxWidgets
    Réponses: 3
    Dernier message: 05/09/2006, 22h38
  5. afficher une image dans une fenêtre windows
    Par yashiro dans le forum Bibliothèques
    Réponses: 3
    Dernier message: 02/05/2006, 16h30

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