-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyAscoltatore.java
More file actions
37 lines (30 loc) · 847 Bytes
/
KeyAscoltatore.java
File metadata and controls
37 lines (30 loc) · 847 Bytes
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
package GUI;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class KeyAscoltatore implements KeyListener {
private TextField t;
private Label lb;
public KeyAscoltatore(TextField t, Label lb) {
this.t = t;
this.lb = lb;
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_ENTER) {
try {
int n = Integer.parseInt(t.getText());
lb.setText(Integer.toString(n));
} catch (Exception err) {
System.out.println("Errore nell'interfaccia");
}
}
}
@Override
public void keyReleased(KeyEvent e) {
}
}