Skip to content

Commit 2bb1deb

Browse files
committed
Text field for ports
1 parent 9ef1506 commit 2bb1deb

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
}

0 commit comments

Comments
 (0)