/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: MessageDialog.java Description: This dialog is displayed whenever a message is given to the user */ //import statements import java.awt.*; public class MessageDialog extends Dialog { public MessageDialog(Frame frame, String title, String message, boolean modal) { super(frame, title, modal); //Create newPanel LPanel p = new LPanel(); //Add message as label p.addLabel(message, 0, 0, 1.0, 1.0, 0, 0); //Add ok button p.addButtonPanel("OK", 0); p.finish(); add("Center", p); pack(); //Determine center position for dialog on screen Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height) frameSize.height = screenSize.height; if (frameSize.width > screenSize.width) frameSize.width = screenSize.width; this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); show(); } public boolean keyDown(Event e, int key) { if (e.key == Event.ENTER) { hide(); dispose(); return true; } return false; } public boolean action(Event event, Object object) { if(event.target instanceof Button && "OK".equals(object)) { hide(); dispose(); return true; } return false; } }