-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJFrameDemo.java
More file actions
46 lines (37 loc) · 1.29 KB
/
JFrameDemo.java
File metadata and controls
46 lines (37 loc) · 1.29 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
import javax.swing.*;
import java.awt.*;
public class SimpleSwingForm extends JFrame {
public SimpleSwingForm() {
// Set frame properties
setTitle("Basic Form");
setSize(400, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(4, 2, 10, 10)); // 4 rows, 2 columns, with gaps
setLocationRelativeTo(null); // Center the window
// Create components
JLabel nameLabel = new JLabel("Name:");
JTextField nameField = new JTextField();
JLabel emailLabel = new JLabel("Email:");
JTextField emailField = new JTextField();
JLabel ageLabel = new JLabel("Age:");
JTextField ageField = new JTextField();
JButton submitButton = new JButton("Submit");
// No ActionListener (no event handling)
// Add components to the frame
add(nameLabel);
add(nameField);
add(emailLabel);
add(emailField);
add(ageLabel);
add(ageField);
add(new JLabel()); // Empty cell for alignment
add(submitButton);
setVisible(true);
}
public static void main(String[] args) {
// Run in the Event Dispatch Thread (EDT)
SwingUtilities.invokeLater(() -> {
new SimpleSwingForm();
});
}
}