// File: MessageDialog.java // Classes: MessageDialog // Author: Kedar Patankar package edu.neu.ccs.demeter.tools.apstudio.graphedit; import java.awt.Button; import java.awt.Label; import java.awt.Frame; import java.awt.BorderLayout; import java.awt.Event; import java.awt.Font; import java.awt.Color; import java.awt.Panel; import java.awt.Point; import java.awt.Dimension; import java.awt.Dialog; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; public class MessageDialog extends Dialog implements ActionListener { private Button _execute; public MessageDialog(Frame frame,String title,String message) { super(frame,title,true); setLayout(new BorderLayout()); Panel p=new Panel(); p.setLayout(new BorderLayout()); p.add("Center",new Label(message,Label.CENTER)); add("Center",p); p.setBackground(Color.lightGray); Panel buttonPanel = new Panel(); _execute = new Button("Ok"); _execute.addActionListener(this); // jdk 1.1 buttonPanel.add(_execute); buttonPanel.setBackground(Color.lightGray); add("South",buttonPanel); pack(); // jdk 1.1 type window event handling addWindowListener(new MDAdapter()); // using inner class for window handling. } public void setVisible(boolean status) { if(status) { _execute.requestFocus(); Dimension frameSize = getParent().getSize(); Point frameLoc = getParent().getLocation(); Dimension mySize = getSize(); int x,y; x = frameLoc.x + (frameSize.width/2) -(mySize.width/2); y = frameLoc.y + (frameSize.height/2)-(mySize.height/2); setBounds(x,y,getSize().width,getSize().height); } super.setVisible(status); } public void actionPerformed(ActionEvent event) { close(); } private void close() { setVisible(false); dispose(); } // inner class VDAdapter class MDAdapter extends WindowAdapter { public void windowClosing(WindowEvent event) { close(); } } } /* end class MessageDialog */