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

📄 appletclient.java

📁 JAVA程序设计导论那本书上的一些源代码. 在学那本书的下来的
💻 JAVA
字号:
import java.io.*;import java.net.*;import java.awt.BorderLayout;import javax.swing.*;public class AppletClient extends JApplet {  // Label for displaying the visit count  private JLabel jlblCount = new JLabel();  // Indicate if it runs as application  private boolean isStandAlone = false;  // Host name or ip  private String host = "localhost";  /** Initialize the applet */  public void init() {    getContentPane().add(jlblCount);    try {      // Create a socket to connect to the server      Socket socket;      if (isStandAlone)        socket = new Socket(host, 8000);      else        socket = new Socket(getCodeBase().getHost(), 8000);      // Create an input stream to receive data from the server      DataInputStream inputFromServer =        new DataInputStream(socket.getInputStream());      // Receive the count from the server and display it on label      int count = inputFromServer.readInt();      jlblCount.setText("You are visitor number " + count);      // Close the stream      inputFromServer.close();    }    catch (IOException ex) {      ex.printStackTrace();    }  }  /** Run the applet as an application */  public static void main(String[] args) {    // Create a frame    JFrame frame = new JFrame("Applet Client");    // Create an instance of the applet    AppletClient applet = new AppletClient();    applet.isStandAlone = true;    // Get host    if (args.length == 1) applet.host = args[0];    // Add the applet instance to the frame    frame.getContentPane().add(applet, BorderLayout.CENTER);    // Invoke init() and start()    applet.init();    applet.start();    // Display the frame    frame.pack();    frame.setVisible(true);  }}

⌨️ 快捷键说明

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