home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / java / awt / TextArea.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  2.9 KB  |  90 lines

  1. package java.awt;
  2.  
  3. import java.awt.peer.TextAreaPeer;
  4.  
  5. public class TextArea extends TextComponent {
  6.    int rows;
  7.    int cols;
  8.  
  9.    public TextArea() {
  10.       super("");
  11.    }
  12.  
  13.    public TextArea(int rows, int cols) {
  14.       super("");
  15.       this.rows = rows;
  16.       this.cols = cols;
  17.    }
  18.  
  19.    public TextArea(String text) {
  20.       super(text);
  21.    }
  22.  
  23.    public TextArea(String text, int rows, int cols) {
  24.       super(text);
  25.       this.rows = rows;
  26.       this.cols = cols;
  27.    }
  28.  
  29.    public synchronized void addNotify() {
  30.       super.peer = ((Component)this).getToolkit().createTextArea(this);
  31.       super.addNotify();
  32.    }
  33.  
  34.    public void insertText(String str, int pos) {
  35.       TextAreaPeer peer = (TextAreaPeer)super.peer;
  36.       if (peer != null) {
  37.          peer.insertText(str, pos);
  38.       } else {
  39.          super.text = super.text.substring(0, pos) + str + super.text.substring(pos);
  40.       }
  41.    }
  42.  
  43.    public void appendText(String str) {
  44.       if (super.peer != null) {
  45.          this.insertText(str, ((TextComponent)this).getText().length());
  46.       } else {
  47.          super.text = super.text + str;
  48.       }
  49.    }
  50.  
  51.    public void replaceText(String str, int start, int end) {
  52.       TextAreaPeer peer = (TextAreaPeer)super.peer;
  53.       if (peer != null) {
  54.          peer.replaceText(str, start, end);
  55.       } else {
  56.          super.text = super.text.substring(0, start) + str + super.text.substring(end);
  57.       }
  58.    }
  59.  
  60.    public int getRows() {
  61.       return this.rows;
  62.    }
  63.  
  64.    public int getColumns() {
  65.       return this.cols;
  66.    }
  67.  
  68.    public Dimension preferredSize(int rows, int cols) {
  69.       TextAreaPeer peer = (TextAreaPeer)super.peer;
  70.       return peer != null ? peer.preferredSize(rows, cols) : super.preferredSize();
  71.    }
  72.  
  73.    public Dimension preferredSize() {
  74.       return this.rows > 0 && this.cols > 0 ? this.preferredSize(this.rows, this.cols) : super.preferredSize();
  75.    }
  76.  
  77.    public Dimension minimumSize(int rows, int cols) {
  78.       TextAreaPeer peer = (TextAreaPeer)super.peer;
  79.       return peer != null ? peer.minimumSize(rows, cols) : super.minimumSize();
  80.    }
  81.  
  82.    public Dimension minimumSize() {
  83.       return this.rows > 0 && this.cols > 0 ? this.minimumSize(this.rows, this.cols) : super.minimumSize();
  84.    }
  85.  
  86.    protected String paramString() {
  87.       return super.paramString() + ",rows=" + this.rows + ",cols=" + this.cols;
  88.    }
  89. }
  90.