bonsoir
je veux bien afficher une fenetre comme jdialog au dessus de ma fenetre en cliquant sur bouton
la fenetre jdialog ouvre mais comme si j'ai ouvri une fenetre normal pas jdialog
je vous montre le code
la fenetre frame qui contient bouton pour ouvrir la fenetre jdialogue
et la fenetre jdialogue
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 import javax.swing.SwingUtilities; import javax.swing.JPanel; import javax.swing.JFrame; import java.awt.Rectangle; import java.awt.Color; import javax.swing.JButton; public class caution extends JFrame { public static caution musta1=null; JPanel jContentPane = null; private JPanel jPanel = null; private JButton jButton = null; private JPanel getJPanel() { if (jPanel == null) { jPanel = new JPanel(); jPanel.setLayout(null); jPanel.setBounds(new Rectangle(8, 5, 745, 512)); jPanel.setBackground(new Color(0, 138, 255)); jPanel.add(getJButton(), null); } return jPanel; } private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setBounds(new Rectangle(53, 209, 34, 25)); jButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { cherche a = new cherche(null); a.setVisible(true); } }); } return jButton; } public static void main(String[] args) { // TODO Auto-generated method stub SwingUtilities.invokeLater(new Runnable() { public void run() { caution thisClass = new caution(); thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); thisClass.setVisible(true); thisClass.setResizable (false); thisClass.setLocationRelativeTo(null); } }); } public caution() { super(); initialize(); } private void initialize() { //musta1=this; this.setSize(803, 673); this.setBackground(Color.orange); this.setContentPane(getJContentPane()); this.setTitle("TRC-EXL-RTO-INF"); } private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.setBackground(new Color(0, 138, 255)); jContentPane.add(getJPanel(), null); } return jContentPane; } }
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 import javax.swing.JPanel; import java.awt.Frame; import javax.swing.JDialog; import javax.swing.JFrame; import java.awt.Rectangle; import java.awt.Color; import javax.swing.JButton; public class cherche extends JDialog { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JButton jButton1 = null; private JButton getJButton1() { if (jButton1 == null) { jButton1 = new JButton(); jButton1.setBounds(new Rectangle(171, 189, 78, 41)); jButton1.setText("Annuler"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() setVisible(false); } }); } return jButton1; } public static void main(String[] args) { // TODO Auto-generated method stub } public cherche(Frame owner) { super(owner); initialize(); } private void initialize() { this.setVisible(true);//On la rend visible this.setBackground(Color.orange); this.setBounds(new Rectangle(200, 200, 526, 360)); this.setContentPane(getJContentPane()); this.setTitle("Contrat"); //On lui donne un titre this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable (false); this.setLocationRelativeTo(null); } private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.setBackground(Color.orange); jContentPane.add(getJButton1(), null); } return jContentPane; } }
Partager