A Frame that uses the Confirm dialog to verify quit #Programming Code Examples #Java/J2EE/J2ME #AWT Components

ConfirmTest.java
****************
import java.awt.*;
import java.awt.event.*;

/** A Frame that uses the Confirm dialog to verify that
 *  users really want to quit.
 *
 
public class ConfirmTest extends Frame {
  public static void main(String[] args) {
    new ConfirmTest();
  }

  public ConfirmTest() {
    super("Confirming QUIT");
    setSize(200, 200);
    addWindowListener(new ConfirmListener());
    setVisible(true);
  }

  public ConfirmTest(String title) {
    super(title);
  }

  private class ConfirmListener extends WindowAdapter {
    public void windowClosing(WindowEvent event) {
      new Confirm(ConfirmTest.this);
    }
  }
}
****************
Confirm.java
****************
dialog box with two buttons: Yes and No
****************
import java.awt.*;
import java.awt.event.*;

/** A modal dialog box with two buttons: Yes and No.
 *  Clicking Yes exits Java. Clicking No exits the
 *  dialog. Used for confirmed quits from frames.
 ********************

class Confirm extends Dialog implements ActionListener {
  private Button yes, no;

  public Confirm(Frame parent) {
    super(parent, "Confirmation", true);
    setLayout(new FlowLayout());
    add(new Label("Really quit?"));
    yes = new Button("Yes");
    yes.addActionListener(this);
    no  = new Button("No");
    no.addActionListener(this);
    add(yes);
    add(no);
    pack();
    setVisible(true);
  }

  public void actionPerformed(ActionEvent event) {
    if (event.getSource() == yes) {
      System.exit(0);
    } else {
      dispose();
    }
  }
}
***************

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10330
Categories:Programming Code Examples, Java/J2EE/J2ME, AWT Components
Tags:Java/J2EE/J2MEAWT Components
Post Data:2017-01-02 16:04:35

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada