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
| public class DialogueDemarrage extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
public DialogueDemarrage() {
setLayout(new BorderLayout());
add(creerComposantImage(), BorderLayout.CENTER);
}
private Component creerComposantImage() {
return new JLabel(new ImageIcon("C:\\Users\\Joël\\Pictures\\suricate.jpg")); // ici bien sûr changer la manière de récupérer le path de l'image voulue
}
/**
* Cette méthode affiche un dialogue avec un bouton standard (OK)
*/
public static void afficherDialogue() {
JOptionPane.showMessageDialog(null, new DialogueDemarrage(), "Titre", JOptionPane.PLAIN_MESSAGE);
}
/**
* Cette méthode affiche un dialogue avec un bouton dont le texte est spécifié en argument
*/
public static void afficherDialogue(String textBouton) {
final JButton button = new JButton(textBouton);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane pane = (JOptionPane) SwingUtilities.getAncestorOfClass(JOptionPane.class, (JComponent)e.getSource());
pane.setValue(JOptionPane.OK_OPTION);
}
});
JOptionPane.showOptionDialog(null, new DialogueDemarrage(), "Titre", JOptionPane.OK_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{button}, button);
}
} |
Partager