viewwebpage.java

来自「一个十分好的java基础学习的课件」· Java 代码 · 共 47 行

JAVA
47
字号
// ViewingWebPagesViewWebPage.java: Access HTML pages through applets
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;

public class ViewWebPage extends JApplet implements ActionListener
{
  // Button to display an HTML page on the applet
  private JButton jbtGo = new JButton("Go");

  // Text field for receiving the URL of the HTML page
  private JTextField jtfURL = new JTextField(20);

  // Initialize the applet
  public void init()
  {
    // Add URL text field and Go button
    getContentPane().setLayout(new FlowLayout());
    getContentPane().add(new JLabel("URL"));
    getContentPane().add(jtfURL);
    getContentPane().add(jbtGo);

    // Register listener
    jbtGo.addActionListener(this);
  }

  // Handle the ActionEvent
  public void actionPerformed(ActionEvent evt)
  {
    if (evt.getSource() == jbtGo)
      try
      {
        AppletContext context = getAppletContext();

        // Get the URL from text field
        URL url = new URL(jtfURL.getText());
        context.showDocument(url);
      }
      catch(Exception ex)
      {
        showStatus("Error " + ex);
      }
  }
}

⌨️ 快捷键说明

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