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

  1. package java.awt;
  2.  
  3. import java.awt.peer.FramePeer;
  4.  
  5. public class Frame extends Window implements MenuContainer {
  6.    public static final int DEFAULT_CURSOR = 0;
  7.    public static final int CROSSHAIR_CURSOR = 1;
  8.    public static final int TEXT_CURSOR = 2;
  9.    public static final int WAIT_CURSOR = 3;
  10.    public static final int SW_RESIZE_CURSOR = 4;
  11.    public static final int SE_RESIZE_CURSOR = 5;
  12.    public static final int NW_RESIZE_CURSOR = 6;
  13.    public static final int NE_RESIZE_CURSOR = 7;
  14.    public static final int N_RESIZE_CURSOR = 8;
  15.    public static final int S_RESIZE_CURSOR = 9;
  16.    public static final int W_RESIZE_CURSOR = 10;
  17.    public static final int E_RESIZE_CURSOR = 11;
  18.    public static final int HAND_CURSOR = 12;
  19.    public static final int MOVE_CURSOR = 13;
  20.    String title;
  21.    Image icon;
  22.    MenuBar menuBar;
  23.    boolean resizable;
  24.    Image cursorImage;
  25.    int cursorType;
  26.    Color cursorFg;
  27.    Color cursorBg;
  28.  
  29.    public Frame() {
  30.       this.title = "Untitled";
  31.       this.resizable = true;
  32.       super.visible = false;
  33.       ((Container)this).setLayout(new BorderLayout());
  34.    }
  35.  
  36.    public Frame(String title) {
  37.       this();
  38.       this.title = title;
  39.    }
  40.  
  41.    public synchronized void addNotify() {
  42.       super.peer = ((Window)this).getToolkit().createFrame(this);
  43.       if (this.menuBar != null) {
  44.          this.menuBar.addNotify();
  45.          ((FramePeer)super.peer).setMenuBar(this.menuBar);
  46.       }
  47.  
  48.       super.addNotify();
  49.    }
  50.  
  51.    public String getTitle() {
  52.       return this.title;
  53.    }
  54.  
  55.    public void setTitle(String title) {
  56.       this.title = title;
  57.       FramePeer peer = (FramePeer)super.peer;
  58.       if (peer != null) {
  59.          peer.setTitle(title);
  60.       }
  61.  
  62.    }
  63.  
  64.    public Image getIconImage() {
  65.       return this.icon;
  66.    }
  67.  
  68.    public void setIconImage(Image image) {
  69.       this.icon = image;
  70.       FramePeer peer = (FramePeer)super.peer;
  71.       if (peer != null) {
  72.          peer.setIconImage(image);
  73.       }
  74.  
  75.    }
  76.  
  77.    public MenuBar getMenuBar() {
  78.       return this.menuBar;
  79.    }
  80.  
  81.    public synchronized void setMenuBar(MenuBar mb) {
  82.       if (this.menuBar != mb) {
  83.          if (mb.parent != null) {
  84.             mb.parent.remove(mb);
  85.          }
  86.  
  87.          if (this.menuBar != null) {
  88.             this.remove(this.menuBar);
  89.          }
  90.  
  91.          this.menuBar = mb;
  92.          this.menuBar.parent = this;
  93.          FramePeer peer = (FramePeer)super.peer;
  94.          if (peer != null) {
  95.             this.menuBar.addNotify();
  96.             peer.setMenuBar(this.menuBar);
  97.          }
  98.  
  99.       }
  100.    }
  101.  
  102.    public synchronized void remove(MenuComponent m) {
  103.       if (m == this.menuBar) {
  104.          FramePeer peer = (FramePeer)super.peer;
  105.          if (peer != null) {
  106.             this.menuBar.removeNotify();
  107.             this.menuBar.parent = null;
  108.             peer.setMenuBar((MenuBar)null);
  109.          }
  110.  
  111.          this.menuBar = null;
  112.       }
  113.  
  114.    }
  115.  
  116.    public synchronized void dispose() {
  117.       if (this.menuBar != null) {
  118.          this.remove(this.menuBar);
  119.          this.menuBar = null;
  120.       }
  121.  
  122.       super.dispose();
  123.    }
  124.  
  125.    public boolean isResizable() {
  126.       return this.resizable;
  127.    }
  128.  
  129.    public void setResizable(boolean resizable) {
  130.       this.resizable = resizable;
  131.       FramePeer peer = (FramePeer)super.peer;
  132.       if (peer != null) {
  133.          peer.setResizable(resizable);
  134.       }
  135.  
  136.    }
  137.  
  138.    public void setCursor(int cursorType) {
  139.       if (cursorType >= 0 && cursorType <= 13) {
  140.          this.cursorType = cursorType;
  141.          if (super.peer != null) {
  142.             ((FramePeer)super.peer).setCursor(cursorType);
  143.          }
  144.  
  145.       } else {
  146.          throw new IllegalArgumentException("illegal cursor type");
  147.       }
  148.    }
  149.  
  150.    public int getCursorType() {
  151.       return this.cursorType;
  152.    }
  153.  
  154.    protected String paramString() {
  155.       String str = super.paramString();
  156.       if (this.resizable) {
  157.          str = str + ",resizable";
  158.       }
  159.  
  160.       if (this.title != null) {
  161.          str = str + ",title=" + this.title;
  162.       }
  163.  
  164.       return str;
  165.    }
  166. }
  167.