InputDialog
Aus Programmers Guide
(Unterschied zwischen Versionen)
Roy (Diskussion | Beiträge) |
Roy (Diskussion | Beiträge) |
||
Zeile 1: | Zeile 1: | ||
- | + | <source lang="java"> | |
- | + | ||
- | + | ||
- | + | ||
+ | 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); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
[[Category:Java]] | [[Category:Java]] |
Version vom 09:42, 30. Mär. 2010
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); } }