import java.awt.*;
import java.awt.event.*;
class MyDialog extends Dialog implements ActionListener{
MyDialog(Frame parent,String msg){
super(parent,"Message");
setSize(200,100);
setLayout(new FlowLayout());
setLocation(400,400);
Label l=new Label(msg);
Button b=new Button("Ok");
add(l);
add(b);
b.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
new DialogboxDemo().setVisible(true);
}
});
setVisible(true);
}
public void actionPerformed(ActionEvent e){
dispose();
new DialogboxDemo().setVisible(true);
}
}
public class DialogboxDemo extends Frame implements ActionListener{
TextField tf;
Label l;
Button b1,b2;
DialogboxDemo(){
super("Send Message");
setSize(400,200);
setLayout(new FlowLayout());
setLocation(200,200);
l=new Label("Enter Message");
add(l);
tf=new TextField(25);
add(tf);
b1=new Button("Enter");
b2=new Button("Exit");
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
setVisible(true);
}
public static void main(String ar[]){
DialogboxDemo d=new DialogboxDemo();
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand()=="Enter")
{
dispose();
new MyDialog(this,tf.getText());
}
else
System.exit(1);
}
}
No comments:
Post a Comment