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

📄 urlconnectapplet.java

📁 java 小型系统连接池参照适用于中小型网站
💻 JAVA
字号:
package ntis.com.util;

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

public class URLConnectApplet extends JApplet {
  boolean isStandalone = false;
  JTextField urlField = new JTextField();
  JScrollPane jScrollPane1 = new JScrollPane();
  JPanel jPanel1 = new JPanel();
  TitledBorder titledBorder1;
  JButton conButton = new JButton();
  JEditorPane messagePane = new JEditorPane();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  /**堷悢抣偺庢摼*/
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }

  /**傾僾儗僢僩偺峔抸*/
  public URLConnectApplet() {
  }
  /**傾僾儗僢僩偺弶婜壔*/
  public void init() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  /**僐儞億乕僱儞僩偺弶婜壔*/
  private void jbInit() throws Exception {
    titledBorder1 = new TitledBorder("");
    this.setSize(new Dimension(800,600));
    this.getContentPane().setLayout(gridBagLayout1);
    jPanel1.setBorder(titledBorder1);
    conButton.setText("愙懕");
    conButton.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        conButton_mouseClicked(e);
      }
    });
    this.getContentPane().add(urlField, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    this.getContentPane().add(jScrollPane1, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0
            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    jScrollPane1.getViewport().add(messagePane, null);
    this.getContentPane().add(jPanel1, new GridBagConstraints(1, 0, 1, 2, 0.0, 1.0
            ,GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(conButton, null);
  }
  /**傾僾儗僢僩偺奐巒*/
  public void start() {

  }
  /**傾僾儗僢僩偺掆巭*/
  public void stop() {
  }
  /**傾僾儗僢僩偺攋婞*/
  public void destroy() {
  }
  /**傾僾儗僢僩偺忣曬庢摼*/
  public String getAppletInfo() {
    return "Applet Information";
  }
  /**堷悢忣曬偺庢摼*/
  public String[][] getParameterInfo() {
    return null;
  }

  //儖僢僋仌僼傿乕儖偺愝掕
  static {
    try {
      //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    }
    catch(Exception e) {
    }
  }

  void conButton_mouseClicked(MouseEvent e) {
    byte[] _bBuff = new byte[1024];
    int    _len   = 0;

    try {
      URL _url = new URL(urlField.getText());
      URLConnection _con = _url.openConnection();
      urlField.setText(_con.getHeaderField(0));
      messagePane.setPage(_url);
/*
      InputStream _in = _con.getInputStream();

      while ((_len = _in.read()) != -1) {
      }

      _in.close();
*/
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }
}

⌨️ 快捷键说明

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