-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardHolderKeyListener.java
More file actions
35 lines (28 loc) · 920 Bytes
/
CardHolderKeyListener.java
File metadata and controls
35 lines (28 loc) · 920 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
//816034459
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CardHolderKeyListener extends KeyAdapter {
private CreditCardGUI ccg;
public CardHolderKeyListener(CreditCardGUI gui) {
this.ccg = gui;
}
public void keyTyped(KeyEvent e){
}
public void keyPressed(KeyEvent e){
}
public void keyReleased(KeyEvent e) {
String name = ccg.getName().getText();
//Checking validity of input
if (name.isEmpty()) {
ccg.getMessageLabel1().setText("The name on the card cannot be blank");
}
else if (!name.matches("[a-zA-Z ]+")) {
ccg.getMessageLabel1().setText("Invalid Input- input must only be letters");
}
else {
ccg.getMessageLabel1().setText("");
ccg.getOverlayLabel5().setText(name.toUpperCase());
}
}
}