Java编程设计

发布网友 发布时间:2022-04-26 01:09

我来回答

1个回答

热心网友 时间:2022-05-01 20:44

  import java.awt.*;

  import java.awt.event.*;

  import javax.swing.*;

  import java.net.*;

  import java.io.IOException;

  import java.io.*;

  public class chat {

  public static void main(String[] args) {

  new UDPMessage();

  }

  }

  class UDPMessage extends JFrame implements ActionListener {

  /**

  *

  */

  private static final long serialVersionUID = 1L;

  private JTextArea recordText = new JTextArea();

  private JTextArea sendText = new JTextArea();

  private DatagramSocket ds;

  private JButton btnSend = new JButton("发送");

  private JButton btnExit = new JButton("关闭");

  private JLabel otherTips = new JLabel("对方IP");

  private JTextField otherIp = new JTextField();

  private JLabel myTips = new JLabel("我的IP");

  private JTextArea myIp = new JTextArea();

  InputStreamReader in;

  //创建一个文件输入流

  OutputStreamWriter out;

  //创建一个文件输出流

  Container p;

  JScrollPane jspRecord;

  JMenuBar mb = new JMenuBar();

  JMenu[] m = {new JMenu("文件"),

  new JMenu("好友"),

  new JMenu("背景")};

  JMenuItem[][] mi = {{new JMenuItem("传送文件")},

  {new JMenuItem("Regina"),new JMenuItem("Taotao"),new JMenuItem("LiShuo")},

  {new JMenuItem("默
  认"),new JMenuItem("浅灰色"),new JMenuItem("淡紫色"),new JMenuItem("黄绿色")}};

  public UDPMessage() {

  super("HiChat");

  p = getContentPane();

  setSize(550, 475);

  centerOnScreen();

  setResizable(false);

  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  for(int i=0; i<m.length; i++) {

  mb.add(m[i]);

  for(int j=0; j<mi[i].length; j++) {

  m[i].add(mi[i][j]);

  mi[i][j].addActionListener(this);

  }

  }

  setJMenuBar(mb);

  p.setBackground(new Color(218, 112, 214));

  p.setLayout(null);

  recordText.setEditable(false);

  recordText.setLineWrap(true);

  jspRecord = new JScrollPane(recordText);

  jspRecord.setBounds(2, 5, 350, 270);

  p.add(jspRecord);

  sendText.setLineWrap(true);

  JScrollPane jspSend = new JScrollPane(sendText);

  jspSend.setBounds(2, 285, 350,100);

  p.add(jspSend);

  btnExit.setBounds(184,390,80,25);

  btnExit.setMargin(new Insets(0, 0, 0, 0));

  btnExit.addActionListener(this);

  p.add(btnExit);

  btnSend.setBounds(271,390,80,25);

  btnSend.setMargin(new Insets(0, 0, 0, 0));

  btnSend.addActionListener(this);

  p.add(btnSend);

  GridLayout gl = new GridLayout(2, 0);

  gl.setVgap(15);

  JPanel infoPane = new JPanel(gl);

  infoPane.setOpa

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com