• 简易聊天界面


     1 package Layout;
     2 
     3 import java.awt.*;
     4 import java.awt.event.ActionEvent;
     5 import java.awt.event.ActionListener;
     6 import java.util.HashMap;
     7 import java.util.Map;
     8 
     9 import javax.swing.*;
    10 
    11 public class ChatInterface extends JFrame implements ActionListener {
    12     private JTextArea jta = new JTextArea();
    13     private JPanel jp = new JPanel();
    14     private Map<String, String> map = new HashMap();
    15     private String str[] = { "one", "two", "three", "four" };
    16     @SuppressWarnings("unused")
    17     private String str1[] = { str + "five" };
    18     private JComboBox jcb = new JComboBox(str);
    19     private JTextField jtf = new JTextField(10);
    20     private JButton b = new JButton("发送");
    21     private JScrollPane jsp = new JScrollPane(jta);//滚动条
    22 
    23     public ChatInterface() {
    24         map.put("one", "one");
    25         map.put("two", "two");
    26         map.put("three", "three");
    27         jp.add(jcb);
    28         jp.add(jtf);
    29         jp.add(b);
    30         // this.setLayout( new GridLayout(2,1));
    31 
    32         this.add(jp, BorderLayout.SOUTH);
    33         this.add(jsp, BorderLayout.CENTER);
    34         this.setTitle("聊天窗口");
    35         this.setIconImage((new ImageIcon("photo/psb.jpg")).getImage());
    36         this.setSize(500, 400);
    37         this.setLocation(100, 100);
    38         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    39         this.setVisible(true);
    40 
    41         b.addActionListener(this);
    42         ActionEvent e = null;
    43 
    44         actionPerformed(e);
    45 
    46         // jta.append();
    47         // jta.append(getName());
    48         // System.out.println(str1);
    49         // if(b!=null){str.}
    50     }
    51 
    52     public static void main(String[] args) {
    53         ChatInterface l = new ChatInterface();
    54 
    55     }
    56 
    57     @Override
    58     public void actionPerformed(ActionEvent e) {
    59      try{
    60         String cmd = e.getActionCommand();
    61         if ("发送" == cmd) {
    62             jta.append(jtf.getText()+'
    ');}
    63         }catch( java.lang.NullPointerException a){}
    64         }
    65     }
  • 相关阅读:
    [1] Tornado Todo Day0
    [0] Tornado Todo 开篇
    RNSS和RDSS
    国密随机数检测--2/15 块内频数检测
    国密随机数检测--1/15 单比特频数检测
    FPGA实用通信协议之IIC
    压缩感知(十)
    压缩感知(九)
    压缩感知(八)
    压缩感知(七)
  • 原文地址:https://www.cnblogs.com/the-wang/p/6752889.html
Copyright © 2020-2023  润新知