This example uses the ScreenSize to compute the coordinates for
the dialog.
=================================================================
import java.awt.*;
import java.awt.event.*;
public class CenterDialog extends Dialog implements ActionListener
{
private Button ok;
public CenterDialog(Frame f)
{
super(f);
setLayout(new FlowLayout());
add(new Label("Hello World"));
add(ok = new Button("OK"));
ok.addActionListener(this);
setSize(200,70);
Dimension screen_size= getToolkit().getScreenSize();
setLocation((screen_size.width - 200) / 2, (screen_size.height - 50) / 2);
super.show();
requestFocus();
}
public void actionPerformed(ActionEvent _ev)
{
if (_ev.getSource() == ok)
{
this.dispose();
System.exit(0);
}
}
public static void main(String args[])
{
Frame f = new Frame();
new CenterDialog(f);
}
}