salut tout le monde
je voudrais savoir comment faire pour afficher un JFrame tout en evitant de l'afficher deux fois.
merci d'avance pour votre aide.
salut tout le monde
je voudrais savoir comment faire pour afficher un JFrame tout en evitant de l'afficher deux fois.
merci d'avance pour votre aide.
Bonjour
voici un exemple
venant directement de la doc java ici
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 import java.awt.*; import java.awt.event.*; import javax.swing.*; /* FrameDemo.java requires no other files. */ public class FrameDemo { /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("FrameDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel emptyLabel = new JLabel(""); emptyLabel.setPreferredSize(new Dimension(175, 100)); frame.getContentPane().add(emptyLabel, BorderLayout.CENTER); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
Page sur Developpez : http://pbriand.developpez.com
arrange toi à toujours fairedans ta méthode main et non dans ton constructeur
Code : Sélectionner tout - Visualiser dans une fenêtre à part taframe.setVisible(true);
salut
tout en évitant de l'afficher deux fois.
vous voulez dire quoi par sa est ce que l'affichage du votre frame se fait pas mal de fois pendant l' utilisation de votre application si c'est le cas vous devez faire disparaitre votre frame et l'afficher à nouveau.
Partager