-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextField_Label.java
More file actions
34 lines (29 loc) · 1.01 KB
/
textField_Label.java
File metadata and controls
34 lines (29 loc) · 1.01 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
import java.awt.*;
import java.awt.event.*;
public class TextFieldExample {
public static void main(String[] args) {
Frame frame = new Frame("Text Field Example");
Label label = new Label("Enter your name:");
TextField textField = new TextField();
label.setBounds(20, 50, 150, 20);
textField.setBounds(20, 80, 150, 20);
Button button = new Button("Submit");
button.setBounds(20, 110, 80, 30);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Submitted Name: " + textField.getText());
}
});
frame.add(label);
frame.add(textField);
frame.add(button);
frame.setSize(300, 200);
frame.setLayout(null);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
}
}