-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyApplication.java
More file actions
63 lines (54 loc) · 1.82 KB
/
Copy pathMyApplication.java
File metadata and controls
63 lines (54 loc) · 1.82 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
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package awt;
import java.awt.*;
import java.awt.event.*;
public class MyApplication extends Frame {
private TextField textField;
private Label label;
public MyApplication() {
// Set layout manager
setLayout(new FlowLayout());
// Create label
label = new Label("You input: ");
add(label);
// Create text field
textField = new TextField(20);
add(textField);
// Create ADD button
Button addButton = new Button("ADD");
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String input = textField.getText();
label.setText("You input: " + input);
}
});
add(addButton);
// Create CLEAR button
Button clearButton = new Button("CLEAR");
clearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField.setText("");
label.setText("You input: ");
}
});
add(clearButton);
// Create EXIT button
Button exitButton = new Button("EXIT");
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
add(exitButton);
// Set frame properties
setTitle("My Application");
setSize(300, 150);
setVisible(true);
}
public static void main(String[] args) {
new MyApplication();
}
}