— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet448/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   444   445   446   447   448   449   450   451   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

a simple 
chat client


networking 
and
threads
you are here
4
487
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”);
JPanel mainPanel = new JPanel();
outgoing = new JTextField(20);
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,500);
frame.setVisible(true);

// close go
private void setUpNetworking() {
try {
sock = new Socket(“127.0.0.1”, 5000);
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();
}

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   444   445   446   447   448   449   450   451   ...   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