import java.awt.*;

import java.awt.event.*;

import java.applet.*;

/*

<applet code="DialogDemo" width=250 height=250>

</applet>

*/

class SampleDialog extends Dialog implements ActionListener {

SampleDialog (Frame parent, String title) {

super(parent, title, false);

setLayout(new FlowLayout());

setSize(300,200);

add(new Label("Press this button:"));

Button b;

add(b = new Button("Cancel"));

b.addActionListener(this);

}

public void actionPerformed (ActionEvent ae){

MyFrame.msg = "Changed directly";

System.out.println(MyFrame.msg);

dispose();

}

public void paint (Graphics g){

g.drawString("This is in the Dialog box.",20, 170);

}

}

class MyFrame extends Frame implements ActionListener {

static String msg = "";

MyFrame (String title){

super (title);

this.setLayout(new BorderLayout());

Button bt;

Label l;

add(bt = new Button("Cancel"),BorderLayout.NORTH);

bt.addActionListener(this);

MyWindowAdapter adapter = new MyWindowAdapter(this);

addWindowListener(adapter);

add(l = new Label(msg),BorderLayout.SOUTH);

}

public void paint (Graphics g){

g.drawString(msg, 10,200);

}

public void actionPerformed(ActionEvent ae) {

msg = "Action Performed";

SampleDialog d = new SampleDialog(this, "New Dialog Box");

d.setVisible(true);

}

}

class MyWindowAdapter extends WindowAdapter{

MyFrame myFrame;

public MyWindowAdapter(MyFrame myFrame){

this.myFrame = myFrame;

}

public void windowClosing (WindowEvent we){

myFrame.dispose();

}

}

 

public class DialogDemo extends Applet {

Frame f;

public void init() {

f = new MyFrame("My Demo");

int width = Integer.parseInt(getParameter("width"));

int height = Integer.parseInt(getParameter("height"));

setSize(width, height);

f.setSize(width, height);

f.setVisible(true);

}

public void start(){

f.setVisible(true);

}

public void stop (){

f.setVisible(false);

}

}