home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-09-09 | 4.5 KB | 163 lines |
- /*
- A basic extension of the java.awt.Dialog class
- */
-
- import java.awt.*;
- import java.awt.event.*;
-
- public class QuitDialog extends Dialog
- {
-
- void QuitDialog_WindowClosing(java.awt.event.WindowEvent event)
- {
- dispose();
- }
-
- void yesButton_Clicked(java.awt.event.ActionEvent event)
- {
- Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent((java.awt.Window)getParent(), WindowEvent.WINDOW_CLOSING));
- }
-
- void noButton_Clicked(java.awt.event.ActionEvent event)
- {
- //{{CONNECTION
- // Clicked from noButton dispose the Dialog
- dispose();
- //}}
- }
-
- public QuitDialog(Frame parent, boolean modal)
- {
- super(parent, modal);
-
- // 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
- GridBagLayout gridBagLayout;
- gridBagLayout = new GridBagLayout();
- setLayout(gridBagLayout);
- setVisible(false);
- setSize(insets().left + insets().right + 337,insets().top + insets().bottom + 135);
- setBackground(new Color(12632256));
- yesButton = new java.awt.Button();
- yesButton.setLabel(" Yes ");
- yesButton.setBounds(insets().left + 63,insets().top + 89,41,23);
- yesButton.setFont(new Font("Dialog", Font.BOLD, 12));
- GridBagConstraints gbc;
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 1;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(yesButton, gbc);
- add(yesButton);
- noButton = new java.awt.Button();
- noButton.setLabel(" No ");
- noButton.setBounds(insets().left + 230,insets().top + 89,42,23);
- noButton.setFont(new Font("Dialog", Font.BOLD, 12));
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 1;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(noButton, gbc);
- add(noButton);
- label1 = new java.awt.Label("Do you really want to quit?",Label.CENTER);
- label1.setBounds(insets().left + 90,insets().top + 22,156,23);
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.gridwidth = 2;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(label1, gbc);
- add(label1);
- setTitle("A Basic Application - Quit");
- //}}
-
- //{{REGISTER_LISTENERS
- Window lWindow = new Window();
- addWindowListener(lWindow);
- Action lAction = new Action();
- noButton.addActionListener(lAction);
- yesButton.addActionListener(lAction);
- //}}
- }
-
- public void addNotify()
- {
- super.addNotify();
-
- if (fComponentsAdjusted)
- return;
-
- // Adjust components according to the insets
- setSize(insets().left + insets().right + getSize().width, insets().top + insets().bottom + getSize().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;
- }
-
- boolean fComponentsAdjusted = false;
-
-
- public QuitDialog(Frame parent, String title, boolean modal)
- {
- this(parent, modal);
- setTitle(title);
- }
-
- public synchronized void show()
- {
- Rectangle bounds = getParent().bounds();
- Rectangle abounds = bounds();
-
- move(bounds.x + (bounds.width - abounds.width)/ 2,
- bounds.y + (bounds.height - abounds.height)/2);
-
- super.show();
- }
-
- //{{DECLARE_CONTROLS
- java.awt.Button yesButton;
- java.awt.Button noButton;
- java.awt.Label label1;
- //}}
-
- class Window extends java.awt.event.WindowAdapter
- {
- public void windowClosing(java.awt.event.WindowEvent event)
- {
- Object object = event.getSource();
- if (object == QuitDialog.this)
- QuitDialog_WindowClosing(event);
- }
- }
-
- class Action implements java.awt.event.ActionListener
- {
- public void actionPerformed(java.awt.event.ActionEvent event)
- {
- Object object = event.getSource();
- if (object == noButton)
- noButton_Clicked(event);
- else if (object == yesButton)
- yesButton_Clicked(event);
- }
- }
- }
-