Questo potrebbe andare bene, è un esempio che ho buttato giù adesso:
codice:
import java.awt.*;
import java.awt.event.*;
public class ConfirmDialog extends Dialog
{
public static final int NO_OPTION = 1;
public static final int YES_OPTION = 2;
private Label textLabel;
private Button yesButton;
private Button noButton;
private int choice;
public ConfirmDialog (Dialog owner, String title, String message)
{
super (owner, title, true);
textLabel = new Label (message);
yesButton = new Button ("Si");
noButton = new Button ("No");
setResizable (false);
setLayout (new GridBagLayout ());
GridBagConstraints c = new GridBagConstraints ();
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets (20, 20, 10, 20);
add (textLabel, c);
c.gridx = 0;
c.gridy = 1;
c.fill = GridBagConstraints.NONE;
c.insets = new Insets (10, 20, 20, 20);
Panel p = new Panel (new FlowLayout (FlowLayout.CENTER, 10, 0));
p.add (yesButton);
p.add (noButton);
add (p, c);
pack ();
Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize ();
Dimension dialogSize = getSize ();
setLocation ((screenSize.width - dialogSize.width) / 2,
(screenSize.height - dialogSize.height) / 2);
ActionListener al = new ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
if (e.getSource () == yesButton)
choice = YES_OPTION;
else
choice = NO_OPTION;
dispose ();
}
};
yesButton.addActionListener (al);
noButton.addActionListener (al);
}
public int showDialog ()
{
show ();
return choice;
}
}
Da usare con:
ConfirmDialog d = new ConfirmDialog (unOwner, "Prova", "Un messaggio di prova per testare la classe ConfirmDialog");
int c = d.showDialog ();
La dialog non è bellissima come quella di JOptionPane ma non fa nemmeno così schifo ... in ogni caso è sicuramente migliorabile, con un pochino di "sbattimento".