-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSwingTextField.java
More file actions
47 lines (36 loc) · 1.1 KB
/
SwingTextField.java
File metadata and controls
47 lines (36 loc) · 1.1 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
package src.uni.lessons.jswing;
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.event.*;
public class SwingTextField extends JFrame implements ActionListener {
private JLabel jLabel;
private JTextField jTextField;
private JButton jButton;
public SwingTextField(String title) {
super(title);
}
public void createWindow() {
setSize(200, 300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
jLabel = new JLabel("Enter text");
jTextField = new JTextField(10);
jButton = new JButton("Update Label");
jButton.addActionListener(this);
add(jLabel);
add(jTextField);
add(jButton);
}
public void actionPerformed(ActionEvent e) {
String text = jTextField.getText();
jLabel.setText(text);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SwingTextField("Textfield Demo").createWindow();
}
});
}
}