File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
src/org/cyberpwn/react/ui Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .cyberpwn .react .ui ;
2+
3+ import java .awt .event .KeyAdapter ;
4+ import java .awt .event .KeyEvent ;
5+
6+ import javax .swing .JTextField ;
7+
8+ public class PortJTextField extends JTextField
9+ {
10+ private static final long serialVersionUID = 1L ;
11+
12+ public PortJTextField ()
13+ {
14+ addKeyListener (new KeyAdapter ()
15+ {
16+ public void keyTyped (KeyEvent e )
17+ {
18+ char ch = e .getKeyChar ();
19+
20+ if (!isNumber (ch ) && !isValidSignal (ch ) && !validatePoint (ch ) && ch != '\b' )
21+ {
22+ e .consume ();
23+ }
24+ }
25+ });
26+
27+ }
28+
29+ private boolean isNumber (char ch )
30+ {
31+ return ch >= '0' && ch <= '9' ;
32+ }
33+
34+ private boolean isValidSignal (char ch )
35+ {
36+ if ((getText () == null || "" .equals (getText ().trim ())) && ch == '-' )
37+ {
38+ return false ;
39+ }
40+
41+ return false ;
42+ }
43+
44+ private boolean validatePoint (char ch )
45+ {
46+ return false ;
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments