SlideShare une entreprise Scribd logo
1  sur  14
Creating a Frame within an Applet




    http://improvejava.blogspot.in/
                                      1
Objective

On completion of this period, you would be
able to know

• Creating a Frame with in an Applet




              http://improvejava.blogspot.in/
                                                2
Recap

In the previous class, you have leant
• Different methods of Frame class
• They are necessary for working with Frames




                http://improvejava.blogspot.in/
                                                  3
Creating a Frame in an Applet

•   Creating a new frame window from within an
    applet is actually quite easy
•   The following steps may be used to do it
    1. Create a subclass of Frame
    2. Override any of the standard window methods, such
       as init( ), start( ), stop( ), and paint( )
    3. Implement the windowClosing( ) method of the
       WindowListener interface, calling setVisible(false)
       when the window is closed

                      http://improvejava.blogspot.in/        4
Creating a Frame in an Applet                  contd..


• Once you have defined a Frame subclass, you
  can create an object of that class
• But it will not be initially visible
• You make it visible by calling setVisible( )
• When created, the window is given a default
  height and width
• You can set the size of the window explicitly by
  calling the setSize( ) method


                 http://improvejava.blogspot.in/             5
An Example Program

• The following applet creates a subclass of
  Frame called SampleFrame
• A window of this subclass is instantiated within
  the init( ) method of AppletFrame
• This example overrides the applet window’s
  start( ) and stop( ) methods




                 http://improvejava.blogspot.in/   6
An Example Program                                contd..

// Create a child frame window from
    within an applet.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="AppletFrame"
    width=300 height=50>
</applet>
*/
// Create a subclass of Frame.
class SampleFrame extends
    Frame {
    SampleFrame(String title) {
    super(title);
                           http://improvejava.blogspot.in/             7
An Example Program                            contd..


  // create an object to handle window events
  MyWindowAdapter adapter = new
  MyWindowAdapter(this);
  // register it to receive those events
  addWindowListener(adapter);
}
public void paint(Graphics g) {
  g.drawString("This is in frame window", 10, 40);
  }
}

                     http://improvejava.blogspot.in/             8
An Example Program                          contd..

// Create frame window.
public class AppletFrame extends Applet {
   Frame f;
   public void init() {
       f = new SampleFrame("A Frame Window");
       f.setSize(250, 250);
       f.setVisible(true);
   }




                  http://improvejava.blogspot.in/             9
An Example Program                             contd..

    public void start() {
        f.setVisible(true);
    }
    public void stop() {
        f.setVisible(false);
    }
    public void paint(Graphics g) {
        g.drawString("This is in applet window", 10, 20);
    }
}



                      http://improvejava.blogspot.in/             10
An Example Program                            contd..


• Sample output from this program is shown here




          Fig. 66.1 Output of SampleFrame program


                   http://improvejava.blogspot.in/             11
Summary

• The steps for creating a new frame window from
  within an applet are
  1. Create a subclass of Frame
  2. Override any of the standard window methods, such
     as init( ), start( ), stop( ), and paint( )
  3. Implement the windowClosing( ) method of the
     WindowListener interface, calling setVisible(false)
     when the window is closed



                    http://improvejava.blogspot.in/        12
Quiz

1. Whether the Frame object is directly visible
    once it is created?
  a) No
  b) Yes




                  http://improvejava.blogspot.in/   13
Frequently Asked Questions

1. Write the steps for creating a frame in an applet
2. Write a program for creating a frame in an applet




                  http://improvejava.blogspot.in/   14

Contenu connexe

Tendances

Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
Jin Castor
 

Tendances (20)

Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in Graphics
 
Er model ppt
Er model pptEr model ppt
Er model ppt
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
 
Java beans
Java beansJava beans
Java beans
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Web Design Issues
Web Design IssuesWeb Design Issues
Web Design Issues
 
Unified process model
Unified process modelUnified process model
Unified process model
 
Hierarchical Object Oriented Design
Hierarchical Object Oriented DesignHierarchical Object Oriented Design
Hierarchical Object Oriented Design
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 

Similaire à Creating a frame within an applet

Creating a windowed program
Creating a windowed programCreating a windowed program
Creating a windowed program
myrajendra
 
Event handling63
Event handling63Event handling63
Event handling63
myrajendra
 

Similaire à Creating a frame within an applet (20)

Creating a windowed program
Creating a windowed programCreating a windowed program
Creating a windowed program
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Applet progming
Applet progmingApplet progming
Applet progming
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
 
oops with java modules iii & iv.pptx
oops with java modules iii & iv.pptxoops with java modules iii & iv.pptx
oops with java modules iii & iv.pptx
 
Applets
AppletsApplets
Applets
 
Applet.pptx
Applet.pptxApplet.pptx
Applet.pptx
 
Applets in Java
Applets in JavaApplets in Java
Applets in Java
 
Applet
AppletApplet
Applet
 
Java Applets
Java AppletsJava Applets
Java Applets
 
27 applet programming
27  applet programming27  applet programming
27 applet programming
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
 
08graphics
08graphics08graphics
08graphics
 
Event handling63
Event handling63Event handling63
Event handling63
 
Java applet-basics
Java applet-basicsJava applet-basics
Java applet-basics
 
Chapter vi(class applet)
Chapter vi(class applet)Chapter vi(class applet)
Chapter vi(class applet)
 
Java applet-basics
Java applet-basicsJava applet-basics
Java applet-basics
 
Applet1 (1).pptx
Applet1 (1).pptxApplet1 (1).pptx
Applet1 (1).pptx
 
SwingApplet.pptx
SwingApplet.pptxSwingApplet.pptx
SwingApplet.pptx
 

Plus de myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

Creating a frame within an applet

  • 1. Creating a Frame within an Applet http://improvejava.blogspot.in/ 1
  • 2. Objective On completion of this period, you would be able to know • Creating a Frame with in an Applet http://improvejava.blogspot.in/ 2
  • 3. Recap In the previous class, you have leant • Different methods of Frame class • They are necessary for working with Frames http://improvejava.blogspot.in/ 3
  • 4. Creating a Frame in an Applet • Creating a new frame window from within an applet is actually quite easy • The following steps may be used to do it 1. Create a subclass of Frame 2. Override any of the standard window methods, such as init( ), start( ), stop( ), and paint( ) 3. Implement the windowClosing( ) method of the WindowListener interface, calling setVisible(false) when the window is closed http://improvejava.blogspot.in/ 4
  • 5. Creating a Frame in an Applet contd.. • Once you have defined a Frame subclass, you can create an object of that class • But it will not be initially visible • You make it visible by calling setVisible( ) • When created, the window is given a default height and width • You can set the size of the window explicitly by calling the setSize( ) method http://improvejava.blogspot.in/ 5
  • 6. An Example Program • The following applet creates a subclass of Frame called SampleFrame • A window of this subclass is instantiated within the init( ) method of AppletFrame • This example overrides the applet window’s start( ) and stop( ) methods http://improvejava.blogspot.in/ 6
  • 7. An Example Program contd.. // Create a child frame window from within an applet. import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="AppletFrame" width=300 height=50> </applet> */ // Create a subclass of Frame. class SampleFrame extends Frame { SampleFrame(String title) { super(title); http://improvejava.blogspot.in/ 7
  • 8. An Example Program contd.. // create an object to handle window events MyWindowAdapter adapter = new MyWindowAdapter(this); // register it to receive those events addWindowListener(adapter); } public void paint(Graphics g) { g.drawString("This is in frame window", 10, 40); } } http://improvejava.blogspot.in/ 8
  • 9. An Example Program contd.. // Create frame window. public class AppletFrame extends Applet { Frame f; public void init() { f = new SampleFrame("A Frame Window"); f.setSize(250, 250); f.setVisible(true); } http://improvejava.blogspot.in/ 9
  • 10. An Example Program contd.. public void start() { f.setVisible(true); } public void stop() { f.setVisible(false); } public void paint(Graphics g) { g.drawString("This is in applet window", 10, 20); } } http://improvejava.blogspot.in/ 10
  • 11. An Example Program contd.. • Sample output from this program is shown here Fig. 66.1 Output of SampleFrame program http://improvejava.blogspot.in/ 11
  • 12. Summary • The steps for creating a new frame window from within an applet are 1. Create a subclass of Frame 2. Override any of the standard window methods, such as init( ), start( ), stop( ), and paint( ) 3. Implement the windowClosing( ) method of the WindowListener interface, calling setVisible(false) when the window is closed http://improvejava.blogspot.in/ 12
  • 13. Quiz 1. Whether the Frame object is directly visible once it is created? a) No b) Yes http://improvejava.blogspot.in/ 13
  • 14. Frequently Asked Questions 1. Write the steps for creating a frame in an applet 2. Write a program for creating a frame in an applet http://improvejava.blogspot.in/ 14