home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / Java++ / VJ / SAMPLES / JAVANOW / CHAP17 / FRAMECOMPONENT / FRAMECOMPONENT.JAVA < prev    next >
Encoding:
Java Source  |  1996-06-13  |  1.8 KB  |  85 lines

  1. // FrameComponent - demonstrates how to create a Frame with
  2. //                  a simple menu and how to read menu selections
  3. import java.applet.*;
  4. import java.awt.*;
  5. import TestFrame;
  6.  
  7. public class FrameComponent extends Applet
  8. {
  9.  
  10.     // m_frame - this is the frame we create
  11.     private Frame m_frame;
  12.  
  13.     // m_object - the action object passed from the
  14.     //            Frame menu
  15.     private Object m_object;
  16.  
  17.     public FrameComponent()
  18.     {
  19.         // TODO: Add Constructor code here
  20.     }
  21.  
  22.     public String getAppletInfo()
  23.     {
  24.         return "Name: FrameComponent\r\n" +
  25.                "Author: Stephan R. Davis\r\n" +
  26.                "Created for Learn Java Now";
  27.     }
  28.  
  29.  
  30.     public void init()
  31.     {
  32.         resize(320, 240);
  33.  
  34.         // TODO: Place Addition Initialization code here
  35.         // create a frame of type TestFrame
  36.         m_frame = new TestFrame(this);
  37.  
  38.         // size the frame
  39.         Dimension d = size();
  40.         m_frame.resize(d);
  41.  
  42.         // now make it visible (frames are created hidden)
  43.         m_frame.show();
  44.     }
  45.  
  46.     public void destroy()
  47.     {
  48.         // TODO: Place applet cleanup code here
  49.     }
  50.  
  51.     // paint - if there is an action object, output it
  52.     //         to the applet window
  53.     public void paint(Graphics g)
  54.     {
  55.         if (m_object != null)
  56.         {
  57.             g.drawString(m_object.toString(), 10, 20);
  58.         }
  59.     }
  60.  
  61.     public void start()
  62.     {
  63.         // TODO: Place additional applet Start code here
  64.     }
  65.     
  66.     public void stop()
  67.     {
  68.     }
  69.  
  70.  
  71.  
  72.  
  73.     // action - record the action object for
  74.     //          display (this method is not normally invoked -
  75.     //          it's only called here because the TestFrame
  76.     //          class passes the event along
  77.     public boolean action(Event event, Object obj)
  78.     {
  79.         m_object = obj;
  80.         repaint();
  81.         return true;
  82.     }
  83.  
  84. }
  85.