/* A basic extension of the java.awt.Dialog class */ import java.awt.*; public class Dialog1 extends Dialog { public Dialog1(Frame parent) { super(parent); // This code is automatically generated by Visual Cafe when you add // components to the visual environment. It instantiates and initializes // the components. To modify the code, only use code syntax that matches // what Visual Cafe can generate, or Visual Cafe may be unable to back // parse your Java file into its visual environment. //{{INIT_CONTROLS setLayout(null); setBackground(new java.awt.Color(208,211,191)); setForeground(new java.awt.Color(91,0,18)); setFont(new Font("Serif", Font.PLAIN, 12)); setSize(242,118); setVisible(false); add(label1); label1.setForeground(new java.awt.Color(91,0,18)); label1.setFont(new Font("Serif", Font.BOLD, 10)); label1.setBounds(12,24,204,29); button1.setLabel("Ok"); add(button1); button1.setBackground(new java.awt.Color(208,211,191)); button1.setForeground(new java.awt.Color(91,0,18)); button1.setFont(new Font("Serif", Font.BOLD, 10)); button1.setBounds(84,72,36,20); //}} //{{REGISTER_LISTENERS SymWindow aSymWindow = new SymWindow(); this.addWindowListener(aSymWindow); SymAction lSymAction = new SymAction(); button1.addActionListener(lSymAction); //}} } public Dialog1(Frame parent, boolean modal) { this(parent); setModal(modal); } public void addNotify() { // Record the size of the window prior to calling parents addNotify. Dimension d = getSize(); super.addNotify(); if (fComponentsAdjusted) return; // Adjust components according to the insets Insets insets = getInsets(); setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height); Component components[] = getComponents(); for (int i = 0; i < components.length; i++) { Point p = components[i].getLocation(); p.translate(insets.left, insets.top); components[i].setLocation(p); } fComponentsAdjusted = true; } // Used for addNotify check. boolean fComponentsAdjusted = false; public Dialog1(Frame parent, String title, boolean modal,String mess) { this(parent, modal); setTitle(title); label1.setText(mess); } /** * Shows or hides the component depending on the boolean flag b. * @param b if true, show the component; otherwise, hide the component. * @see java.awt.Component#isVisible */ public void setVisible(boolean b) { if(b) { Rectangle bounds = getParent().getBounds(); Rectangle abounds = getBounds(); setLocation(bounds.x + (bounds.width - abounds.width)/ 2, bounds.y + (bounds.height - abounds.height)/2); } super.setVisible(b); } //{{DECLARE_CONTROLS java.awt.Label label1 = new java.awt.Label(); java.awt.Button button1 = new java.awt.Button(); //}} class SymWindow extends java.awt.event.WindowAdapter { public void windowClosing(java.awt.event.WindowEvent event) { Object object = event.getSource(); if (object == Dialog1.this) Dialog1_WindowClosing(event); } } void Dialog1_WindowClosing(java.awt.event.WindowEvent event) { setVisible(false); } class SymAction implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent event) { Object object = event.getSource(); if (object == button1) button1_ActionPerformed(event); } } void button1_ActionPerformed(java.awt.event.ActionEvent event) { // to do: code goes here. this.setVisible(false); } }