-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAWTLayoutmanagers.java
60 lines (45 loc) · 1.47 KB
/
AWTLayoutmanagers.java
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
package javaGUI;
import java.awt.*;
import java.awt.event.*;
public class AWTLayoutmanagers {
public static void main(String[] args) {
// TODO Auto-generated method stub
Frame frame = new Frame("AWT application");
//set the window size
frame.setSize(400,400);
FlowLayout flow = new FlowLayout();
Panel panel1 = new Panel(flow);
panel1.add(new Button("Button1"));
panel1.add(new Button("Button2"));
panel1.add(new Button("Button3"));
panel1.add(new Button("Button4"));
panel1.add(new Button("Button5"));
frame.add(panel1);
BorderLayout bl = new BorderLayout();
frame.setLayout(bl);
Button b1 = new Button("Button1");
Button b2 = new Button("Button2");
Button b3 = new Button("Button3");
Button b4 = new Button("Button4");
Button b5 = new Button("Button5");
frame.add(b1,BorderLayout.NORTH);
frame.add(b2,BorderLayout.EAST);
frame.add(b3,BorderLayout.WEST);
frame.add(b4,BorderLayout.SOUTH);
frame.add(b5,BorderLayout.CENTER);
GridLayout grid = new GridLayout();
Panel panel2 = new Panel(grid);
panel2.add(new Button("Button1"));
panel2.add(new Button("Button2"));
panel2.add(new Button("Button3"));
panel2.add(new Button("Button4"));
frame.add(panel2);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
//set visibility for the window
frame.setVisible(true);
}
}