Friday, 29 June 2012

program that display child Frame Window within an parent in 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);
// 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 Frmae 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(250, 250);
 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", 10 , 20);
 } }