簡體   English   中英

在哪里可以找到StreamedTextArea()類-是否已棄用?

[英]Where can I find the StreamedTextArea() class - is it deprecated?

javac找不到此類:StreamedTextArea(),我認為它是java.awt。*的一部分。 如果我需要自己寫,那么任何人都可以給我一些建議。 在網上唯一引用它的時間是在〜1999年左右,這使我認為它不是Sun的課程,而是我必須寫的一門課。 同樣在這段代碼(來自教科書)中,他們使用Frame而不是JFrame。 是否已棄用,如今應如何編寫此應用程序? 請我嘗試自己在線查找答案,但無濟於事。

應用程序 :

//URLViewer.java
//This is a simple application that provides a window in which you can view the
//contents of a URL.

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



public class URLViewer extends Frame implements WindowListener, ActionListener  {

  TextField theURL = new TextField();
  Button loadbutton = new Button("load");
  StreamedTextArea theDisplay = new StreamedTextArea();

                public URLViewer()  {
                  super ("URL Viewer");
                }

                                public void init()  {

                                this.add("North", theURL);
                                this.add("Center", theDisplay);
                                Panel south = new Panel();
                                south.add(loadbutton);
                                this.add("South", south);
                                theURL.addActionListener(this);
                                this.addWindowListener(this);
                                this.setLocation(50, 50);
                                this.pack();
                                this.show();
                                }

        public void actionPerformed (ActionEvent evt)  {

          try  {
          URL u = new URL (theURL.getText());
          InputStream in = u.openStream();
          OutputStream out = theDisplay.getOutputStream();
          StreamCopier.copy(in, out);
          in.close();
          out.close();
          }  catch (MalformedURLException ex)  {theDisplay.setText("Invalid URL");}
             catch (IOException ex)  {theDisplay.setText("Invalid URL");}
        }


        public void windowClosing (WindowEvent e)  {         
        this.setVisible(false);
        this.dispose();
        }
                                public void windowOpened(WindowEvent e) {}
                                public void windowClosed(WindowEvent e) {}
                                public void windowIconified(WindowEvent e) {}
                                public void windowDeiconified(WindowEvent e) {}
                                public void windowActivated(WindowEvent e) {}
                                public void windowDeactivated(WindowEvent e) {}


        public static void main (String[] args)  {

          URLViewer me = new URLViewer();
          me.init();
        }

}

和StreamCopier:

import java.io.*;

public class StreamCopier  {

  public static void main (String[] args)  {

                try  {

                copy (null, null);

                } catch (IOException e) {System.err.println(e);}
  }

  public static void copy (InputStream in, OutputStream out) throws IOException  {

    //do not allow other threads to read from the  input or
    //write to the output while copying is taking place.
    synchronized (in)  {
      synchronized (out)  {
        byte [] buffer = new byte [256];
                                  while (true)   {
                                    int bytesRead = in.read(buffer);
                                    if (bytesRead == -1) break;
                                    out.write(buffer, 0, bytesRead);
                                  }
      }
    }
  }  //end copy()

} 

是StreamedTextArea.java。 我在此頁面上找到了它, 該頁面中還包含與您的StreamCopier類匹配的代碼。 此頁面還包含有關該站點的信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM