Tuesday, November 4, 2008

MessageBox

import java.awt.*;
import java.awt.event.*;
public class MessageBox {

Dialog msgBox;
public MessageBox(Frame parentWindow, String msg,String title){

if (parentWindow==null){
Frame emptyWindow =new Frame();
msgBox=new Dialog(emptyWindow,title,true);
} else
msgBox=new Dialog(parentWindow,title,true);

Label Message=new Label(msg);

msgBox.setLayout(new FlowLayout());
msgBox.add(Message);

Button OKButton=new Button("OK");
OKButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
msgBox.setVisible(false);
}
});

msgBox.add(OKButton);
msgBox.setSize(new Dimension(200, 100));

}
public void show(){
msgBox.show();
}
}