FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaExercises/Head First Java/SimpleChatClientA.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
/
Head First Java
/
SimpleChatClientA.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (44 loc) · 1.49 KB
Breadcrumbs
JavaExercises
/
Head First Java
/
SimpleChatClientA.java
Copy path
File metadata and controls
50 lines (44 loc) · 1.49 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
import
java
.
io
.*;
import
java
.
net
.*;
import
javax
.
swing
.*;
import
java
.
awt
.*;
import
java
.
awt
.
event
.*;
public
class
SimpleChatClientA
{
JTextField
outgoing
;
PrintWriter
writer
;
Socket
sock
;
public
void
go
() {
JFrame
frame
=
new
JFrame
(
"Ludicrously Simple Chat Client"
);
frame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
JPanel
mainPanel
=
new
JPanel
();
outgoing
=
new
JTextField
(
25
);
JButton
sendButton
=
new
JButton
(
"Send"
);
sendButton
.
addActionListener
(
new
SendButtonListener
());
mainPanel
.
add
(
outgoing
);
mainPanel
.
add
(
sendButton
);
frame
.
getContentPane
().
add
(
BorderLayout
.
CENTER
,
mainPanel
);
setUpNetworking
();
frame
.
setSize
(
400
,
100
);
frame
.
setVisible
(
true
);
}
private
void
setUpNetworking
() {
try
{
sock
=
new
Socket
(
"127.0.0.1"
,
5000
);
writer
=
new
PrintWriter
(
sock
.
getOutputStream
());
System
.
out
.
println
(
"Networking established."
);
}
catch
(
Exception
ex
) {
ex
.
printStackTrace
(); }
}
public
class
SendButtonListener
implements
ActionListener
{
public
void
actionPerformed
(
ActionEvent
ev
) {
try
{
writer
.
println
(
outgoing
.
getText
());
writer
.
flush
();
}
catch
(
Exception
ex
) {
ex
.
printStackTrace
(); }
outgoing
.
setText
(
""
);
outgoing
.
requestFocus
();
}
}
public
static
void
main
(
String
[]
args
) {
new
SimpleChatClientA
().
go
();
}
}
Back
|
FazBrowse Home
|
New Git URL