home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / solaris2 / jdk / src / java / awt / frame.jav < prev    next >
Encoding:
Text File  |  1995-10-30  |  4.9 KB  |  214 lines

  1. /*
  2.  * @(#)Frame.java    1.35 95/10/21 Sami Shaio
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package java.awt;
  20.  
  21. import java.awt.peer.FramePeer;
  22.  
  23. /**
  24.  * A Frame is a top-level window with a title.
  25.  * The default layout for a frame is BorderLayout.
  26.  *
  27.  * @version     1.35, 10/21/95
  28.  * @author     Sami Shaio
  29.  */
  30. public class Frame extends Window implements MenuContainer {
  31.     String     title = "Untitled";
  32.     Image      icon;
  33.     MenuBar    menuBar;
  34.     boolean    resizable = true;
  35.  
  36.     /**
  37.      * Constructs a new Frame that is initially invisible.
  38.      * @see #resize
  39.      * @see #show
  40.      */
  41.     public Frame() {
  42.     visible = false;
  43.     setLayout(new BorderLayout());
  44.     }
  45.  
  46.     /**
  47.      * Constructs a new, initially invisible Frame with the specified 
  48.      * title.
  49.      * @param title te specified title 
  50.      * @see #resize
  51.      * @see #show
  52.      */
  53.     public Frame(String title) {
  54.     this();
  55.     this.title = title;
  56.     }
  57.  
  58.     /**
  59.      * Creates the Frame's peer.  The peer allows us to change the look
  60.      * of the Frame without changing its functionality.
  61.      */
  62.     public synchronized void addNotify() {
  63.     peer = getToolkit().createFrame(this);
  64.     if (menuBar != null) {
  65.         menuBar.addNotify();
  66.         ((FramePeer)peer).setMenuBar(menuBar);
  67.     }
  68.     super.addNotify();
  69.     }
  70.  
  71.     /**
  72.      * Gets the title of the Frame.
  73.      * @see #setTitle
  74.      */
  75.     public String getTitle() {
  76.     return title;
  77.     }
  78.  
  79.     /**
  80.      * Sets the title for this Frame to the specified title.
  81.      * @param title the specified title of this Frame
  82.      * @see #getTitle
  83.      */
  84.     public void setTitle(String title) {
  85.     this.title = title;
  86.     FramePeer peer = (FramePeer)this.peer;
  87.     if (peer != null) {
  88.         peer.setTitle(title);
  89.     }
  90.     }
  91.  
  92.     /**
  93.      * Returns the icon image for this Frame.
  94.      */
  95.     public Image getIconImage() {
  96.     return icon;
  97.     }
  98.  
  99.     /**
  100.      * Sets the image to display when this Frame is iconized. Note that
  101.      * not all platforms support the concept of iconizing a window.
  102.      * @param image the icon image to be displayed
  103.      */
  104.     public void setIconImage(Image image) {
  105.     this.icon = image;
  106.     FramePeer peer = (FramePeer)this.peer;
  107.     if (peer != null) {
  108.         peer.setIconImage(image);
  109.     }
  110.     }
  111.  
  112.     /**
  113.      * Gets the menu bar for this Frame.
  114.      */
  115.     public MenuBar getMenuBar() {
  116.     return menuBar;
  117.     }
  118.  
  119.     /**
  120.      * Sets the menubar for this Frame to the specified menubar.
  121.      * @param mb the menubar being set
  122.      */
  123.     public synchronized void setMenuBar(MenuBar mb) {
  124.     if (menuBar == mb) {
  125.         return;
  126.     }
  127.     if (mb.parent != null) {
  128.         mb.parent.remove(mb);
  129.     }
  130.     if (menuBar != null) {
  131.         remove(menuBar);
  132.     }
  133.     menuBar = mb;
  134.     menuBar.parent = this;
  135.  
  136.     FramePeer peer = (FramePeer)this.peer;
  137.     if (peer != null) {
  138.         menuBar.addNotify();
  139.         peer.setMenuBar(menuBar);
  140.     }
  141.     }
  142.  
  143.     /**
  144.      * Removes the specified menu bar from this Frame.
  145.      */
  146.     public synchronized void remove(MenuComponent m) {
  147.     if (m == menuBar) {
  148.         FramePeer peer = (FramePeer)this.peer;
  149.         if (peer != null) {
  150.         menuBar.removeNotify();
  151.         menuBar.parent = null;
  152.         peer.setMenuBar(null);
  153.         }
  154.         menuBar = null;
  155.     }
  156.     }
  157.  
  158.     /**
  159.      * Disposes of the Frame. This method must
  160.      * be called to release the resources that
  161.      * are used for the frame.
  162.      */
  163.     public synchronized void dispose() {
  164.     if (menuBar != null) {
  165.         remove(menuBar);
  166.             menuBar = null;
  167.     }
  168.         super.dispose();
  169.     }
  170.  
  171.     /**
  172.      * Returns true if the user can resize the Frame.
  173.      */
  174.     public boolean isResizable() {
  175.     return resizable;
  176.     }
  177.  
  178.     /**
  179.      * Sets the resizable flag.
  180.      * @param resizable true if resizable; false otherwise.
  181.      */
  182.     public void setResizable(boolean resizable) {
  183.     this.resizable = resizable;
  184.     FramePeer peer = (FramePeer)this.peer;
  185.     if (peer != null) {
  186.         peer.setResizable(resizable);
  187.     }
  188.     }
  189.  
  190.     /**
  191.      * Set the cursor image
  192.      */
  193.     public void setCursor(Image img) {
  194.     FramePeer peer = (FramePeer)this.peer;
  195.     if (peer != null) {
  196.         peer.setCursor(img);
  197.     }
  198.     }
  199.  
  200.     /**
  201.      * Returns the parameter String of this Frame.
  202.      */
  203.     protected String paramString() {
  204.     String str = super.paramString();
  205.     if (resizable) {
  206.         str += ",resizable";
  207.     }
  208.     if (title != null) {
  209.         str += ",title= " + title;
  210.     }
  211.     return str;
  212.     }
  213. }
  214.