⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chatframe.java~32~

📁 rmi的例子和制作的录像
💻 JAVA~32~
字号:
package rmichat;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JLabel;
import javax.swing.border.TitledBorder;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

public class ChatFrame extends JFrame {
    BorderLayout borderLayout1 = new BorderLayout();
    JLabel jLabel1 = new JLabel();
    TitledBorder titledBorder1 = new TitledBorder("");
    JPanel jPanel1 = new JPanel();
    JTextField txtMsg = new JTextField();
    JButton btnSend = new JButton();
    JScrollPane jScrollPane1 = new JScrollPane();
    JTextArea txtShowMsg = new JTextArea();

    Chat chat;
    String userName;
    String ip;
    public ChatFrame(Chat chat,String name) {
        try {
            this.chat=chat;
            this.userName=name;
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(borderLayout1);
        jLabel1.setBorder(titledBorder1);
        jLabel1.setText("欢迎登陆聊天室!");
        jPanel1.setBorder(BorderFactory.createRaisedBevelBorder());
        txtShowMsg.setText("jTextArea1");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.addWindowListener(new ChatFrame_this_windowAdapter(this));
        btnSend.addActionListener(new ChatFrame_btnSend_actionAdapter(this));
        this.getContentPane().add(jLabel1, java.awt.BorderLayout.NORTH);
        txtMsg.setColumns(30);
        this.getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
        btnSend.setText("发送");
        jPanel1.add(txtMsg);
        jPanel1.add(btnSend);
        this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
        jScrollPane1.getViewport().add(txtShowMsg);
        GetMsg gm=new GetMsg(this.chat,this.txtShowMsg);
        this.setVisible(true);
    }




    public void this_windowClosing(WindowEvent e) throws RemoteException {
        this.chat.logout(this.userName);
    }

    public void btnSend_actionPerformed(ActionEvent e) throws RemoteException {
        this.chat.sendMsg(this.userName+":"+this.txtMsg.getText());
    }
    /*
    public static void main(String[] args) {
        ChatFrame chatframe = new ChatFrame();
    }*/
}
class GetMsg extends Thread{
    JTextArea txtShowMsg=new JTextArea();
    Chat chat;
    public GetMsg(Chat chat,JTextArea tf){
        this.chat=chat;
        this.txtShowMsg=tf;
    }
    public void run(){
        try {
            txtShowMsg.setText(chat.getMsg());
        } catch (RemoteException ex1) {
        }
        try {
            this.sleep(5000);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    }

class ChatFrame_this_windowAdapter extends WindowAdapter {
    private ChatFrame adaptee;
    ChatFrame_this_windowAdapter(ChatFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void windowClosing(WindowEvent e) {
        try {
            adaptee.this_windowClosing(e);
        } catch (RemoteException ex) {
        }
    }
}


class ChatFrame_btnSend_actionAdapter implements ActionListener {
    private ChatFrame adaptee;
    ChatFrame_btnSend_actionAdapter(ChatFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e){
        try {
            adaptee.btnSend_actionPerformed(e);
        } catch (RemoteException ex) {
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -