import javax.swing.*;
import java.awt.event.*;
public class ShowInputDialog{
//Konstruktor
public ShowInputDialog(){
JFrame frame = new JFrame("Input Dialog Box Frame");
JButton button = new JButton("Show Input Dialog Box");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String str = JOptionPane.showInputDialog(null, "Gib einen Text ein: ", "roy-bohn.de", 1);
if(str != null){
JOptionPane.showMessageDialog(null, "Du hast: " + str + " eingegeben", "roy-bohn.de", 1);
}
else
JOptionPane.showMessageDialog(null, "Abbruch...", "roy-bohn.de", 1);
}
});
JPanel panel = new JPanel();
panel.add(button);
frame.add(panel);
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}