-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTestPanels.java
More file actions
40 lines (33 loc) · 1.13 KB
/
TestPanels.java
File metadata and controls
40 lines (33 loc) · 1.13 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
package programs;
import java.awt.*;
import javax.swing.*;
public class TestPanels extends JFrame {
public TestPanels() {
// Create panel p1 for the buttons and set GridLayout
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(4, 3));
// Add buttons to the panel
for (int i = 1; i <= 9; i++) {
p1.add(new JButton("" + i));
}
p1.add(new JButton("" + 0));
p1.add(new JButton("Start"));
p1.add(new JButton("Stop"));
// Create panel p2 to hold a text field and p1
JPanel p2 = new JPanel(new BorderLayout());
p2.add(new JTextField("Time to be displayed here"), BorderLayout.NORTH);
p2.add(p1, BorderLayout.CENTER);
// add contents into the frame
add(p2, BorderLayout.EAST);
add(new JButton("Food to be placed here"), BorderLayout.CENTER);
}
/** Main method */
public static void main(String[] args) {
TestPanels frame = new TestPanels();
frame.setTitle("The Front View of a Microwave Oven");
frame.setSize(400, 250);
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}