SlideShare a Scribd company logo
5
Most read
7
Most read
10
Most read
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

More Related Content

What's hot (20)

PPTX
Applets in java
Wani Zahoor
 
PPTX
Abstraction java
MahinImran
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PDF
Java I/o streams
Hamid Ghorbani
 
PPT
Introduction to JavaScript
Andres Baravalle
 
PPTX
Java Server Pages(jsp)
Manisha Keim
 
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
PPTX
PHP FUNCTIONS
Zeeshan Ahmed
 
PPTX
Exception Handling in Java
lalithambiga kamaraj
 
PDF
Java Thread Synchronization
Benj Del Mundo
 
PPTX
CLASS OBJECT AND INHERITANCE IN PYTHON
Lalitkumar_98
 
PPTX
JAVA AWT
shanmuga rajan
 
ODP
OOP java
xball977
 
PPTX
Inter thread communication
subash andey
 
PPTX
Database Connectivity in PHP
Taha Malampatti
 
PPTX
Polymorphism in java
Elizabeth alexander
 
PPTX
Strings in Java
Abhilash Nair
 
PPT
Java interfaces
Raja Sekhar
 
PPTX
Java(Polymorphism)
harsh kothari
 
PPS
Java Exception handling
kamal kotecha
 
Applets in java
Wani Zahoor
 
Abstraction java
MahinImran
 
Classes, objects in JAVA
Abhilash Nair
 
Java I/o streams
Hamid Ghorbani
 
Introduction to JavaScript
Andres Baravalle
 
Java Server Pages(jsp)
Manisha Keim
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
PHP FUNCTIONS
Zeeshan Ahmed
 
Exception Handling in Java
lalithambiga kamaraj
 
Java Thread Synchronization
Benj Del Mundo
 
CLASS OBJECT AND INHERITANCE IN PYTHON
Lalitkumar_98
 
JAVA AWT
shanmuga rajan
 
OOP java
xball977
 
Inter thread communication
subash andey
 
Database Connectivity in PHP
Taha Malampatti
 
Polymorphism in java
Elizabeth alexander
 
Strings in Java
Abhilash Nair
 
Java interfaces
Raja Sekhar
 
Java(Polymorphism)
harsh kothari
 
Java Exception handling
kamal kotecha
 

Similar to Creating a frame within an applet (20)

PPT
Creating a windowed program
myrajendra
 
PDF
Applet in java
Jancypriya M
 
PPTX
Applets in Java. Learn java program with applets
halaplay385
 
PPTX
Applet progming
VIKRANTHMALLIKARJUN
 
PPTX
Applet in java new
Kavitha713564
 
PPT
Basic of Applet
suraj pandey
 
PPTX
oops with java modules iii & iv.pptx
rani marri
 
PPTX
Applets
Nuha Noor
 
PPTX
Applet.pptx
LakachewYezihalem
 
PPTX
Java Applet presentation............pptx
ZaildarHussainFaisal
 
PDF
Advanced programming chapter 2 - Java Applet.pdf
fikadumeuedu
 
PPTX
Applets in Java
Gary Mendonca
 
PPTX
Applet
Priyanka Pradhan
 
PDF
27 applet programming
Ravindra Rathore
 
DOCX
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
PPT
08graphics
Waheed Warraich
 
PPT
Event handling63
myrajendra
 
PDF
Java applet-basics
kanchanmahajan23
 
PPTX
Chapter vi(class applet)
Chhom Karath
 
Creating a windowed program
myrajendra
 
Applet in java
Jancypriya M
 
Applets in Java. Learn java program with applets
halaplay385
 
Applet progming
VIKRANTHMALLIKARJUN
 
Applet in java new
Kavitha713564
 
Basic of Applet
suraj pandey
 
oops with java modules iii & iv.pptx
rani marri
 
Applets
Nuha Noor
 
Applet.pptx
LakachewYezihalem
 
Java Applet presentation............pptx
ZaildarHussainFaisal
 
Advanced programming chapter 2 - Java Applet.pdf
fikadumeuedu
 
Applets in Java
Gary Mendonca
 
27 applet programming
Ravindra Rathore
 
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
08graphics
Waheed Warraich
 
Event handling63
myrajendra
 
Java applet-basics
kanchanmahajan23
 
Chapter vi(class applet)
Chhom Karath
 
Ad

More from myrajendra (20)

PPT
Fundamentals
myrajendra
 
PPT
Data type
myrajendra
 
PPTX
Hibernate example1
myrajendra
 
PPTX
Jdbc workflow
myrajendra
 
PPTX
2 jdbc drivers
myrajendra
 
PPTX
3 jdbc api
myrajendra
 
PPTX
4 jdbc step1
myrajendra
 
PPTX
Dao example
myrajendra
 
PPTX
Sessionex1
myrajendra
 
PPTX
Internal
myrajendra
 
PPTX
3. elements
myrajendra
 
PPTX
2. attributes
myrajendra
 
PPTX
1 introduction to html
myrajendra
 
PPTX
Headings
myrajendra
 
PPTX
Forms
myrajendra
 
PPT
Css
myrajendra
 
PPTX
Views
myrajendra
 
PPTX
Views
myrajendra
 
PPTX
Views
myrajendra
 
PPT
Starting jdbc
myrajendra
 
Fundamentals
myrajendra
 
Data type
myrajendra
 
Hibernate example1
myrajendra
 
Jdbc workflow
myrajendra
 
2 jdbc drivers
myrajendra
 
3 jdbc api
myrajendra
 
4 jdbc step1
myrajendra
 
Dao example
myrajendra
 
Sessionex1
myrajendra
 
Internal
myrajendra
 
3. elements
myrajendra
 
2. attributes
myrajendra
 
1 introduction to html
myrajendra
 
Headings
myrajendra
 
Forms
myrajendra
 
Views
myrajendra
 
Views
myrajendra
 
Views
myrajendra
 
Starting jdbc
myrajendra
 
Ad

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