FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaExercises/Experiments/RegExpTest.java at master · biblelamp/JavaExercises · GitHub
biblelamp
/
JavaExercises
Public
Notifications
You must be signed in to change notification settings
Fork
130
Star
153
Code
Issues
1
Pull requests
9
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaExercises
/
Experiments
/
RegExpTest.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (67 loc) · 2.55 KB
Breadcrumbs
JavaExercises
/
Experiments
/
RegExpTest.java
Copy path
File metadata and controls
73 lines (67 loc) · 2.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Java. Test for regexp
*
* @author Sergey Iryupin
* @version 0.1 dated October 10, 2016
*/
import
java
.
awt
.*;
import
java
.
awt
.
event
.*;
import
javax
.
swing
.*;
import
java
.
util
.*;
class
RegExpTest
extends
JFrame
{
final
String
TITLE_OF_PROGRAM
=
"RegExp Testing"
;
final
static
int
WINDOW_WIDTH
=
500
;
final
static
int
WINDOW_HEIGHT
=
400
;
final
static
int
START_POSITION
=
200
;
JTextField
pattern
;
JTextArea
textIn
;
JTextArea
textOut
;
public
static
void
main
(
String
[]
args
) {
new
RegExpTest
();
}
RegExpTest
() {
setTitle
(
TITLE_OF_PROGRAM
);
setDefaultCloseOperation
(
EXIT_ON_CLOSE
);
setBounds
(
START_POSITION
,
START_POSITION
,
WINDOW_WIDTH
,
WINDOW_HEIGHT
);
setMinimumSize
(
new
Dimension
(
WINDOW_WIDTH
,
WINDOW_HEIGHT
));
Font
font
=
new
Font
(
""
,
Font
.
BOLD
,
22
);
pattern
=
new
JTextField
(
"[ {,|.}?]+"
,
22
);
// [\s\t\'\"\-{,|.|\?|\!}?]
pattern
.
setFont
(
font
);
JButton
btnGo
=
new
JButton
(
"Go"
);
btnGo
.
addActionListener
(
new
ActionListener
() {
public
void
actionPerformed
(
ActionEvent
e
) {
TreeMap
<
String
,
Integer
>
tm
=
new
TreeMap
<
String
,
Integer
>();
Set
<
Map
.
Entry
<
String
,
Integer
>>
set
=
tm
.
entrySet
();
String
[]
lines
=
textIn
.
getText
().
split
(
"
\\
n"
);
for
(
String
line
:
lines
) {
//System.out.println(line);
String
[]
words
=
line
.
toLowerCase
().
split
(
pattern
.
getText
());
for
(
String
word
:
words
) {
int
value
=
0
;
try
{
value
=
tm
.
get
(
word
);
}
catch
(
NullPointerException
ex
) { }
tm
.
put
(
word
,
value
+
1
);
}
}
textOut
.
setText
(
null
);
for
(
Map
.
Entry
<
String
,
Integer
>
o
:
set
) {
textOut
.
append
(
o
.
getKey
() +
": "
+
o
.
getValue
() +
"
\n
"
);
}
textOut
.
append
(
"The book has "
+
tm
.
size
() +
" unique words."
);
}
});
JPanel
btnPanel
=
new
JPanel
();
btnPanel
.
add
(
pattern
);
btnPanel
.
add
(
btnGo
);
textIn
=
new
JTextArea
(
10
,
10
);
textIn
.
setLineWrap
(
true
);
textOut
=
new
JTextArea
(
10
,
10
);
JScrollPane
scrollOut
=
new
JScrollPane
(
textOut
);
JScrollPane
scrollIn
=
new
JScrollPane
(
textIn
);
add
(
BorderLayout
.
NORTH
,
btnPanel
);
add
(
BorderLayout
.
CENTER
,
scrollIn
);
add
(
BorderLayout
.
SOUTH
,
scrollOut
);
setVisible
(
true
);
}
}
Back
|
FazBrowse Home
|
New Git URL