?? 聊天室項目講解提綱3.txt
字號:
tf.setText();
tf.getText();
ta.append();
tf.requestFocus();
DataOutputStream類的writeUTF(String s);
DataInputStream類的readUTF();
getInputStream();
getOutputStream();
JButton類的setMnemonic() setToolTipText()
引用數據類型參數的傳遞
//===============================================================================
public class TestServer implements ActionListener{
public TestServer(){界面的初始化}//構造方法
public void connect(){創建ServerThread線程,能隨時接受客戶端連接的線程}
public static void main(String[] args){創建對象,調用連接方法}
}
class ServerReadThread extends Thread//服務器讀信息,寫出到所有客戶端
{
public ServerReadThread(TextArea t,DataInputStream d,DataOutputStream []dos){//傳入三個對象類型的參數}
輸入流傳一個就行, 輸出流要傳一個數組,以便向所有客戶端寫出
public void run(){把讀入的信息寫出到服務器文本區,寫出讀入的信息到所有客戶端}
}
class ServerThread implements Runnable{////使服務器能反復接收新的連接,并且把聊天內容打印到所有客戶端的屏幕上
public ServerThread(TextArea ta){}
public void run(){開放服務器,建立連接,搭建輸入輸出流,可隨時接受新的連接請求,用容量為100的數組,創建ServerReadThread并啟動}
}
//------------------------------------------------------------------------------------
public class TestClient implements ActionListener{//實現了監聽器接口
{
public TestClient(String s1,String s2){//構造方法 s1客戶端用戶名 s2服務器IP
界面的初始化,注冊監聽器,調用連接方法,調用創建線程方法}
public void connect(){建立連接,輸入輸出流的包裝DataInputStream/DataOutputStream}
public void createReadThread(){創建線程并啟動,與main線程并發}
public void actionPerformed(ActionEvent e)//在主線程中按鈕或文本框事件被觸發,主線程與rt并發執行
{監聽器的處理方法,對文本框/區的操作,向輸出流寫出writeUTF()}
}
class ClientReadThread extends Thread{
public ClientReadThread(TextArea t,DataInputStream d){傳參}
public void run(){讀readUTF,操作文本區}
}
//-------------------------------------------------------------------------------------
public class Login implements ActionListener{
public Login(){界面的初始化,注冊監聽器}//構造方法
public void actionPerformed(ActionEvent e){輸入合法性判斷,創建客戶端TestClient對象}
public static void main(String[] args){創建對象}
}
//----------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -