-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanel_Demo_1.java
More file actions
51 lines (36 loc) · 1.14 KB
/
Panel_Demo_1.java
File metadata and controls
51 lines (36 loc) · 1.14 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
package panel_demo;
//PanelDemo.java
//Using a JPanel to help lay out components.
//Java core packages
import java.awt.*;
import java.awt.event.*;
//Java extension packages
import javax.swing.*;
public class Panel_Demo_1 extends JFrame {
private JPanel buttonPanel;
private JButton buttons[];
// set up GUI
public Panel_Demo_1() {
super("Panel Demo");
// get content pane
Container container = getContentPane();
// create buttons array
buttons = new JButton[5];
// set up panel and set its layout
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1, buttons.length));
// create and add buttons
for (int count = 0; count < buttons.length; count++) {
buttons[count] = new JButton("Button " + (count + 1));
buttonPanel.add(buttons[count]);
}
container.add(buttonPanel, BorderLayout.SOUTH);
setSize(425, 150);
setVisible(true);
}
// execute application
public static void main(String args[]) {
Panel_Demo_1 application = new Panel_Demo_1();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} // end class PanelDemo