Bonsoir,
Cet après-midi j'ai eu des échanges pour réaliser la 1ere étape de mon sujet.
Il s'agissait de créer une fenêtre avec un message basique.
Il s'agit maintenant de créer une zone pour un nom et un password.
J'ai avancé sur 2 options de codes.
Merci de bien vouloir m'aiguiller.
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 import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.JFrame; import java.awt.Dimension; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; public class Td30Ihm { Td30Ihm () { createAndShowGUI (); } private static void createAndShowGUI() { JFrame frame = new JFrame("NFA035_td30"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myPanel = new JPanel(new GridLayout(3,2,1,1)); buttons_panel = new JPanel(new FlowLayout()); username_label = new JLabel("Username: "); password_label = new JLabel("Password: "); username = new JTextField(20); password = new JPasswordField(20); myPanel.add(username_label); myPanel.add(username); myPanel.add(password_label); myPanel.add(password); getContentPane().add(myPanel, BorderLayout.CENTER); getContentPane().add(buttons_panel, BorderLayout.PAGE_END); textLabel.setPreferredSize(new Dimension(300,200)); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); } }
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 import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.JFrame; import java.awt.Dimension; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; public class Td30Ihm { Td30Ihm () { createAndShowGUI (); } private static void createAndShowGUI() { setTitle("NFA035"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JLabel nomLabel = new JLabel("Nom : "); JTextField nomText = new JTextField(10); nomText.setMaximumSize(nomText.getPreferredSize()); Box hBox1 = Box.createHorizontalBox(); hBox1.add(nomLabel); hBox1.add(Box.createHorizontalStrut(5)); hBox1.add(nomText); JLabel motdepasseLabel = new JLabel("Mot de passe : "); JTextField motdepasseText = new JTextField(10); motdepasseText.setMaximumSize(motdepasseText.getPreferredSize()); Box hBox2 = Box.createHorizontalBox(); hBox2.add(motdepasseLabel); hBox2.add(Box.createHorizontalStrut(5)); hBox2.add(motdepasseText); Box vBox = Box.createVerticalBox(); vBox.add(hBox1); vBox.add(hBox2); Container c = getContentPane(); c.add(vBox,BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); } }
Partager