Examples of Dialogs

The following program displays a simple non-modal dialog with an OK Button and no title-bar.

import java.applet.*;
import java.awt.*; 

public class DialogTester extends Applet {

  public void init() {
    
    // This trick may not work in all browsers
    // It works on Firefox on the Mac
    Container container = this.getParent();
    while (! (container instanceof Frame)) {
      container = container.getParent();
    }
    Frame parent = (Frame) container;
    
    Dialog d = new Dialog(parent, false);    
    d.setLocation(320, 240);
    d.add(new Label("Hello " 
     + parent.getClass().getName()), BorderLayout.NORTH);
    d.add(new Button("OK"), BorderLayout.SOUTH);
    d.pack();
    d.setVisible(true);
    
  }
  
}

Previous | Next | Top | Cafe au Lait

Copyright 1997, 1999, 2002, 2005 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified July 1, 2005