1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
import java.awt.*;
import java.awt.event.*;
public class MyDialog extends Dialog implements WindowListener, ActionListener
{
static final int WIDTH = 220;
static final int HEIGHT = 120;
public MyDialog( Frame parent )
{
super( parent, "titre", true ); // true -> dialogue modale
setBounds( parent.getX() + (parent.getWidth()-WIDTH)/2, parent.getY() + (parent.getHeight()-HEIGHT)/2, WIDTH, HEIGHT ); // et centrée en plus :wink:
this.setResizable( false ); // non redimensionnable
addWindowListener( this );
// ajoute ici tes composants : boutons, champs textes, etc...
// sans oublier dans les ajouter dans l'actionlistener (i.e. myButton.addActionListener( this );)
}
public void actionPerformed( ActionEvent evt )
{
Object obj = evt.getSource();
String target = evt.getActionCommand();
if( obj instanceof TextField )
{
// getsion des textfields
}
else
if( obj instanceof Button )
{
// gestion des boutons
}
}
public void windowActivated( WindowEvent evt ) {}
public void windowClosed( WindowEvent evt ) {}
public void windowClosing( WindowEvent evt )
{
this.dispose();
}
public void windowDeactivated( WindowEvent evt ) {}
public void windowDeiconified( WindowEvent evt ) {}
public void windowIconified( WindowEvent evt ) {}
public void windowOpened( WindowEvent evt ) {}
} |