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

📄 myclient.java~8~

📁 用java写的用于C/S服务的网络应用程序
💻 JAVA~8~
字号:
package myclient;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class MyClient
    extends JFrame {
  Socket ClientSocket;
  PrintStream os;
  DataInputStream is;
  String s;

  JPanel contentPane;
  BorderLayout borderLayout1 = new BorderLayout();
  JLabel Mylabel = new JLabel();
  JScrollPane jScrollPane1 = new JScrollPane();
  JTextArea textArea = new JTextArea();
  JButton MyButton = new JButton();

  //Construct the frame
  public MyClient() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  //Component initialization
  private void jbInit() throws Exception {
    contentPane = (JPanel)this.getContentPane();
    Mylabel.setEnabled(true);
    Mylabel.setPreferredSize(new Dimension(132, 16));
    Mylabel.setText("欢迎使用本机器提供的信息");
    contentPane.setLayout(borderLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Client Window");
    textArea.setText("");
    MyButton.setText("发送");
    contentPane.add(Mylabel, BorderLayout.NORTH);
    contentPane.add(jScrollPane1, BorderLayout.CENTER);
    contentPane.add(MyButton, BorderLayout.SOUTH);
  }

  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }

    public void connect() {
      try {
        ClientSocket = new Socket("127.0.0.1", 8000);
        os = new PrintStream(new BufferedOutputStream
                             (ClientSocket.getOutputStream()));
        is = new DataInputStream(new BufferedInputStream
                                 (ClientSocket.getInputStream()));
        s = is.readLine();
        textArea.appendText(s + "\n");
      }
      catch (Exception e) {}
    }


}

⌨️ 快捷键说明

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