gestionnaires.java
4.53 KB
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
package tp1;
import javax.swing.*;
import java.awt.*;
public class gestionnaires {
public static final int width = 500;
public static final int height = 400;
public static void main(String[] args) {
//question 16
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
} catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
JFrame win = new JFrame();
win.setSize( width, height);
win.setLocationRelativeTo(null);
/*
//questioon 6
JButton toto1 = new JButton("button1");
JButton toto2 = new JButton("button2");
JButton toto3 = new JButton("button3");
JButton toto4 = new JButton("button4");
JButton toto5 = new JButton("button5");
win.add(toto1, BorderLayout.EAST);
win.add(toto2, BorderLayout.WEST);
win.add(toto3, BorderLayout.NORTH);
win.add(toto4, BorderLayout.SOUTH);
win.add(toto5, BorderLayout.CENTER);
*/
/*
//question 7
FlowLayout layout = new FlowLayout();
win.setLayout(layout);
JButton[] buttons = new JButton[20];
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new JButton("button "+ i);
win.add(buttons[i]);
}
*/
/*
//question 8
GridLayout layout = new GridLayout(4,4);
win.setLayout(layout);
JButton[] buttons = new JButton[16];
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new JButton("button "+ i);
win.add(buttons[i]);
}
*/
/*
//question 9
BoxLayout layout = new BoxLayout(win.getContentPane(), BoxLayout.PAGE_AXIS);
win.setLayout(layout);
JButton[] buttons = new JButton[3];
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new JButton("button "+ i);
buttons[i].setPreferredSize(new Dimension(width-1, 50));
}
win.add(buttons[0]);
win.add(Box.createRigidArea(new Dimension(0, 20)));
win.add(buttons[1]);
win.add(Box.createVerticalGlue());
win.add(buttons[2]);
*/
/*
//question 10
GridBagLayout layout = new GridBagLayout();
win.setLayout(layout);
GridBagConstraints[] c = new GridBagConstraints[10];
for (int i = 0; i < c.length; i++) {
c[i] = new GridBagConstraints();
}
c[0].gridx = 0;
c[0].gridy = 0;
c[1].gridx = 1;
c[1].gridy = 0;
c[2].gridx = 2;
c[2].gridy = 0;
c[3].gridx = 3;
c[3].gridy = 0;
c[4].gridx = 0;
c[4].gridy = 1;
c[4].gridwidth = 4;
c[5].gridx = 0;
c[5].gridy = 2;
c[5].gridwidth = 3;
c[6].gridx = 3;
c[6].gridy = 2;
c[7].gridx = 0;
c[7].gridy = 3;
c[7].gridheight = 2;
c[8].gridx = 1;
c[8].gridy = 3;
c[8].gridwidth = 3;
c[9].gridx = 1;
c[9].gridy = 4;
c[9].gridwidth = 3;
JButton[] buttons = new JButton[10];
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new JButton("button "+ i);
c[i].fill = GridBagConstraints.BOTH;
win.add(buttons[i], c[i]);
}
*/
/*
//question 12
win.setLayout(null);
int nbouton = 10;
int xstep = width/(nbouton +1);
int ystep = height/(nbouton +1);
JButton[] buttons = new JButton[nbouton];
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new JButton("button "+ i);
win.add(buttons[i]);
buttons[i].setBounds( i*xstep, i*ystep,100,30);
buttons[i].repaint();
}
*/
JButton toto1 = new JButton("button1");
JButton toto2 = new JButton("button2");
JButton toto4 = new JButton("button4");
JButton toto5 = new JButton("button5");
JPanel toto3 = new JPanel();
toto3.add(new Button("bouton"));
toto3.add(new Button("bouton"));
toto3.add(new Button("bouton"));
win.add(toto1, BorderLayout.EAST);
win.add(toto2, BorderLayout.WEST);
win.add(toto3, BorderLayout.NORTH);
win.add(toto4, BorderLayout.SOUTH);
win.add(toto5, BorderLayout.CENTER);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
}