Wednesday 26 February 2014

CREATING A FRAME WINDOW IN AN APPLET

How to create a child frame window from within an applet...........

Creating a new frame window from within an applet is actually quite easy.
The following steps may be used to do it,
  • Create a subclass of Frame
  • Override any of the standard window methods,such as init(),start(),stop(),and paint().
  • Implement the windowClosing() method of the windowlistener interface,calling setVisible(false)when the window is closed
  • Once you have defined a Frame subclass,you can create an object of that class.But it will note be initially visible
  • 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
The example program is  shown below:

// Create a child frame window from within an applet.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="AppletFrame" width=400 height=60>
</applet>
*/
// Create a subclass of Frame.
class SampleFrame extends Frame {
SampleFrame(String title) {
super(title);
// 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);
}
}
class MyWindowAdapter extends WindowAdapter {
SampleFrame sampleFrame;
public MyWindowAdapter(SampleFrame sampleFrame) {
this.sampleFrame = sampleFrame;
}
public void windowClosing(WindowEvent we) {
sampleFrame.setVisible(false);
}
}
// Create frame window.
public class AppletFrame extends Applet {
Frame f;
public void init() {
f = new SampleFrame("A Frame Window");
f.setSize(150, 150);
f.setVisible(true);
}
public void start() {
f.setVisible(true);
}
public void stop() {
f.setVisible(false);
}
public void paint(Graphics g) {
g.drawString("This is in applet window", 15, 30);
}

}

OUTPUT


4 comments :

  1. Each window in your home or commercial property is considered a system that is designed to eliminate or moderate sound, light, and air from entering a structure. As a secondary function, windows also function as a point exit or entry into homes. The window glass and window frame you choose can positively affect the operation of your home, including security, safety, interior and exterior decor, comfort, enjoyment of your outdoor landscape, and the energy efficiency of your entire home. painting services

    ReplyDelete
  2. The initial thought of an entry enclosure gate might be that your home would look too fenced in, but there are many options to choose from. From custom to classic and simple designs, there are gates to complement any home and any sense of style.https://tqsecurity.co.uk

    ReplyDelete