Rambler's Top100

А Б В Г Д Е Ж З И К Л М Н О П Р С Т У Ф Х Ц Ч Ш Э Ю Я

Все примеры | Примеры по пакетам

Форма чат-клиента


package niochat1;
//Форма чат-клиента
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JTextPane;


public class clientFrame extends javax.swing.JFrame{
    chatClient cc; // process pr;
       public JTextPane jtp=new JTextPane();
       JTextField jtf;
       String UserID;
       String passwd;
    public clientFrame() {
        initComponents();
        cc=new  chatClient();
        cc.cf=this;

    }
       private void initComponents() {
         setSize(500,350);
         setResizable(false);
         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
         this.setLayout(null);
        jtf=new JTextField();
        jtf.setBounds(11, 11, 250, 20);
        JButton jb=new JButton();
        jb.setBounds(300, 20, 100, 22);
        jb.setText("Connect");
        jb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbActionPerformed(evt);
            }
        });
        this.getContentPane().add(jb);
        JButton jb1=new JButton();
        jb1.setBounds(300, 44, 100, 22);
        jb1.setText("Send");
        jb1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb1ActionPerformed(evt);
            }
        });
        this.getContentPane().add(jb);
        this.getContentPane().add(jb1);
        jtp=new JTextPane();
        jtp.setBounds(11, 30, 250, 250);
        getContentPane().add(jtf);
        getContentPane().add(jtp);
       }
  class BasicThread1 extends Thread {
        // This method is called when the thread runs
        public void run() {

            try {
              jtp=  cc.msgProcessing(jtp);

             jtp.setVisible(false);
                jtp.setVisible(true);

            } catch (InterruptedException ex) {

            }
        }
    }
private void jbActionPerformed(java.awt.event.ActionEvent evt) {

      Thread tr=new BasicThread1();
      tr.start();

    }
private void jb1ActionPerformed(java.awt.event.ActionEvent evt) {
        try {

            String instr=jtf.getText();
            cc.sendMessage(UserID+": "+instr);
            cc.sendMessage("                         ");
        } catch (InterruptedException ex) {
            //
        }


    }
    public static void main(String[] args) {

         java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new clientFrame().setVisible(true);
            }
        });
    }

}

16.05.2009


Файл к примеру: Простейший чат-сервер с использованием nio
Rambler's Top100


Ассоциативные ссылки