— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet480/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   476   477   478   479   480   481   482   483   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

final 
chat client
This is mostly GUI code you’ve seen 
before. Nothing special except the 
highlighted part where we start the 
new ‘reader’ thread.
We’re starting a new thread, 
using a new inner class as 
the Runnable (job) for the 
thread. The thread’s job is 
to read from the server’s 
socket stream, displaying 
any incoming messages in the 
scrolling text area. 
Yes, there really IS an 
end to this chapter. 
But not yet...


networking 
and
threads
you are here
4
519
private void setUpNetworking() { 
 
try {
sock = new Socket(“127.0.0.1”, 5000);
InputStreamReader streamReader = new InputStreamReader(sock.getInputStream());
reader = new BufferedReader(streamReader);
writer = new PrintWriter(sock.getOutputStream());
System.out.println(“networking established”);
} catch(IOException ex) {
ex.printStackTrace();
}

// close setUpNetworking

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();
}
}
// close inner class

public class IncomingReader implements Runnable {
public void run() {
String message;
try {
while ((message = reader.readLine()) != null) {
System.out.println(“read “ + message);

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   476   477   478   479   480   481   482   483   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish