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

📄 jiluframe.java~3~

📁 Java 聊天程序 有客户端和服务端。
💻 JAVA~3~
字号:
package chatclient;

import java.io.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.BorderFactory;

/**
 * <p>Title: 聊天系统客户端</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: 个人</p>
 *
 * @author Mothz
 * @version 1.0
 */
public class jiluFrame
    extends JFrame {
    BorderLayout borderLayout1 = new BorderLayout();
    JScrollPane jScrollPane1 = new JScrollPane();
    JTextArea txt = new JTextArea();
    JPanel jPanel1 = new JPanel();
    JButton jButton1 = new JButton();
    JLabel jLabel1 = new JLabel();
    JButton jButton2 = new JButton();
    public jiluFrame() {
        try {
            this.setIconImage(Toolkit.getDefaultToolkit().createImage(
                "images/chat2.png"));
            jbInit();
        }
        catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.setSize(400, 300);
        getContentPane().setLayout(borderLayout1);
        jButton1.setBorder(null);
        jButton1.setDisabledSelectedIcon(null);
        jButton1.setIcon(new ImageIcon("images/exit.jpg"));
        jButton1.addActionListener(new jiluFrame_jButton1_actionAdapter(this));
        jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 14));
        jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel1.setText("本地所有的聊天记录");
        txt.setBorder(BorderFactory.createLoweredBevelBorder());
        jButton2.setBorder(null);
        jButton2.setIcon(new ImageIcon("images/jilu.jpg"));
        jButton2.addActionListener(new jiluFrame_jButton2_actionAdapter(this));
        this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
        jScrollPane1.getViewport().add(txt);
        this.getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
        jPanel1.add(jButton2);
        jPanel1.add(jButton1);
        this.getContentPane().add(jLabel1, java.awt.BorderLayout.NORTH);
        File f=new File("messages.dat");
        if(f.exists()){
            //读取文件内容
            FileReader fr = new FileReader("messages.dat");
            BufferedReader bf = new BufferedReader(fr);
            String s;
            while ( (s = bf.readLine()) != null) {
                txt.append(s + "\n");
            }
            fr.close();
            bf.close();
        }else{
            JOptionPane.showMessageDialog(null,"消息记录文件不存在!");
        }
    }
    //关闭按钮
    public void jButton1_actionPerformed(ActionEvent e) {
        this.dispose();
    }
    //清除记录按钮
    public void jButton2_actionPerformed(ActionEvent e) {
        String nul = "";
        try {
            FileOutputStream fout = new
                FileOutputStream(
                    "messages.dat", false);
            byte[] s = nul.getBytes();
            try {
                fout.write(s);
                fout.close();
            }
            catch (IOException ex1) {
            }
        }
        catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }
        JOptionPane.showMessageDialog(null, "清除成功!");
        txt.setText("");
    }
}

class jiluFrame_jButton2_actionAdapter
    implements ActionListener {
    private jiluFrame adaptee;
    jiluFrame_jButton2_actionAdapter(jiluFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
    }
}

class jiluFrame_jButton1_actionAdapter
    implements ActionListener {
    private jiluFrame adaptee;
    jiluFrame_jButton1_actionAdapter(jiluFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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